lxgui
Loading...
Searching...
No Matches
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
9namespace lxgui::gui {
10
11class texture;
12
30class slider : public frame {
31public:
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
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
199protected:
200 void constrain_thumb_();
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.
An node in a layout file.
Manages the user interface.
The base class of all elements in the GUI.
A frame with a movable texture.
void set_value(float value, bool silent=false)
Sets this slider's value.
orientation orientation_
void notify_borders_need_update() override
Tells this region that its borders need updating.
void set_orientation(orientation orient)
Sets the orientation of this slider.
void parse_attributes_(const layout_node &node) override
void set_min_value(float min_value)
Sets this slider's minimum value.
layer get_thumb_draw_layer() const
Returns the draw layer of this slider's thumb texture.
static constexpr const char * class_name
void fire_script(const std::string &script_name, const event_data &data=event_data{}) override
Calls a script.
bool is_in_region(const vector2f &position) const override
Checks if the provided coordinates are in the slider.
float get_value() const
Returns this slider's value.
void set_min_max_values(float min_value, float max_value)
Sets the slider's value range.
void set_thumb_texture(utils::observer_ptr< texture > tex)
Sets the texture to use for the thumb.
void notify_thumb_texture_needs_update_()
void parse_all_nodes_before_children_(const layout_node &node) override
const std::vector< std::string > & get_type_list_() const override
utils::observer_ptr< texture > thumb_texture_
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.
orientation get_orientation() const
Returns the orientation of this slider.
bool can_use_script(const std::string &script_name) const override
Returns 'true' if this slider can use a script.
void set_thumb_draw_layer(layer thumb_layer)
Sets the draw layer of this slider's thumb texture.
void set_value_step(float value_step)
Sets this slider's value step.
float get_min_value() const
Returns this slider's minimum value.
void set_max_value(float max_value)
Sets this slider's maximum value.
bool are_clicks_outside_thumb_allowed() const
Checks if clicks are allowed outside of the thumb.
void copy_from(const region &obj) override
Copies a region's parameters into this slider (inheritance).
void set_allow_clicks_outside_thumb(bool allow)
Allows the user to click anywhere in the slider to relocate the thumb.
const utils::observer_ptr< texture > & get_thumb_texture()
Returns the texture used for the thumb.
float get_max_value() const
Returns this slider's maximum value.
utils::observer_ptr< const texture > get_thumb_texture() const
Returns the texture used for the thumb.
std::string serialize(const std::string &tab) const override
Prints all relevant information about this region in a string.
layer
ID of a layer for rendering inside a frame.
Struct holding all the core information about a frame necessary for its creation.