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

◆ horizontal_fader()

MAYAFLUX_API Form< float > MayaFlux::Portal::Forma::Geometry::horizontal_fader ( Kinesis::AABB2D  bounds,
float  handle_w,
glm::vec3  track_color = glm::vec3(0.3F),
glm::vec3  handle_color = glm::vec3(0.9F),
const std::function< glm::vec2()> &  live_offset = {} 
)

Geometry function for a horizontal fader in NDC space.

Parameters
boundsFull extent of the fader in NDC.
handle_wHandle width in NDC units.
track_colorTrack quad color.
handle_colorHandle quad color.
live_offsetOptional. Current translation of the drawn fader, e.g. a Scrollable's live scroll offset. Shifts both the rendered geometry and the drag's cursor mapping.

Definition at line 18 of file FormFactory.cpp.

24{
25 GeometryFn<float> fn = [bounds, handle_w, track_color, handle_color, live_offset](
26 float v, std::vector<uint8_t>& out, Element& el) {
27 const glm::vec2 shift = live_offset ? live_offset() : glm::vec2(0.F);
28 const Kinesis::AABB2D live = bounds.translated(shift);
29
30 float x = live.min.x + v * (live.width() - handle_w);
31 float yt = live.min.y + live.height() * 0.35F;
32 float yb = live.min.y + live.height() * 0.65F;
33
34 Kinesis::AABB2D track { .min = glm::vec2(live.min.x, yt), .max = glm::vec2(live.max.x, yb) };
35 Kinesis::AABB2D handle { .min = glm::vec2(x, live.min.y), .max = glm::vec2(x + handle_w, live.max.y) };
36
37 const Kinesis::AABB2D fill { .min = track.min, .max = { x + handle_w * 0.5F, track.max.y } };
38
39 auto verts = Kakshya::to_mesh_vertices(Kinesis::filled_rect(track, track_color));
40 join_strip(verts, Kakshya::to_mesh_vertices(Kinesis::filled_rect(fill, glm::mix(track_color, handle_color, 0.5F))));
41 join_strip(verts, Kakshya::to_mesh_vertices(Kinesis::filled_rect(handle, handle_color)));
42
43 write_verts(out, verts);
44
45 el.bounds_hint = handle;
46 el.contains = {};
47 };
48
49 return { std::move(fn),
50 Graphics::PrimitiveTopology::TRIANGLE_STRIP,
51 static_cast<size_t>(16) * sizeof(Kakshya::MeshVertex),
52 drag_with<float>(Kinesis::axis_fraction(bounds, handle_w, true, live_offset)) };
53}
std::vector< float > * out
std::function< void(T value, std::vector< uint8_t > &out_bytes, Element &element)> GeometryFn
Geometry function signature.
Definition Mapped.hpp:71
float height() const noexcept
Definition Bounds.hpp:80
AABB2D translated(glm::vec2 offset) const noexcept
Definition Bounds.hpp:84
float width() const noexcept
Definition Bounds.hpp:79
Axis-aligned bounding rectangle in a 2D coordinate space.
Definition Bounds.hpp:63
A bounded, renderable region on a window surface.
Definition Element.hpp:61

References MayaFlux::Kinesis::axis_fraction(), MayaFlux::Kinesis::filled_rect(), MayaFlux::Kinesis::AABB2D::height(), MayaFlux::Kinesis::AABB2D::max, MayaFlux::Kinesis::AABB2D::min, out, MayaFlux::Kakshya::to_mesh_vertices(), MayaFlux::Kinesis::AABB2D::translated(), MayaFlux::Portal::Graphics::TRIANGLE_STRIP, MayaFlux::Kinesis::AABB2D::width(), and write_verts().

+ Here is the call graph for this function: