guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
guillaume::components::Range Class Reference

An interval [low, high] kept inside a range, with a callback run when it changes. More...

#include <headers/guillaume/components/range.hpp>

Inheritance diagram for guillaume::components::Range:
Collaboration diagram for guillaume::components::Range:

Public Types

using Handler = std::function<void(float, float)>
 Callback receiving the new low and high ends, in that order.

Public Member Functions

 Range (void)=default
 Create the interval 0 to 1 in the range 0 to 1, without snapping.
 ~Range (void)=default
 Default destructor for the Range component.
float getMin (void) const
 Get the lower bound of the range.
Range & setMin (float min)
 Set the lower bound of the range.
float getMax (void) const
 Get the upper bound of the range.
Range & setMax (float max)
 Set the upper bound of the range.
float getLow (void) const
 Get the low end of the interval.
Range & setLow (float low)
 Set the low end of the interval.
float getHigh (void) const
 Get the high end of the interval.
Range & setHigh (float high)
 Set the high end of the interval.
float getStep (void) const
 Get the snapping step.
Range & setStep (float step)
 Set the snapping step.
Range & setOnChangedHandler (const Handler &handler)
 Set the callback run when the interval changes.
Handler getOnChangedHandler (void) const
 Get the callback run when the interval changes.
Public Member Functions inherited from guillaume::ecs::Component
bool hasChanged (void) const
 Tell whether a value of the component changed since the flags were last reset (the end of the previous frame).
void setHasChanged (bool hasChanged)
 Raise or lower the changed flag.
 Component (void)=default
 Create a component that is not marked as changed.
virtual ~Component (void)=default
 Virtual destructor, so components can be destroyed through the base class.

Detailed Description

An interval [low, high] kept inside a range, with a callback run when it changes.

It is the two-ended counterpart of components::Value, meant for controls with two handles such as a range slider. Both ends always lie within [min, max] (0 to 1 by default), are snapped to a multiple of step above min when step is strictly positive, and are kept ordered: if a new low end passes the high end, the two are swapped. No system of the library reads it; it is a building block for application widgets.

range.setMax(100.0f); // the interval is 0 to 1
range.setHigh(80.0f).setLow(90.0f); // the interval is 80 to 90
An interval [low, high] kept inside a range, with a callback run when it changes.
Definition range.hpp:59
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 & setHigh(float high)
Set the high end of the interval.
Definition range.cpp:78

Watch out:

  • The handler runs inside the setter, synchronously, each time the stored interval really changes, including when a new bound clamps it.
  • Keep min <= max: when raising both bounds, set the maximum first.
See also
components::Value

Definition at line 58 of file range.hpp.

Member Typedef Documentation

◆ Handler

using guillaume::components::Range::Handler = std::function<void(float, float)>

Callback receiving the new low and high ends, in that order.

Definition at line 62 of file range.hpp.

Member Function Documentation

◆ getHigh()

float guillaume::components::Range::getHigh ( void ) const

Get the high end of the interval.

Returns
The high end, within [low, max].

Definition at line 73 of file range.cpp.

◆ getLow()

float guillaume::components::Range::getLow ( void ) const

Get the low end of the interval.

Returns
The low end, within [min, high].

Definition at line 62 of file range.cpp.

◆ getMax()

float guillaume::components::Range::getMax ( void ) const

Get the upper bound of the range.

Returns
The maximum (1 by default).

Definition at line 46 of file range.cpp.

◆ getMin()

float guillaume::components::Range::getMin ( void ) const

Get the lower bound of the range.

Returns
The minimum (0 by default).

Definition at line 30 of file range.cpp.

◆ getOnChangedHandler()

Range::Handler guillaume::components::Range::getOnChangedHandler ( void ) const

Get the callback run when the interval changes.

Returns
A copy of the callback, empty when none is set.

Definition at line 105 of file range.cpp.

◆ getStep()

float guillaume::components::Range::getStep ( void ) const

Get the snapping step.

Returns
The step; 0 (the default) or less disables snapping.

Definition at line 84 of file range.cpp.

◆ setHigh()

Range & guillaume::components::Range::setHigh ( float high)

Set the high end of the interval.

The value is clamped and snapped first. If it ends up below the low end, the two ends are swapped. When the interval changes, marks the component changed and calls the handler.

Parameters
highThe requested high end, in the unit of the range.
Returns
This component, for chaining.

Definition at line 78 of file range.cpp.

Here is the call graph for this function:

◆ setLow()

Range & guillaume::components::Range::setLow ( float low)

Set the low end of the interval.

The value is clamped and snapped first. If it ends up above the high end, the two ends are swapped. When the interval changes, marks the component changed and calls the handler.

Parameters
lowThe requested low end, in the unit of the range.
Returns
This component, for chaining.

Definition at line 67 of file range.cpp.

Here is the call graph for this function:

◆ setMax()

Range & guillaume::components::Range::setMax ( float max)

Set the upper bound of the range.

When the bound differs, marks the component changed, then clamps and snaps both ends again, which runs the handler if one moves.

Parameters
maxThe new maximum; it must not be below the minimum.
Returns
This component, for chaining.

Definition at line 51 of file range.cpp.

Here is the call graph for this function:

◆ setMin()

Range & guillaume::components::Range::setMin ( float min)

Set the lower bound of the range.

When the bound differs, marks the component changed, then clamps and snaps both ends again, which runs the handler if one moves.

Parameters
minThe new minimum; it must not exceed the maximum.
Returns
This component, for chaining.

Definition at line 35 of file range.cpp.

Here is the call graph for this function:

◆ setOnChangedHandler()

Range & guillaume::components::Range::setOnChangedHandler ( const Handler & handler)

Set the callback run when the interval changes.

Replaces the previous handler. Does not mark the component changed.

Parameters
handlerThe callback, or an empty one to remove it; it receives the new low and high ends.
Returns
This component, for chaining.

Definition at line 99 of file range.cpp.

Here is the call graph for this function:

◆ setStep()

Range & guillaume::components::Range::setStep ( float step)

Set the snapping step.

Marks the component changed when the step differs. The interval is not snapped again until one of its ends or a bound is set.

Parameters
stepThe distance between two allowed values, counted from the minimum; 0 or less disables snapping.
Returns
This component, for chaining.

Definition at line 89 of file range.cpp.

Here is the call graph for this function:

The documentation for this class was generated from the following files: