MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ axis_fraction()

std::function< float(glm::vec2)> MayaFlux::Kinesis::axis_fraction ( AABB2D  bounds,
float  handle_extent = 0.F,
bool  horizontal = true,
const std::function< glm::vec2()> &  live_offset = {} 
)
inlinenoexcept

Fraction along one axis of bounds, inverse to fader placement.

horizontal_fader and vertical_fader place the handle's leading edge at min + value * (extent - handle_extent), so the handle centre travels a span shorter than the track by one handle. This subtracts half a handle before dividing by the reduced span, so the handle centre tracks the cursor across the whole range rather than lagging by up to half a handle at the extremes.

Pass handle_extent of zero for mappings with no handle inset, such as a level_meter used as a scrub region.

Parameters
boundsTrack region in NDC.
handle_extentHandle width for horizontal, height for vertical.
horizontalTrue to map the x axis, false for y.
live_offsetOptional. Current translation of the drawn control, e.g. a Scrollable's live scroll offset.
Returns
Callable producing a value in [0, 1].

Definition at line 49 of file Projection.hpp.

50 {}) noexcept
51{
52 const float extent = horizontal ? bounds.width() : bounds.height();
53 const float span = extent - handle_extent;
54 const float origin = horizontal ? bounds.min.x : bounds.min.y;
55 const float half = handle_extent * 0.5F;
56
57 return [origin, half, span, horizontal, live_offset](glm::vec2 p) -> float {
58 if (span <= 0.F)
59 return 0.F;
60 const float shift = live_offset ? (horizontal ? live_offset().x : live_offset().y) : 0.F;
61 const float pos = (horizontal ? p.x : p.y) - shift;
62 return std::clamp((pos - origin - half) / span, 0.F, 1.F);
63 };
64}
float height() const noexcept
Definition Bounds.hpp:80
float width() const noexcept
Definition Bounds.hpp:79

Referenced by MayaFlux::Portal::Forma::Geometry::horizontal_fader(), and MayaFlux::Portal::Forma::Geometry::vertical_fader().

+ Here is the caller graph for this function: