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

◆ toggle()

MAYAFLUX_API Form< bool > MayaFlux::Portal::Forma::Geometry::toggle ( Kinesis::AABB2D  region,
glm::vec3  color_off = glm::vec3(0.25F),
glm::vec3  color_on = glm::vec3(0.2F, 0.7F, 0.4F),
const std::function< glm::vec2()> &  live_offset = {} 
)

Geometry function for a boolean toggle in NDC space.

Renders region as a filled rect in color_off or color_on based on the current bool value. Interaction is the caller's responsibility.

Parameters
regionNDC bounds of the toggle.
color_offFill color when false.
color_onFill color when true.
live_offsetOptional. Current translation of the drawn toggle - the wire (press_flip) does no coordinate math itself, so only the geometry needs this.

Definition at line 298 of file FormFactory.cpp.

303{
304 GeometryFn<bool> fn = [region, color_off, color_on, live_offset](
305 bool v, std::vector<uint8_t>& out, Element& el) {
306 const glm::vec2 shift = live_offset ? live_offset() : glm::vec2(0.F);
307 const Kinesis::AABB2D live = region.translated(shift);
308
309 write_verts(out, Kakshya::to_mesh_vertices(Kinesis::filled_rect(live, v ? color_on : color_off)));
310 el.bounds_hint = live;
311 el.contains = {};
312 };
313
314 return { std::move(fn),
315 Graphics::PrimitiveTopology::TRIANGLE_STRIP,
316 static_cast<size_t>(4) * sizeof(Kakshya::MeshVertex),
317 press_flip() };
318}
std::vector< float > * out
void write_verts(std::vector< uint8_t > &out, const std::vector< V > &verts)
Write a vertex array into a GeometryFn output buffer.
Definition Geometry.hpp:35
std::function< void(T value, std::vector< uint8_t > &out_bytes, Element &element)> GeometryFn
Geometry function signature.
Definition Mapped.hpp:71
Vertex type for indexed triangle mesh primitives (TRIANGLE_LIST topology)
bool contains(glm::vec2 p) const noexcept
Definition Bounds.hpp:67
AABB2D translated(glm::vec2 offset) const noexcept
Definition Bounds.hpp:84
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::AABB2D::contains(), MayaFlux::Kinesis::filled_rect(), out, press_flip(), MayaFlux::Kakshya::to_mesh_vertices(), MayaFlux::Kinesis::AABB2D::translated(), MayaFlux::Portal::Graphics::TRIANGLE_STRIP, and write_verts().

+ Here is the call graph for this function: