GUI2: Add wrap key to [scroll_label]

This commit is contained in:
Celtic Minstrel 2016-03-24 17:33:17 -04:00
parent 16ed12f7de
commit a6fbabead2
3 changed files with 31 additions and 9 deletions

View file

@ -1709,6 +1709,11 @@
type="scrollbar_mode"
default=initial_auto
[/key]
[key]
name="wrap"
type="bool"
default=true
[/key]
[/tag]
[tag]
name="scrollbar_panel"

View file

@ -39,7 +39,7 @@ namespace gui2
REGISTER_WIDGET(scroll_label)
tscroll_label::tscroll_label() : tscrollbar_container(COUNT), state_(ENABLED)
tscroll_label::tscroll_label(bool wrap) : tscrollbar_container(COUNT), state_(ENABLED), wrap_on(wrap)
{
connect_signal<event::LEFT_BUTTON_DOWN>(
boost::bind(
@ -95,13 +95,22 @@ void tscroll_label::finalize_subclass()
assert(lbl);
lbl->set_label(label());
lbl->set_can_wrap(wrap_on);
}
/**
* @todo wrapping should be a label setting.
* This setting shoul be mutual exclusive with the horizontal scrollbar.
* Also the scroll_grid needs to set the status for the scrollbars.
*/
lbl->set_can_wrap(true);
void tscroll_label::set_can_wrap(bool can_wrap)
{
assert(content_grid());
tlabel* lbl = dynamic_cast<tlabel*>(content_grid()->find("_label", false));
assert(lbl);
wrap_on = can_wrap;
lbl->set_can_wrap(wrap_on);
}
bool tscroll_label::can_wrap() const
{
return wrap_on;
}
const std::string& tscroll_label::get_control_type() const
@ -210,6 +219,8 @@ tscroll_label_definition::tresolution::tresolution(const config& cfg)
* horizontal_scrollbar_mode & scrollbar_mode & initial_auto &
* Determines whether or not to show the
* scrollbar. $
* wrap & boolean & true & Determines whether the text of the
* label is allowed to wrap. $
* @end{table}
* @end{tag}{name="scroll_label"}
* @end{parent}{name="gui/window/resolution/grid/row/column/"}
@ -224,12 +235,13 @@ tbuilder_scroll_label::tbuilder_scroll_label(const config& cfg)
get_scrollbar_mode(cfg["vertical_scrollbar_mode"]))
, horizontal_scrollbar_mode(
get_scrollbar_mode(cfg["horizontal_scrollbar_mode"]))
, wrap_on(cfg["wrap"].to_bool(true))
{
}
twidget* tbuilder_scroll_label::build() const
{
tscroll_label* widget = new tscroll_label();
tscroll_label* widget = new tscroll_label(wrap_on);
init_control(widget);

View file

@ -45,7 +45,7 @@ class tscroll_label : public tscrollbar_container
friend struct implementation::tbuilder_scroll_label;
public:
tscroll_label();
tscroll_label(bool wrap);
/** See @ref tcontrol::set_label. */
virtual void set_label(const t_string& label) OVERRIDE;
@ -63,6 +63,9 @@ public:
/** See @ref tcontrol::get_state. */
virtual unsigned get_state() const OVERRIDE;
bool can_wrap() const;
void set_can_wrap(bool can_wrap);
private:
/**
@ -86,6 +89,7 @@ private:
* reacts to certain 'events'.
*/
tstate state_;
bool wrap_on;
void finalize_subclass();
@ -128,6 +132,7 @@ struct tbuilder_scroll_label : public tbuilder_control
tscrollbar_container::tscrollbar_mode vertical_scrollbar_mode;
tscrollbar_container::tscrollbar_mode horizontal_scrollbar_mode;
bool wrap_on;
};
} // namespace implementation