Skip to content

Commit

Permalink
GUI2: Add wrap key to [scroll_label]
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Mar 24, 2016
1 parent 16ed12f commit a6fbabe
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
5 changes: 5 additions & 0 deletions data/gui/schema.cfg
Expand Up @@ -1709,6 +1709,11 @@
type="scrollbar_mode"
default=initial_auto
[/key]
[key]
name="wrap"
type="bool"
default=true
[/key]
[/tag]
[tag]
name="scrollbar_panel"
Expand Down
28 changes: 20 additions & 8 deletions src/gui/widgets/scroll_label.cpp
Expand Up @@ -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(
Expand Down Expand Up @@ -95,13 +95,22 @@ void tscroll_label::finalize_subclass()

assert(lbl);
lbl->set_label(label());
lbl->set_can_wrap(wrap_on);
}

void tscroll_label::set_can_wrap(bool can_wrap)
{
assert(content_grid());
tlabel* lbl = dynamic_cast<tlabel*>(content_grid()->find("_label", false));

/**
* @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);
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
Expand Down Expand Up @@ -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/"}
Expand All @@ -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);

Expand Down
7 changes: 6 additions & 1 deletion src/gui/widgets/scroll_label.hpp
Expand Up @@ -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;
Expand All @@ -63,6 +63,9 @@ class tscroll_label : public tscrollbar_container

/** See @ref tcontrol::get_state. */
virtual unsigned get_state() const OVERRIDE;

bool can_wrap() const;
void set_can_wrap(bool can_wrap);

private:
/**
Expand All @@ -86,6 +89,7 @@ class tscroll_label : public tscrollbar_container
* reacts to certain 'events'.
*/
tstate state_;
bool wrap_on;

void finalize_subclass();

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a6fbabe

Please sign in to comment.