lxgui
gui_slider.hpp
1 #ifndef LXGUI_GUI_SLIDER_HPP
2 #define LXGUI_GUI_SLIDER_HPP
3 
4 #include "lxgui/gui_frame.hpp"
5 #include "lxgui/gui_orientation.hpp"
6 #include "lxgui/lxgui.hpp"
7 #include "lxgui/utils.hpp"
8 
9 namespace lxgui::gui {
10 
11 class texture;
12 
30 class slider : public frame {
31 public:
32  using base = frame;
33 
35  explicit slider(utils::control_block& block, manager& mgr, const frame_core_attributes& attr);
36 
42  std::string serialize(const std::string& tab) const override;
43 
49  bool can_use_script(const std::string& script_name) const override;
50 
59  void
60  fire_script(const std::string& script_name, const event_data& data = event_data{}) override;
61 
66  void copy_from(const region& obj) override;
67 
72  void set_thumb_texture(utils::observer_ptr<texture> tex);
73 
78  const utils::observer_ptr<texture>& get_thumb_texture() {
79  return thumb_texture_;
80  }
81 
86  utils::observer_ptr<const texture> get_thumb_texture() const {
87  return thumb_texture_;
88  }
89 
94  void set_orientation(orientation orient);
95 
101 
107  void set_min_max_values(float min_value, float max_value);
108 
113  void set_min_value(float min_value);
114 
119  void set_max_value(float max_value);
120 
125  float get_min_value() const;
126 
131  float get_max_value() const;
132 
138  void set_value(float value, bool silent = false);
139 
144  float get_value() const;
145 
150  void set_value_step(float value_step);
151 
156  float get_value_step() const;
157 
162  void set_thumb_draw_layer(layer thumb_layer);
163 
168  layer get_thumb_draw_layer() const;
169 
174  void set_allow_clicks_outside_thumb(bool allow);
175 
182 
189  bool is_in_region(const vector2f& position) const override;
190 
192  void notify_borders_need_update() override;
193 
195  static void register_on_lua(sol::state& lua);
196 
197  static constexpr const char* class_name = "Slider";
198 
199 protected:
200  void constrain_thumb_();
201  void update_thumb_texture_();
202 
204 
205  void parse_attributes_(const layout_node& node) override;
206  void parse_all_nodes_before_children_(const layout_node& node) override;
207 
208  const std::vector<std::string>& get_type_list_() const override;
209 
211 
212  float value_ = 0.0f;
213  float min_value_ = 0.0f;
214  float max_value_ = 1.0f;
215  float value_step_ = 0.1f;
216 
218 
220  utils::observer_ptr<texture> thumb_texture_ = nullptr;
221 
222  bool is_thumb_dragged_ = false;
223 };
224 
225 } // namespace lxgui::gui
226 
227 #endif
Stores a variable number of arguments for an event.
A region that can contain other regions and react to events.
Definition: gui_frame.hpp:255
An node in a layout file.
Manages the user interface.
Definition: gui_manager.hpp:44
The base class of all elements in the GUI.
Definition: gui_region.hpp:161
A frame with a movable texture.
Definition: gui_slider.hpp:30
void set_value(float value, bool silent=false)
Sets this slider's value.
Definition: gui_slider.cpp:217
bool allow_clicks_outside_thumb_
Definition: gui_slider.hpp:217
orientation orientation_
Definition: gui_slider.hpp:210
void notify_borders_need_update() override
Tells this region that its borders need updating.
Definition: gui_slider.cpp:341
void set_orientation(orientation orient)
Sets the orientation of this slider.
Definition: gui_slider.cpp:265
void parse_attributes_(const layout_node &node) override
void set_min_value(float min_value)
Sets this slider's minimum value.
Definition: gui_slider.cpp:164
layer get_thumb_draw_layer() const
Returns the draw layer of this slider's thumb texture.
Definition: gui_slider.cpp:307
static constexpr const char * class_name
Definition: gui_slider.hpp:197
void fire_script(const std::string &script_name, const event_data &data=event_data{}) override
Calls a script.
Definition: gui_slider.cpp:49
bool is_in_region(const vector2f &position) const override
Checks if the provided coordinates are in the slider.
Definition: gui_slider.cpp:319
float get_value() const
Returns this slider's value.
Definition: gui_slider.cpp:295
void set_min_max_values(float min_value, float max_value)
Sets the slider's value range.
Definition: gui_slider.cpp:200
void set_thumb_texture(utils::observer_ptr< texture > tex)
Sets the texture to use for the thumb.
Definition: gui_slider.cpp:251
const utils::observer_ptr< texture > & get_thumb_texture()
Returns the texture used for the thumb.
Definition: gui_slider.hpp:78
void notify_thumb_texture_needs_update_()
Definition: gui_slider.cpp:346
void parse_all_nodes_before_children_(const layout_node &node) override
const std::vector< std::string > & get_type_list_() const override
Definition: gui_slider.cpp:350
utils::observer_ptr< texture > thumb_texture_
Definition: gui_slider.hpp:220
void update_thumb_texture_()
Definition: gui_slider.cpp:328
static void register_on_lua(sol::state &lua)
Registers this region class to the provided Lua state.
float get_value_step() const
Returns this slider's value step.
Definition: gui_slider.cpp:299
utils::observer_ptr< const texture > get_thumb_texture() const
Returns the texture used for the thumb.
Definition: gui_slider.hpp:86
orientation get_orientation() const
Returns the orientation of this slider.
Definition: gui_slider.cpp:303
bool can_use_script(const std::string &script_name) const override
Returns 'true' if this slider can use a script.
Definition: gui_slider.cpp:45
void set_thumb_draw_layer(layer thumb_layer)
Sets the draw layer of this slider's thumb texture.
Definition: gui_slider.cpp:280
void set_value_step(float value_step)
Sets this slider's value step.
Definition: gui_slider.cpp:232
float get_min_value() const
Returns this slider's minimum value.
Definition: gui_slider.cpp:287
void set_max_value(float max_value)
Sets this slider's maximum value.
Definition: gui_slider.cpp:182
bool are_clicks_outside_thumb_allowed() const
Checks if clicks are allowed outside of the thumb.
Definition: gui_slider.cpp:315
slider(utils::control_block &block, manager &mgr, const frame_core_attributes &attr)
Constructor.
Definition: gui_slider.cpp:22
void copy_from(const region &obj) override
Copies a region's parameters into this slider (inheritance).
Definition: gui_slider.cpp:92
void set_allow_clicks_outside_thumb(bool allow)
Allows the user to click anywhere in the slider to relocate the thumb.
Definition: gui_slider.cpp:311
float get_max_value() const
Returns this slider's maximum value.
Definition: gui_slider.cpp:291
std::string serialize(const std::string &tab) const override
Prints all relevant information about this region in a string.
Definition: gui_slider.cpp:31
layer
ID of a layer for rendering inside a frame.
Struct holding all the core information about a frame necessary for its creation.