From de1c04e1870b9bc93983dd008025593bac8c4fd3 Mon Sep 17 00:00:00 2001 From: Chris Beck Date: Fri, 17 Oct 2014 03:58:11 -0400 Subject: [PATCH] make labels read "link_aware" property from their widget defn This adds a "link_aware" key to label definitions, and C++ tlabel objects no longer initializer this to true, but instead read the value from their definition configuration. --- data/gui/default/widget/label_default.cfg | 2 ++ data/gui/schema.cfg | 5 +++++ src/gui/auxiliary/widget_definition/label.cpp | 10 ++++++++++ src/gui/auxiliary/widget_definition/label.hpp | 2 ++ src/gui/widgets/label.cpp | 16 +++++++++++++++- src/gui/widgets/label.hpp | 4 ++++ 6 files changed, 38 insertions(+), 1 deletion(-) diff --git a/data/gui/default/widget/label_default.cfg b/data/gui/default/widget/label_default.cfg index 501532b9884b..6460f82a9d90 100644 --- a/data/gui/default/widget/label_default.cfg +++ b/data/gui/default/widget/label_default.cfg @@ -23,6 +23,8 @@ text_font_size = {FONT_SIZE} text_font_style = {FONT_STYLE} + link_aware = true + [state_enabled] [draw] diff --git a/data/gui/schema.cfg b/data/gui/schema.cfg index 96cf319a17c9..4ef825628706 100644 --- a/data/gui/schema.cfg +++ b/data/gui/schema.cfg @@ -685,6 +685,11 @@ max="1" super="generic/state" [/tag] + [key] + name="link_aware" + type="bool" + default="false" + [/key] [/tag] [/tag] [tag] diff --git a/src/gui/auxiliary/widget_definition/label.cpp b/src/gui/auxiliary/widget_definition/label.cpp index 0d755495b62a..29326dd78d21 100644 --- a/src/gui/auxiliary/widget_definition/label.cpp +++ b/src/gui/auxiliary/widget_definition/label.cpp @@ -41,12 +41,21 @@ tlabel_definition::tlabel_definition(const config& cfg) * The reason is that labels are often used as visual indication of the state * of the widget it labels. * + * Note: The above is outdated, if "link_aware" is enabled then there is interaction. + * + * * The following states exist: * * state_enabled, the label is enabled. * * state_disabled, the label is disabled. * @begin{parent}{name="gui/"} * @begin{tag}{name="label_definition"}{min=0}{max=-1}{super="generic/widget_definition"} * @begin{tag}{name="resolution"}{min=0}{max=-1}{super="generic/widget_definition/resolution"} + * @begin{table}{config} + * link_aware & bool & false & Whether the label is link aware. This means + * it is rendered with links highlighted, + * and responds to click events on those + * links. $ + * @end{table} * @begin{tag}{name="state_enabled"}{min=0}{max=1}{super="generic/state"} * @end{tag}{name="state_enabled"} * @begin{tag}{name="state_disabled"}{min=0}{max=1}{super="generic/state"} @@ -57,6 +66,7 @@ tlabel_definition::tlabel_definition(const config& cfg) */ tlabel_definition::tresolution::tresolution(const config& cfg) : tresolution_definition_(cfg) + , link_aware(cfg["link_aware"].to_bool(false)) { // Note the order should be the same as the enum tstate is label.hpp. state.push_back(tstate_definition(cfg.child("state_enabled"))); diff --git a/src/gui/auxiliary/widget_definition/label.hpp b/src/gui/auxiliary/widget_definition/label.hpp index a814626e98df..49ea79a063de 100644 --- a/src/gui/auxiliary/widget_definition/label.hpp +++ b/src/gui/auxiliary/widget_definition/label.hpp @@ -28,6 +28,8 @@ struct tlabel_definition : public tcontrol_definition struct tresolution : public tresolution_definition_ { explicit tresolution(const config& cfg); + + bool link_aware; }; }; diff --git a/src/gui/widgets/label.cpp b/src/gui/widgets/label.cpp index 47fc6e52656e..090f9928a784 100644 --- a/src/gui/widgets/label.cpp +++ b/src/gui/widgets/label.cpp @@ -42,7 +42,7 @@ tlabel::tlabel() , state_(ENABLED) , can_wrap_(false) , characters_per_line_(0) - , link_aware_(true) + , link_aware_(false) { connect_signal(boost::bind(&tlabel::signal_handler_left_button_click, this, _2, _3)); connect_signal(boost::bind(&tlabel::signal_handler_right_button_click, this, _2, _3)); @@ -115,6 +115,20 @@ const std::string& tlabel::get_control_type() const return type; } +void tlabel::load_config_extra() +{ + assert(config()); + + boost::intrusive_ptr + conf = boost::dynamic_pointer_cast( + config()); + + assert(conf); + + set_link_aware(conf->link_aware); +} + + void tlabel::signal_handler_left_button_click(const event::tevent /* event */, bool & handled) { DBG_GUI_E << "label click" << std::endl; diff --git a/src/gui/widgets/label.hpp b/src/gui/widgets/label.hpp index 10d45866b238..a950e1b12844 100644 --- a/src/gui/widgets/label.hpp +++ b/src/gui/widgets/label.hpp @@ -99,6 +99,10 @@ class tlabel : public tcontrol /** See @ref tcontrol::get_control_type. */ virtual const std::string& get_control_type() const OVERRIDE; + /** Inherited from tcontrol. */ + void load_config_extra(); + + /***** ***** ***** signal handlers ***** ****** *****/ /** * Left click signal handler: checks if we clicked on a hyperlink