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.
This commit is contained in:
Chris Beck 2014-10-17 03:58:11 -04:00
parent 3ccb0b0274
commit de1c04e187
6 changed files with 38 additions and 1 deletions

View file

@ -23,6 +23,8 @@
text_font_size = {FONT_SIZE}
text_font_style = {FONT_STYLE}
link_aware = true
[state_enabled]
[draw]

View file

@ -685,6 +685,11 @@
max="1"
super="generic/state"
[/tag]
[key]
name="link_aware"
type="bool"
default="false"
[/key]
[/tag]
[/tag]
[tag]

View file

@ -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")));

View file

@ -28,6 +28,8 @@ struct tlabel_definition : public tcontrol_definition
struct tresolution : public tresolution_definition_
{
explicit tresolution(const config& cfg);
bool link_aware;
};
};

View file

@ -42,7 +42,7 @@ tlabel::tlabel()
, state_(ENABLED)
, can_wrap_(false)
, characters_per_line_(0)
, link_aware_(true)
, link_aware_(false)
{
connect_signal<event::LEFT_BUTTON_CLICK>(boost::bind(&tlabel::signal_handler_left_button_click, this, _2, _3));
connect_signal<event::RIGHT_BUTTON_CLICK>(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<const tlabel_definition::tresolution>
conf = boost::dynamic_pointer_cast<const tlabel_definition::tresolution>(
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;

View file

@ -99,6 +99,10 @@ private:
/** 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