guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
range.hpp
1/*
2 Copyright (c) 2026 ETIB Corporation
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in
6 the Software without restriction, including without limitation the rights to
7 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 of the Software, and to permit persons to whom the Software is furnished to do
9 so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
21 */
22
23#pragma once
24
25#include <functional>
26
27#include "guillaume/ecs/component.hpp"
28
30{
31
58 class Range: public ecs::Component
59 {
60 public:
62 using Handler = std::function<void(float, float)>;
63
64 private:
65 float _min { 0.0f };
66 float _max { 1.0f };
67 float _low { 0.0f };
68 float _high { 1.0f };
69 float _step { 0.0f };
70 Handler _onChanged {};
71
72 public:
77 Range(void) = default;
78
82 ~Range(void) = default;
83
88 float getMin(void) const;
89
98 Range &setMin(float min);
99
104 float getMax(void) const;
105
114 Range &setMax(float max);
115
120 float getLow(void) const;
121
131 Range &setLow(float low);
132
137 float getHigh(void) const;
138
148 Range &setHigh(float high);
149
154 float getStep(void) const;
155
165 Range &setStep(float step);
166
176 Range &setOnChangedHandler(const Handler &handler);
177
182 Handler getOnChangedHandler(void) const;
183
184 private:
192 float sanitize(float value) const;
193
203 void apply(float low, float high);
204 };
205
206} // namespace guillaume::components
Handler getOnChangedHandler(void) const
Get the callback run when the interval changes.
Definition range.cpp:105
Range(void)=default
Create the interval 0 to 1 in the range 0 to 1, without snapping.
Range & setStep(float step)
Set the snapping step.
Definition range.cpp:89
float getLow(void) const
Get the low end of the interval.
Definition range.cpp:62
std::function< void(float, float)> Handler
Callback receiving the new low and high ends, in that order.
Definition range.hpp:62
float getStep(void) const
Get the snapping step.
Definition range.cpp:84
Range & setOnChangedHandler(const Handler &handler)
Set the callback run when the interval changes.
Definition range.cpp:99
float getMin(void) const
Get the lower bound of the range.
Definition range.cpp:30
Range & setMin(float min)
Set the lower bound of the range.
Definition range.cpp:35
float getMax(void) const
Get the upper bound of the range.
Definition range.cpp:46
Range & setLow(float low)
Set the low end of the interval.
Definition range.cpp:67
Range & setMax(float max)
Set the upper bound of the range.
Definition range.cpp:51
~Range(void)=default
Default destructor for the Range component.
float getHigh(void) const
Get the high end of the interval.
Definition range.cpp:73
Range & setHigh(float high)
Set the high end of the interval.
Definition range.cpp:78
Base class of every component: a piece of state attached to an entity, plus a "changed" flag.
Definition component.hpp:72
State. Every class here is plain data attached to an entity.