Scroll Labels: allow setting text alignment

This commit is contained in:
Charles Dang 2016-09-11 22:18:09 +11:00
parent d2f31787dd
commit 4e21ae709e
2 changed files with 12 additions and 3 deletions

View file

@ -39,7 +39,11 @@ namespace gui2
REGISTER_WIDGET(scroll_label)
tscroll_label::tscroll_label(bool wrap) : tscrollbar_container(COUNT), state_(ENABLED), wrap_on(wrap)
tscroll_label::tscroll_label(bool wrap, const std::string& text_alignment)
: tscrollbar_container(COUNT)
, state_(ENABLED)
, wrap_on(wrap)
, text_alignment(text_alignment)
{
connect_signal<event::LEFT_BUTTON_DOWN>(
std::bind(
@ -99,6 +103,7 @@ void tscroll_label::finalize_subclass()
assert(lbl);
lbl->set_label(label());
lbl->set_can_wrap(wrap_on);
lbl->set_text_alignment(decode_text_alignment(text_alignment));
}
void tscroll_label::set_can_wrap(bool can_wrap)
@ -239,12 +244,13 @@ tbuilder_scroll_label::tbuilder_scroll_label(const config& cfg)
, horizontal_scrollbar_mode(
get_scrollbar_mode(cfg["horizontal_scrollbar_mode"]))
, wrap_on(cfg["wrap"].to_bool(true))
, text_alignment(cfg["text_alignment"])
{
}
twidget* tbuilder_scroll_label::build() const
{
tscroll_label* widget = new tscroll_label(wrap_on);
tscroll_label* widget = new tscroll_label(wrap_on, text_alignment);
init_control(widget);

View file

@ -45,7 +45,7 @@ class tscroll_label : public tscrollbar_container
friend struct implementation::tbuilder_scroll_label;
public:
tscroll_label(bool wrap);
tscroll_label(bool wrap, const std::string& text_alignment);
/** See @ref tcontrol::set_label. */
virtual void set_label(const t_string& label) override;
@ -91,6 +91,8 @@ private:
tstate state_;
bool wrap_on;
const std::string text_alignment;
void finalize_subclass() override;
/***** ***** ***** inherited ****** *****/
@ -133,6 +135,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;
const std::string text_alignment;
};
} // namespace implementation