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

◆ create_element() [2/2]

template<typename T >
Mapped< T > MayaFlux::Portal::Forma::create_element ( Surface surface,
GeometryFn< T >  geom,
initial,
Graphics::PrimitiveTopology  topology = Graphics::PrimitiveTopology::TRIANGLE_STRIP,
std::function< float(T)>  project = {} 
)

Build a FormaBuffer, register it, construct a Mapped<T>, add the element to surface's layer, and register it with the application Bridge.

Surface-accepting overload of create_element. Reads the layer and window from surface; everything else matches the existing (Layer&, Window) overload.

After registration, one sync() is run so that bounds_hint and contains populated by the geometry function are visible on the Element before the first frame. This removes the manual

layer->set_bounds(el.element.id, ...);
layer->set_contains(el.element.id, ...);

boilerplate seen at fader-style call sites: those values now arrive directly from the geometry function on construction. The geometry function remains the user's; the sync is the same one that runs every frame.

Template Parameters
TMappedState value type.
Parameters
surfaceCanvas to register the element on.
geomGeometry function producing vertex bytes from T.
initialStarting value written into MappedState.
topologyPrimitive topology for the FormaBuffer.
projectOptional T -> float projection for outbound readers.
Returns
Fully constructed Mapped<T> with element registered.

Definition at line 333 of file Forma.hpp.

338 {})
339{
340 auto mapped = create_element<T>(
341 surface.layer(), surface.window(),
342 std::move(geom), std::move(initial),
343 topology, internal::k_capacity_bytes, std::move(project));
344
345 mapped.sync();
346 if (mapped.element.bounds_hint)
347 surface.layer().set_bounds(mapped.element.id, *mapped.element.bounds_hint);
348 if (mapped.element.contains)
349 surface.layer().set_contains(mapped.element.id, mapped.element.contains);
350
351 return mapped;
352}
bool set_bounds(uint32_t id, Kinesis::AABB2D bounds)
Replace the bounds_hint on an existing element.
Definition Layer.cpp:36
bool set_contains(uint32_t id, std::function< bool(glm::vec2)> fn)
Replace the contains callable on an existing element.
Definition Layer.cpp:45
const std::shared_ptr< Core::Window > & window() const noexcept
Access the rendering target window.
Definition Surface.hpp:126
Layer & layer() noexcept
Access the spatial registry.
Definition Surface.hpp:107