The Battle for Wesnoth  1.17.0-dev
scroll_label.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2018 by Mark de Wever <koraq@xs4all.nl>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #pragma once
16 
18 
21 
22 namespace gui2
23 {
24 
25 // ------------ WIDGET -----------{
26 
27 class label;
28 class spacer;
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 
126  label* get_internal_label();
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 
140  void signal_handler_left_button_down(const event::ui_event event);
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 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
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:48
A label displays a text, the text can be wrapped but no scrollbars are provided.
Definition: label.hpp:56
state_t
Possible states of the widget.
Generic file dialog.
Definition: field-fwd.hpp:22
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:216
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:392
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:59
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:47