The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
label.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2008 - 2025
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
21
22namespace gui2
23{
24namespace implementation
25{
26 struct builder_label;
27}
28
29// ------------ WIDGET -----------{
30
31class label : public styled_widget
32{
34
35public:
36 explicit label(const implementation::builder_label& builder);
37
38 /** See @ref widget::can_wrap. */
39 virtual bool can_wrap() const override
40 {
41 return can_wrap_ || characters_per_line_ != 0;
42 }
43
44 /** See @ref styled_widget::get_characters_per_line. */
45 virtual unsigned get_characters_per_line() const override
46 {
48 }
49
50 /** See @ref styled_widget::get_link_aware. */
51 virtual bool get_link_aware() const override
52 {
53 return link_aware_;
54 }
55
56 /** See @ref styled_widget::get_link_aware. */
57 virtual color_t get_link_color() const override
58 {
59 return link_color_;
60 }
61
62 /** See @ref styled_widget::set_active. */
63 virtual void set_active(const bool active) override;
64
65 /** See @ref styled_widget::get_active. */
66 virtual bool get_active() const override
67 {
68 return state_ != DISABLED;
69 }
70
71 /** See @ref styled_widget::get_state. */
72 virtual unsigned get_state() const override
73 {
74 return state_;
75 }
76
77 /** See @ref widget::disable_click_dismiss. */
78 bool disable_click_dismiss() const override
79 {
80 return false;
81 }
82
83 /** See @ref widget::can_mouse_focus. */
84 virtual bool can_mouse_focus() const override
85 {
86 return !tooltip().empty() || get_link_aware();
87 }
88
89 /** See @ref styled_widget::update_canvas. */
90 virtual void update_canvas() override;
91
92 /***** ***** ***** setters / getters for members ***** ****** *****/
93
94 void set_can_wrap(const bool wrap)
95 {
96 can_wrap_ = wrap;
97 }
98
99 void set_characters_per_line(const unsigned characters_per_line)
100 {
101 characters_per_line_ = characters_per_line;
102 }
103
104 void set_link_aware(bool l);
105
106 void set_link_color(const color_t& color);
107
108 void set_can_shrink(bool can_shrink)
109 {
110 can_shrink_ = can_shrink;
111 }
112
113 void set_text_alpha(unsigned short alpha);
114
115private:
116 /**
117 * Possible states of the widget.
118 *
119 * Note the order of the states must be the same as defined in settings.hpp.
120 */
125
126 void set_state(const state_t state);
127
128 /**
129 * Current state of the widget.
130 *
131 * The state of the widget determines what to render and how the widget
132 * reacts to certain 'events'.
133 */
135
136 /** Holds the label can wrap or not. */
138
139 /**
140 * The maximum number of characters per line.
141 *
142 * The maximum is not an exact maximum, it uses the average character width.
143 */
145
146 /**
147 * Whether the label is link aware, rendering links with special formatting
148 * and handling click events.
149 */
151
152 /**
153 * What color links will be rendered in.
154 */
156
158
159 unsigned short text_alpha_;
160
161 /** Inherited from styled_widget. */
162 virtual bool text_can_shrink() override
163 {
164 return can_shrink_;
165 }
166
167public:
168 /** Static type getter that does not rely on the widget being constructed. */
169 static const std::string& type();
170
171private:
172 /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
173 virtual const std::string& get_control_type() const override;
174
175 /***** ***** ***** signal handlers ***** ****** *****/
176
177 /**
178 * Left click signal handler: checks if we clicked on a hyperlink
179 */
180 void signal_handler_left_button_click(bool& handled);
181
182 /**
183 * Right click signal handler: checks if we clicked on a hyperlink, copied to clipboard
184 */
185 void signal_handler_right_button_click(bool& handled);
186
187 /**
188 * Mouse motion signal handler: checks if the cursor is on a hyperlink
189 */
190 void signal_handler_mouse_motion(bool& handled, const point& coordinate);
191
192 /**
193 * Mouse leave signal handler: checks if the cursor left a hyperlink
194 */
195 void signal_handler_mouse_leave(bool& handled);
196
197 /**
198 * Implementation detail for (re)setting the hyperlink cursor.
199 */
200 void update_mouse_cursor(bool enable);
201};
202
203// }---------- DEFINITION ---------{
204
206{
207
208 explicit label_definition(const config& cfg);
209
211 {
212 explicit resolution(const config& cfg);
213
215 };
216};
217
218// }---------- BUILDER -----------{
219
220namespace implementation
221{
222
224{
225 builder_label(const config& cfg);
226
228
229 virtual std::unique_ptr<widget> build() const override;
230
231 bool wrap;
232
234
235 PangoAlignment text_alignment;
236
239};
240
241} // namespace implementation
242
243// }------------ END --------------
244
245} // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition config.hpp:157
void set_can_shrink(bool can_shrink)
Definition label.hpp:108
unsigned short text_alpha_
Definition label.hpp:159
bool can_shrink_
Definition label.hpp:157
virtual bool get_link_aware() const override
See styled_widget::get_link_aware.
Definition label.hpp:51
void signal_handler_left_button_click(bool &handled)
Left click signal handler: checks if we clicked on a hyperlink.
Definition label.cpp:115
virtual bool text_can_shrink() override
Inherited from styled_widget.
Definition label.hpp:162
virtual const std::string & get_control_type() const override
Inherited from styled_widget, implemented by REGISTER_WIDGET.
static const std::string & type()
Static type getter that does not rely on the widget being constructed.
void set_link_color(const color_t &color)
Definition label.cpp:98
void signal_handler_mouse_leave(bool &handled)
Mouse leave signal handler: checks if the cursor left a hyperlink.
Definition label.cpp:180
color_t link_color_
What color links will be rendered in.
Definition label.hpp:155
void signal_handler_right_button_click(bool &handled)
Right click signal handler: checks if we clicked on a hyperlink, copied to clipboard.
Definition label.cpp:145
bool disable_click_dismiss() const override
See widget::disable_click_dismiss.
Definition label.hpp:78
bool link_aware_
Whether the label is link aware, rendering links with special formatting and handling click events.
Definition label.hpp:150
virtual unsigned get_state() const override
See styled_widget::get_state.
Definition label.hpp:72
void set_can_wrap(const bool wrap)
Definition label.hpp:94
virtual void update_canvas() override
See styled_widget::update_canvas.
Definition label.cpp:63
void set_state(const state_t state)
Definition label.cpp:107
void set_characters_per_line(const unsigned characters_per_line)
Definition label.hpp:99
state_t
Possible states of the widget.
Definition label.hpp:121
virtual bool get_active() const override
See styled_widget::get_active.
Definition label.hpp:66
state_t state_
Current state of the widget.
Definition label.hpp:134
virtual void set_active(const bool active) override
See styled_widget::set_active.
Definition label.cpp:82
virtual unsigned get_characters_per_line() const override
See styled_widget::get_characters_per_line.
Definition label.hpp:45
unsigned characters_per_line_
The maximum number of characters per line.
Definition label.hpp:144
void update_mouse_cursor(bool enable)
Implementation detail for (re)setting the hyperlink cursor.
Definition label.cpp:194
virtual color_t get_link_color() const override
See styled_widget::get_link_aware.
Definition label.hpp:57
virtual bool can_mouse_focus() const override
See widget::can_mouse_focus.
Definition label.hpp:84
void set_link_aware(bool l)
Definition label.cpp:89
void set_text_alpha(unsigned short alpha)
Definition label.cpp:73
virtual bool can_wrap() const override
See widget::can_wrap.
Definition label.hpp:39
void signal_handler_mouse_motion(bool &handled, const point &coordinate)
Mouse motion signal handler: checks if the cursor is on a hyperlink.
Definition label.cpp:167
bool can_wrap_
Holds the label can wrap or not.
Definition label.hpp:137
const t_string & tooltip() const
bool empty() const
Definition tstring.hpp:200
const config * cfg
std::string label
What to show in the filter's drop-down list.
Definition manager.cpp:201
Generic file dialog.
Contains the implementation details for lexical_cast and shouldn't be used directly.
The basic class for representing 8-bit RGB or RGBA colour values.
Definition color.hpp:51
virtual std::unique_ptr< widget > build() const override
Definition label.cpp:241
virtual std::unique_ptr< widget > build() const=0
Holds a 2D point.
Definition point.hpp:25