The Battle for Wesnoth  1.19.7+dev
scroll_text.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2023 - 2024
3  by Subhraman Sarkar (babaissarkar) <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 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 
88 private:
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  */
94  enum state_t {
97  };
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 
110  bool wrap_on_;
111 
112  PangoAlignment text_alignment_;
113 
114  bool editable_;
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 
128  assert(horizontal_scrollbar());
130  }
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. */
143  void set_max_size(point max_size);
144 
145 public:
146  /** Static type getter that does not rely on the widget being constructed. */
147  static const std::string& type();
148 
150 
151 private:
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 
178 namespace 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;
190  bool editable;
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:172
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:76
multiline_text * get_internal_text_box()
Definition: scroll_text.cpp:53
static const std::string & type()
Static type getter that does not rely on the widget being constructed.
PangoAlignment text_alignment_
void set_link_aware(bool l)
Definition: scroll_text.cpp:85
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:62
void set_value(const t_string &label)
Definition: scroll_text.hpp:47
void set_editable(bool editable)
Definition: scroll_text.hpp:78
bool is_editable() const
Definition: scroll_text.hpp:83
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.
virtual bool get_link_aware() const override
See styled_widget::get_link_aware.
Definition: scroll_text.hpp:73
state_t state_
Current state of the widget.
virtual void set_text_alignment(const PangoAlignment text_alignment) override
See styled_widget::set_text_alignment.
Definition: scroll_text.cpp:94
bool can_wrap() const override
See widget::can_wrap.
unsigned get_vertical_position()
state_t
Possible states of the widget.
Definition: scroll_text.hpp:94
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_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(std::string_view str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:85
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