GUI2: made link_aware a per-instance config option rather than per-definition

Back when link awareness was first added (https://github.com/wesnoth/wesnoth/pull/300), this key was added
globally to label definitions alongside link_color. This had the unintended side effect of making *all* labels
link aware, leading to issues such as being able to open a do-you-want-to-open prompt from an instance of the
same ad-infinitum.

This became an active issue after 213453e6cf, since now that labels could capture
focus if link_aware was true - which it always was for most labels - labels in toggle panels would always
grab mouse_motion events and no longer allow their parent toggle panels to gain their hovered states. That
appears to be in keeping with the design of GUI2, and a further evaluation of that issue is needed at a later
time. However, the fact remains that almost every single label was marked as link-aware, even when in almost every
case that was not the desired behavior.

This change move the link_aware config option to individual label and scroll_label instances. The following uses
had this explicitly enabled:

- Addon license prompt
- Addon descriptions
- Campaign descriptions
- The Server Info popup
- The chatbox
This commit is contained in:
Charles Dang 2020-12-12 03:03:09 +11:00
parent 22647c388a
commit 7188781f91
12 changed files with 19 additions and 9 deletions

View file

@ -19,6 +19,7 @@
* Undead variations for Falcon, Giant Rat, serpents, and Gorer/Tusklet
### User interface
* Text labels now use the hyperlink mouse cursor while hovering links.
* Link awareness is now configured on a per-instance basis for labels/scroll labels instead of globally in their definition.
### WML Engine
### Miscellaneous and Bug Fixes
* Fixed several possible crashes in wmllint

View file

@ -78,6 +78,8 @@
vertical_scrollbar_mode = "always"
horizontal_scrollbar_mode = "never"
link_aware = true
[/scroll_label]
[/column]
[/row]

View file

@ -24,7 +24,6 @@
text_font_size = {FONT_SIZE}
text_font_style = {FONT_STYLE}
link_aware = true
link_color = "255, 225, 0"
[state_enabled]

View file

@ -68,8 +68,6 @@ where box_width = {_GUI_ESTIMATE_TEXT_WIDTH})#enddef
text_font_size = {GUI_FONT_SIZE_LARGE}
link_aware = false
[state_enabled]
[draw]

View file

@ -77,6 +77,7 @@
id = "terms"
definition = "description"
label = "server terms placeholder"
link_aware = true
[/scroll_label]
[/column]
[/row]

View file

@ -126,7 +126,7 @@
border = "left,top,bottom"
border_size = 5
horizontal_alignment = "right"
[menu_button]
id = "version_filter"
definition = "default"
@ -157,6 +157,7 @@
label = _ "No description available."
horizontal_scrollbar_mode = "never"
link_aware = true
[/scroll_label]
[/column]

View file

@ -361,6 +361,7 @@
definition = "default"
wrap = true
link_aware = true
[/label]
[/column]

View file

@ -25,6 +25,7 @@
label = ""
use_markup = true
wrap = true
link_aware = true
[/label]
[/column]

View file

@ -46,7 +46,7 @@ label::label(const implementation::builder_label& builder)
, state_(ENABLED)
, can_wrap_(builder.wrap)
, characters_per_line_(builder.characters_per_line)
, link_aware_(false)
, link_aware_(builder.link_aware)
, link_color_(color_t::from_hex_string("ffff00"))
, can_shrink_(builder.can_shrink)
, text_alpha_(ALPHA_OPAQUE)
@ -127,7 +127,6 @@ void label::signal_handler_left_button_click(bool& handled)
return;
}
point mouse = get_mouse_position();
mouse.x -= get_x();
@ -272,7 +271,6 @@ label_definition::label_definition(const config& cfg)
*/
label_definition::resolution::resolution(const config& cfg)
: resolution_definition(cfg)
, link_aware(cfg["link_aware"].to_bool(false))
, link_color(cfg["link_color"].empty() ? color_t::from_hex_string("ffff00") : color_t::from_rgba_string(cfg["link_color"].str()))
{
// Note the order should be the same as the enum state_t is label.hpp.
@ -328,6 +326,7 @@ builder_label::builder_label(const config& cfg)
, characters_per_line(cfg["characters_per_line"])
, text_alignment(decode_text_alignment(cfg["text_alignment"]))
, can_shrink(cfg["can_shrink"].to_bool(false))
, link_aware(cfg["link_aware"].to_bool(false))
{
}
@ -339,7 +338,6 @@ widget* builder_label::build() const
assert(conf);
lbl->set_text_alignment(text_alignment);
lbl->set_link_aware(conf->link_aware);
lbl->set_link_color(conf->link_color);
DBG_GUI_G << "Window builder: placed label '" << id << "' with definition '"

View file

@ -212,7 +212,6 @@ struct label_definition : public styled_widget_definition
{
explicit resolution(const config& cfg);
bool link_aware;
color_t link_color;
};
};
@ -237,6 +236,7 @@ struct builder_label : public builder_styled_widget
PangoAlignment text_alignment;
bool can_shrink;
bool link_aware;
};
} // namespace implementation

View file

@ -44,6 +44,7 @@ scroll_label::scroll_label(const implementation::builder_scroll_label& builder)
, state_(ENABLED)
, wrap_on_(builder.wrap_on)
, text_alignment_(builder.text_alignment)
, link_aware_(builder.link_aware)
{
connect_signal<event::LEFT_BUTTON_DOWN>(
std::bind(&scroll_label::signal_handler_left_button_down, this, std::placeholders::_2),
@ -105,6 +106,8 @@ void scroll_label::set_text_alpha(unsigned short alpha)
void scroll_label::set_link_aware(bool l)
{
link_aware_ = l;
if(label* widget = get_internal_label()) {
widget->set_link_aware(l);
}
@ -133,6 +136,7 @@ void scroll_label::finalize_subclass()
lbl->set_label(get_label());
lbl->set_can_wrap(wrap_on_);
lbl->set_text_alignment(text_alignment_);
lbl->set_link_aware(link_aware_);
lbl->set_use_markup(get_use_markup());
}
@ -266,6 +270,7 @@ builder_scroll_label::builder_scroll_label(const config& cfg)
, horizontal_scrollbar_mode(get_scrollbar_mode(cfg["horizontal_scrollbar_mode"]))
, wrap_on(cfg["wrap"].to_bool(true))
, text_alignment(decode_text_alignment(cfg["text_alignment"]))
, link_aware(cfg["link_aware"].to_bool(false))
{
}

View file

@ -99,6 +99,8 @@ private:
PangoAlignment text_alignment_;
bool link_aware_;
void finalize_subclass() override;
label* get_internal_label();
@ -149,6 +151,7 @@ struct builder_scroll_label : public builder_styled_widget
scrollbar_container::scrollbar_mode horizontal_scrollbar_mode;
bool wrap_on;
const PangoAlignment text_alignment;
bool link_aware;
};
} // namespace implementation