The Battle for Wesnoth  1.19.0-dev
scroll_text.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2023 - 2024
3  by babaissarkar(Subhraman Sarkar) <suvrax@gmail.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 
25 namespace gui2
26 {
27 
28 // ------------ WIDGET -----------{
29 
30 namespace implementation
31 {
32 struct builder_scroll_text;
33 }
34 
36 {
38 
39 public:
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 styled_widget::set_use_markup. */
57  virtual void set_use_markup(bool use_markup) override;
58 
59  /** See @ref container_base::set_self_active. */
60  virtual void set_self_active(const bool active) override;
61 
62  /***** ***** ***** setters / getters for members ***** ****** *****/
63 
64  /** See @ref styled_widget::get_active. */
65  virtual bool get_active() const override;
66 
67  /** See @ref styled_widget::get_state. */
68  virtual unsigned get_state() const override;
69 
70  bool can_wrap() const override;
71  void set_can_wrap(bool can_wrap);
72 
73  void set_editable(bool editable)
74  {
75  editable_ = editable;
76  }
77 
78  bool is_editable()
79  {
80  return editable_;
81  }
82 
83 private:
84  /**
85  * Possible states of the widget.
86  *
87  * Note the order of the states must be the same as defined in settings.hpp.
88  */
89  enum state_t {
92  };
93 
94  // It's not needed for now so keep it disabled, no definition exists yet.
95  // void set_state(const state_t state);
96 
97  /**
98  * Current state of the widget.
99  *
100  * The state of the widget determines what to render and how the widget
101  * reacts to certain 'events'.
102  */
104 
105  bool wrap_on_;
106 
107  PangoAlignment text_alignment_;
108 
109  bool editable_;
110 
112 
113  void finalize_subclass() override;
114 
115  /** Used for moving scrollbars.
116  Has to be called from signal notify_modified, otherwise
117  doesn't work after invalidate_layout. */
118  void refresh();
119 
121  assert(horizontal_scrollbar());
123  }
124 
126  assert(vertical_scrollbar());
128  }
129 
130  void place(const point& origin, const point& size) override;
131 
132  /** See @ref widget::calculate_best_size. */
133  point calculate_best_size() const override;
134 
135  /** Sets the size of the text beyond which scrollbars should be visible. */
136  void set_max_size(point max_size);
137 
138 public:
139  /** Static type getter that does not rely on the widget being constructed. */
140  static const std::string& type();
141 
143 
144 private:
145  /***** ***** ***** inherited ****** *****/
146 
147  /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
148  virtual const std::string& get_control_type() const override;
149 
150  /***** ***** ***** signal handlers ***** ****** *****/
151 
153 };
154 
155 // }---------- DEFINITION ---------{
156 
158 {
159  explicit scroll_text_definition(const config& cfg);
160 
162  {
163  explicit resolution(const config& cfg);
164 
166  };
167 };
168 
169 // }---------- BUILDER -----------{
170 
171 namespace implementation
172 {
173 
175 {
176  explicit builder_scroll_text(const config& cfg);
177 
179 
180  virtual std::unique_ptr<widget> build() const override;
181 
184  const PangoAlignment text_alignment;
185  bool editable;
186 };
187 
188 } // namespace implementation
189 
190 // }------------ END --------------
191 
192 } // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159
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()
Definition: scroll_text.cpp:74
multiline_text * get_internal_text_box()
Definition: scroll_text.cpp:52
static const std::string & type()
Static type getter that does not rely on the widget being constructed.
PangoAlignment text_alignment_
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
Definition: scroll_text.cpp:61
void set_value(const t_string &label)
Definition: scroll_text.hpp:47
void set_editable(bool editable)
Definition: scroll_text.hpp:73
virtual void set_self_active(const bool active) override
See container_base::set_self_active.
scroll_text(const implementation::builder_scroll_text &builder)
Definition: scroll_text.cpp:39
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.
state_t state_
Current state of the widget.
virtual void set_use_markup(bool use_markup) override
See styled_widget::set_use_markup.
Definition: scroll_text.cpp:95
virtual void set_text_alignment(const PangoAlignment text_alignment) override
See styled_widget::set_text_alignment.
Definition: scroll_text.cpp:83
bool can_wrap() const override
See widget::can_wrap.
unsigned get_vertical_position()
state_t
Possible states of the widget.
Definition: scroll_text.hpp:89
virtual const std::string & get_control_type() const override
Inherited from styled_widget, implemented by REGISTER_WIDGET.
unsigned get_positioner_offset() const
Definition: scrollbar.hpp:179
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_base * vertical_scrollbar()
scrollbar_base * horizontal_scrollbar()
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.
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:85
scrollbar_container::scrollbar_mode horizontal_scrollbar_mode
scrollbar_container::scrollbar_mode vertical_scrollbar_mode
virtual std::unique_ptr< widget > build() const override
virtual std::unique_ptr< widget > build() const=0
scroll_text_definition(const config &cfg)
Holds a 2D point.
Definition: point.hpp:25