guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
value.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
55 class Value: public ecs::Component
56 {
57 public:
59 using Handler = std::function<void(float)>;
60
61 private:
62 float _min { 0.0f };
63 float _max { 1.0f };
64 float _value { 0.0f };
65 float _step { 0.0f };
66 Handler _onChanged {};
67
68 public:
72 Value(void) = default;
73
77 ~Value(void) = default;
78
83 float getMin(void) const;
84
94 Value &setMin(float min);
95
100 float getMax(void) const;
101
111 Value &setMax(float max);
112
117 float getValue(void) const;
118
128 Value &setValue(float value);
129
134 float getStep(void) const;
135
146 Value &setStep(float step);
147
153 float getNormalizedValue(void) const;
154
163 Value &setNormalizedValue(float normalized);
164
174 Value &setOnChangedHandler(const Handler &handler);
175
180 Handler getOnChangedHandler(void) const;
181
182 private:
190 float sanitize(float value) const;
191 };
192
193} // namespace guillaume::components
float getStep(void) const
Get the snapping step.
Definition value.cpp:81
~Value(void)=default
Default destructor for the Value component.
float getNormalizedValue(void) const
Get where the value sits in its range.
Definition value.cpp:96
std::function< void(float)> Handler
Callback receiving the new value, already clamped and snapped.
Definition value.hpp:59
Value & setMin(float min)
Set the lower bound of the range.
Definition value.cpp:35
Value(void)=default
Create a value of 0 in the range 0 to 1, without snapping.
Handler getOnChangedHandler(void) const
Get the callback run when the value changes.
Definition value.cpp:117
Value & setOnChangedHandler(const Handler &handler)
Set the callback run when the value changes.
Definition value.cpp:111
float getValue(void) const
Get the current value.
Definition value.cpp:62
float getMin(void) const
Get the lower bound of the range.
Definition value.cpp:30
Value & setNormalizedValue(float normalized)
Set the value from its position in the range.
Definition value.cpp:105
float getMax(void) const
Get the upper bound of the range.
Definition value.cpp:46
Value & setValue(float value)
Set the current value.
Definition value.cpp:67
Value & setMax(float max)
Set the upper bound of the range.
Definition value.cpp:51
Value & setStep(float step)
Set the snapping step.
Definition value.cpp:86
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.