Skip to content

Commit

Permalink
make labels read "link_aware" property from their widget defn
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cbeck88 committed Oct 19, 2014
1 parent 3ccb0b0 commit de1c04e
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 1 deletion.
2 changes: 2 additions & 0 deletions data/gui/default/widget/label_default.cfg
Expand Up @@ -23,6 +23,8 @@
text_font_size = {FONT_SIZE}
text_font_style = {FONT_STYLE}

link_aware = true

[state_enabled]

[draw]
Expand Down
5 changes: 5 additions & 0 deletions data/gui/schema.cfg
Expand Up @@ -685,6 +685,11 @@
max="1"
super="generic/state"
[/tag]
[key]
name="link_aware"
type="bool"
default="false"
[/key]
[/tag]
[/tag]
[tag]
Expand Down
10 changes: 10 additions & 0 deletions src/gui/auxiliary/widget_definition/label.cpp
Expand Up @@ -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"}
Expand All @@ -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")));
Expand Down
2 changes: 2 additions & 0 deletions src/gui/auxiliary/widget_definition/label.hpp
Expand Up @@ -28,6 +28,8 @@ struct tlabel_definition : public tcontrol_definition
struct tresolution : public tresolution_definition_
{
explicit tresolution(const config& cfg);

bool link_aware;
};
};

Expand Down
16 changes: 15 additions & 1 deletion src/gui/widgets/label.cpp
Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/gui/widgets/label.hpp
Expand Up @@ -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
Expand Down

0 comments on commit de1c04e

Please sign in to comment.