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