The Battle for Wesnoth  1.19.5+dev
scroll_label.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2024
3  by Mark de Wever <koraq@xs4all.nl>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #pragma once
17 
19 #include "gui/widgets/label.hpp"
20 
23 
24 namespace gui2
25 {
26 
27 // ------------ WIDGET -----------{
28 
29 class label;
30 class spacer;
31 
32 namespace implementation
33 {
34 struct builder_scroll_label;
35 }
36 
38 {
40 
41 public:
42  explicit scroll_label(const implementation::builder_scroll_label& builder);
43 
44  /** See @ref styled_widget::set_label. */
45  virtual void set_label(const t_string& label) override;
46 
47  /** See @ref styled_widget::set_text_alignment. */
48  virtual void set_text_alignment(const PangoAlignment text_alignment) override;
49 
50  /** See @ref styled_widget::set_use_markup. */
51  virtual void set_use_markup(bool use_markup) override;
52 
53  /** See @ref container_base::set_self_active. */
54  virtual void set_self_active(const bool active) override;
55 
56  /***** ***** ***** setters / getters for members ***** ****** *****/
57 
58  /** See @ref styled_widget::get_active. */
59  virtual bool get_active() const override;
60 
61  /** See @ref styled_widget::get_state. */
62  virtual unsigned get_state() const override;
63 
64  bool can_wrap() const override;
65  void set_can_wrap(bool can_wrap);
66 
67  void set_text_alpha(unsigned short alpha);
68 
69  /** See @ref styled_widget::get_link_aware. */
70  virtual bool get_link_aware() const override
71  {
72  return link_aware_;
73  }
74 
75  void set_link_aware(bool l);
76 
77  void set_text_max_width(int max_width) {
78  label* text_label = get_internal_label();
79  if (text_label) {
80  text_label->set_text_maximum_width(max_width);
81  }
82  }
83 
84 private:
85  /**
86  * Possible states of the widget.
87  *
88  * Note the order of the states must be the same as defined in settings.hpp.
89  */
90  enum state_t {
93  };
94 
95  // It's not needed for now so keep it disabled, no definition exists yet.
96  // void set_state(const state_t state);
97 
98  /**
99  * Current state of the widget.
100  *
101  * The state of the widget determines what to render and how the widget
102  * reacts to certain 'events'.
103  */
105 
106  bool wrap_on_;
107 
108  PangoAlignment text_alignment_;
109 
111 
112  void finalize_subclass() override;
113 
115 
116 public:
117  /** Static type getter that does not rely on the widget being constructed. */
118  static const std::string& type();
119 
120 private:
121  /***** ***** ***** inherited ****** *****/
122 
123  /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
124  virtual const std::string& get_control_type() const override;
125 
126  /***** ***** ***** signal handlers ***** ****** *****/
127 
129 };
130 
131 // }---------- DEFINITION ---------{
132 
134 {
135  explicit scroll_label_definition(const config& cfg);
136 
138  {
139  explicit resolution(const config& cfg);
140 
142  };
143 };
144 
145 // }---------- BUILDER -----------{
146 
147 namespace implementation
148 {
149 
151 {
152  explicit builder_scroll_label(const config& cfg);
153 
155 
156  virtual std::unique_ptr<widget> build() const override;
157 
160  bool wrap_on;
161  const PangoAlignment text_alignment;
163 };
164 
165 } // namespace implementation
166 
167 // }------------ END --------------
168 
169 } // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:172
virtual bool get_active() const override
See styled_widget::get_active.
void set_can_wrap(bool can_wrap)
void signal_handler_left_button_down(const event::ui_event event)
bool can_wrap() const override
See widget::can_wrap.
static const std::string & type()
Static type getter that does not rely on the widget being constructed.
virtual void set_label(const t_string &label) override
See styled_widget::set_label.
virtual void set_text_alignment(const PangoAlignment text_alignment) override
See styled_widget::set_text_alignment.
state_t
Possible states of the widget.
virtual bool get_link_aware() const override
See styled_widget::get_link_aware.
void set_text_alpha(unsigned short alpha)
virtual void set_use_markup(bool use_markup) override
See styled_widget::set_use_markup.
void finalize_subclass() override
Function for the subclasses to do their setup.
label * get_internal_label()
scroll_label(const implementation::builder_scroll_label &builder)
void set_link_aware(bool l)
state_t state_
Current state of the widget.
virtual const std::string & get_control_type() const override
Inherited from styled_widget, implemented by REGISTER_WIDGET.
virtual unsigned get_state() const override
See styled_widget::get_state.
PangoAlignment text_alignment_
virtual void set_self_active(const bool active) override
See container_base::set_self_active.
void set_text_max_width(int max_width)
Base class for creating containers with one or two scrollbar(s).
scrollbar_mode
The way to handle the showing or hiding of the scrollbar.
void set_text_maximum_width(int max_width)
Set how wide the text can become.
std::string label
What to show in the filter's drop-down list.
Definition: manager.cpp:200
ui_event
The event sent to the dispatcher.
Definition: handler.hpp:115
Generic file dialog.
std::shared_ptr< builder_grid > builder_grid_ptr
Contains the implementation details for lexical_cast and shouldn't be used directly.
scrollbar_container::scrollbar_mode vertical_scrollbar_mode
scrollbar_container::scrollbar_mode horizontal_scrollbar_mode
virtual std::unique_ptr< widget > build() const override
virtual std::unique_ptr< widget > build() const=0
scroll_label_definition(const config &cfg)