The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
scroll_text.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2023 - 2025
3 by Subhraman Sarkar (babaissarkar) <sbmskmm@protonmail.com>
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
22
24
25namespace gui2
26{
27
28// ------------ WIDGET -----------{
29
30namespace implementation
31{
32struct builder_scroll_text;
33}
34
36{
38
39public:
40 explicit scroll_text(const implementation::builder_scroll_text& builder);
41
42// /** See @ref styled_widget::set_label. */
43 virtual void set_label(const t_string& label) override;
44
45// void set_value(const std::string text);
46
47 void set_value(const t_string& label) {
49 }
50
51 std::string get_value();
52
53 /** See @ref styled_widget::set_text_alignment. */
54 virtual void set_text_alignment(const PangoAlignment text_alignment) override;
55
56 /** See @ref container_base::set_self_active. */
57 virtual void set_self_active(const bool active) override;
58
59 /***** ***** ***** setters / getters for members ***** ****** *****/
60
61 /** See @ref styled_widget::get_active. */
62 virtual bool get_active() const override;
63
64 /** See @ref styled_widget::get_state. */
65 virtual unsigned get_state() const override;
66
67 bool can_wrap() const override;
68 void set_can_wrap(bool can_wrap);
69
70 void set_link_aware(bool l);
71
72 /** See @ref styled_widget::get_link_aware. */
73 virtual bool get_link_aware() const override
74 {
75 return link_aware_;
76 }
77
78 void set_editable(bool editable)
79 {
80 editable_ = editable;
81 }
82
83 bool is_editable() const
84 {
85 return editable_;
86 }
87
88private:
89 /**
90 * Possible states of the widget.
91 *
92 * Note the order of the states must be the same as defined in settings.hpp.
93 */
98
99 // It's not needed for now so keep it disabled, no definition exists yet.
100 // void set_state(const state_t state);
101
102 /**
103 * Current state of the widget.
104 *
105 * The state of the widget determines what to render and how the widget
106 * reacts to certain 'events'.
107 */
109
111
112 PangoAlignment text_alignment_;
113
115
117
119
120 void finalize_subclass() override;
121
122 /** Used for moving scrollbars.
123 Has to be called from signal notify_modified, otherwise
124 doesn't work after invalidate_layout. */
125 void refresh();
126
131
133 assert(vertical_scrollbar());
135 }
136
137 void place(const point& origin, const point& size) override;
138
139 /** See @ref widget::calculate_best_size. */
140 point calculate_best_size() const override;
141
142 /** Sets the size of the text beyond which scrollbars should be visible. */
144
145public:
146 /** Static type getter that does not rely on the widget being constructed. */
147 static const std::string& type();
148
150
151private:
152 /***** ***** ***** inherited ****** *****/
153
154 /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
155 virtual const std::string& get_control_type() const override;
156
157 /***** ***** ***** signal handlers ***** ****** *****/
158
160};
161
162// }---------- DEFINITION ---------{
163
165{
166 explicit scroll_text_definition(const config& cfg);
167
169 {
170 explicit resolution(const config& cfg);
171
173 };
174};
175
176// }---------- BUILDER -----------{
177
178namespace implementation
179{
180
182{
183 explicit builder_scroll_text(const config& cfg);
184
186
187 virtual std::unique_ptr<widget> build() const override;
188
189 const PangoAlignment text_alignment;
192};
193
194} // namespace implementation
195
196// }------------ END --------------
197
198} // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition config.hpp:157
static const std::string & type()
Static type getter that does not rely on the widget being constructed.
virtual const std::string & get_control_type() const override
Inherited from styled_widget, implemented by REGISTER_WIDGET.
void set_max_size(point max_size)
Sets the size of the text beyond which scrollbars should be visible.
void signal_handler_left_button_down(const event::ui_event event)
unsigned get_horizontal_position()
void refresh()
Used for moving scrollbars.
virtual unsigned get_state() const override
See styled_widget::get_state.
std::string get_value()
multiline_text * get_internal_text_box()
PangoAlignment text_alignment_
void set_link_aware(bool l)
void set_can_wrap(bool can_wrap)
void finalize_subclass() override
Function for the subclasses to do their setup.
virtual void set_label(const t_string &label) override
void set_value(const t_string &label)
void set_editable(bool editable)
bool is_editable() const
virtual void set_self_active(const bool active) override
See container_base::set_self_active.
void place(const point &origin, const point &size) override
See widget::place.
point calculate_best_size() const override
See widget::calculate_best_size.
virtual bool get_active() const override
See styled_widget::get_active.
virtual bool get_link_aware() const override
See styled_widget::get_link_aware.
state_t state_
Current state of the widget.
virtual void set_text_alignment(const PangoAlignment text_alignment) override
See styled_widget::set_text_alignment.
bool can_wrap() const override
See widget::can_wrap.
unsigned get_vertical_position()
state_t
Possible states of the widget.
unsigned get_positioner_offset() const
Base class for creating containers with one or two scrollbar(s).
scrollbar_base * horizontal_scrollbar()
scrollbar_base * vertical_scrollbar()
const config * cfg
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.
const std::size_t max_size
Definition sound.cpp:145
virtual std::unique_ptr< widget > build() const override
virtual std::unique_ptr< widget > build() const=0
Holds a 2D point.
Definition point.hpp:25