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

◆ place()

Scrollable & MayaFlux::Portal::Forma::Scrollable::place ( FormaTarget  in_buf,
Surface &  surface,
Kinesis::AABB2D  viewport 
)

Register the viewport element, wire wheel scrolling, and populate scroll, offset, buf, and cursor_out.

Parameters
in_bufPre-created buffer for the viewport background. Its render processor is scissored to viewport, so give a slice of a create_buffer() buffer and create the tracked elements as slices of the same buffer: one scissor then clips them all. Elements on buffers of their own are scissored individually by track(), as before. Do not share this buffer with anything that must draw outside the viewport.
surfaceSurface to register the viewport on.
viewportNDC region: hit-test bounds, wheel-scroll trigger region, background quad, and the Scissor clip every track()ed element with a buffer gets.
Returns
*this, with results populated.

Definition at line 47 of file Scrollable.cpp.

51{
52 buf = std::move(in_buf);
53 viewport_bounds = viewport;
54
56
57 if (buf) {
58 if (auto render = buf->get_render_processor())
59 render->set_scissor(Kinesis::Scissor::from(viewport));
60 }
61
62 Element el = Element {}
63 .with_name("scrollable_viewport")
64 .with_bounds(viewport)
65 .with_buffer(buf);
66
67 viewport_id = surface.layer().add(el);
68
69 scroll = std::make_shared<Kinesis::ScrollState>();
70 scroll->viewport_bounds = viewport;
71 scroll->content_bounds = viewport;
72
73 offset = std::make_shared<MappedState<glm::vec2>>();
74
75 m_tracked = std::make_shared<std::vector<Tracked>>();
76 m_indicator = std::make_shared<Mapped<glm::vec2>>();
77
78 cursor_out = LayoutCursor(viewport.max.y, viewport.min.x, viewport.max.x);
80
81 surface.ctx().on_scroll(viewport_id, wheel_handler(surface));
82
83 return *this;
84}
virtual std::shared_ptr< RenderProcessor > get_render_processor() const
Get a RenderProcessor suitable for rendering this buffer.
Definition VKBuffer.hpp:605
void submit(const std::vector< uint8_t > &bytes) const
Replace this target's geometry.
Definition Target.cpp:51
void bind_scroll(std::shared_ptr< MappedState< glm::vec2 > > offset)
Bind a live scroll offset.
std::array< Kakshya::Vertex, 4 > filled_rect(Kinesis::AABB2D region, glm::vec3 color)
Generate a filled TRIANGLE_STRIP quad from an AABB2D.
static Scissor from(AABB2D ndc_bounds) noexcept
Construct directly from an NDC AABB2D.
Definition Scissor.hpp:37
MAYAFLUX_API std::function< void(uint32_t, glm::vec2, double, double)> wheel_handler(Surface &surface) const
A self-contained wheel-scroll handler bound to this Scrollable's own state.
Kinesis::AABB2D viewport_bounds
NDC region occupied by the viewport. Valid after place().
std::shared_ptr< MappedState< glm::vec2 > > offset
Reactive mirror of scroll->offset, bound into cursor_out. Valid after place().
std::shared_ptr< Mapped< glm::vec2 > > m_indicator
uint32_t viewport_id
Element id of the viewport background. Valid after place().
FormaTarget buf
FormaBuffer backing the viewport background. Valid after place().
glm::vec3 m_background
Background fill color. Default: glm::vec3(0.08F, 0.08F, 0.1F).
std::shared_ptr< std::vector< Tracked > > m_tracked
std::shared_ptr< Kinesis::ScrollState > scroll
Clamped scroll offset and content/viewport extents. Valid after place().
LayoutCursor cursor_out
Cursor scoped to the viewport, bound to offset. Valid after place().

References MayaFlux::Portal::Forma::Layer::add(), MayaFlux::Portal::Forma::LayoutCursor::bind_scroll(), buf, MayaFlux::Portal::Forma::Surface::ctx(), cursor_out, MayaFlux::Kinesis::filled_rect(), MayaFlux::Kinesis::Scissor::from(), MayaFlux::Buffers::VKBuffer::get_render_processor(), MayaFlux::Portal::Forma::Surface::layer(), m_background, m_indicator, m_tracked, MayaFlux::Kinesis::AABB2D::max, MayaFlux::Kinesis::AABB2D::min, offset, MayaFlux::Portal::Forma::Context::on_scroll(), scroll, MayaFlux::Portal::Forma::FormaTarget::submit(), viewport_bounds, viewport_id, wheel_handler(), MayaFlux::Portal::Forma::Element::with_bounds(), MayaFlux::Portal::Forma::Element::with_buffer(), and MayaFlux::Portal::Forma::Element::with_name().

Referenced by MayaFlux::Portal::Forma::create_text_field(), and MayaFlux::Portal::Forma::make_scrollable().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: