The Battle for Wesnoth  1.19.0-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 
22 
23 namespace gui2
24 {
25 
26 // ------------ WIDGET -----------{
27 
28 class label;
29 
30 namespace implementation
31 {
32 struct builder_scroll_label;
33 }
34 
35 /**
36  * @ingroup GUIWidgetWML
37  *
38  * Label showing a text.
39  *
40  * This version shows a scrollbar if the text gets too long and has some scrolling features.
41  * In general this widget is slower as the normal label so the normal label should be preferred.
42  *
43  * Key |Type |Default |Description
44  * -------------|----------------------------|---------|-----------
45  * grid | @ref guivartype_grid "grid"|mandatory|A grid containing the widgets for main widget.
46  *
47  * TODO: we need one definition for a vertical scrollbar since this is the second time we use it.
48  *
49  * ID (return value)|Type |Default |Description
50  * -----------------|----------------------------|---------|-----------
51  * _content_grid | @ref guivartype_grid "grid"|mandatory|A grid which should only contain one label widget.
52  * _scrollbar_grid | @ref guivartype_grid "grid"|mandatory|A grid for the scrollbar (Merge with listbox info.)
53  * The following states exist:
54  * * state_enabled - the scroll label is enabled.
55  * * state_disabled - the scroll label is disabled.
56  * List with the scroll label specific variables:
57  * Key |Type |Default |Description
58  * -------------------------|------------------------------------------------|------------|-----------
59  * vertical_scrollbar_mode | @ref guivartype_scrollbar_mode "scrollbar_mode"|initial_auto|Determines whether or not to show the scrollbar.
60  * horizontal_scrollbar_mode| @ref guivartype_scrollbar_mode "scrollbar_mode"|initial_auto|Determines whether or not to show the scrollbar.
61  */
63 {
65 
66 public:
67  explicit scroll_label(const implementation::builder_scroll_label& builder);
68 
69  /** See @ref styled_widget::set_label. */
70  virtual void set_label(const t_string& label) override;
71 
72  /** See @ref styled_widget::set_text_alignment. */
73  virtual void set_text_alignment(const PangoAlignment text_alignment) override;
74 
75  /** See @ref styled_widget::set_use_markup. */
76  virtual void set_use_markup(bool use_markup) override;
77 
78  /** See @ref container_base::set_self_active. */
79  virtual void set_self_active(const bool active) override;
80 
81  /***** ***** ***** setters / getters for members ***** ****** *****/
82 
83  /** See @ref styled_widget::get_active. */
84  virtual bool get_active() const override;
85 
86  /** See @ref styled_widget::get_state. */
87  virtual unsigned get_state() const override;
88 
89  bool can_wrap() const override;
90  void set_can_wrap(bool can_wrap);
91 
92  void set_text_alpha(unsigned short alpha);
93 
94  void set_link_aware(bool l);
95 
96 private:
97  /**
98  * Possible states of the widget.
99  *
100  * Note the order of the states must be the same as defined in settings.hpp.
101  */
102  enum state_t {
105  };
106 
107  // It's not needed for now so keep it disabled, no definition exists yet.
108  // void set_state(const state_t state);
109 
110  /**
111  * Current state of the widget.
112  *
113  * The state of the widget determines what to render and how the widget
114  * reacts to certain 'events'.
115  */
117 
118  bool wrap_on_;
119 
120  PangoAlignment text_alignment_;
121 
123 
124  void finalize_subclass() override;
125 
127 
128 public:
129  /** Static type getter that does not rely on the widget being constructed. */
130  static const std::string& type();
131 
132 private:
133  /***** ***** ***** inherited ****** *****/
134 
135  /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
136  virtual const std::string& get_control_type() const override;
137 
138  /***** ***** ***** signal handlers ***** ****** *****/
139 
141 };
142 
143 // }---------- DEFINITION ---------{
144 
146 {
147  explicit scroll_label_definition(const config& cfg);
148 
150  {
151  explicit resolution(const config& cfg);
152 
154  };
155 };
156 
157 // }---------- BUILDER -----------{
158 
159 namespace implementation
160 {
161 
163 {
164  explicit builder_scroll_label(const config& cfg);
165 
167 
168  virtual std::unique_ptr<widget> build() const override;
169 
172  bool wrap_on;
173  const PangoAlignment text_alignment;
175 };
176 
177 } // namespace implementation
178 
179 // }------------ END --------------
180 
181 } // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159
A label displays text that can be wrapped but no scrollbars are provided.
Definition: label.hpp:56
Label showing a text.
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.
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.
Base class for creating containers with one or two scrollbar(s).
scrollbar_mode
The way to handle the showing or hiding of the scrollbar.
std::string label
What to show in the filter's drop-down list.
Definition: manager.cpp:209
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
Base class of a resolution, contains the common keys for a resolution.
scroll_label_definition(const config &cfg)