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

◆ scrollable()

TextField & MayaFlux::Portal::Forma::TextField::scrollable ( FormaTarget  in_buf,
Surface &  surface,
Scrollable &  scroller,
std::shared_ptr< Portal::Text::PressParams >  in_params,
std::string  initial_text = {},
float  content_multiplier = 3.F 
)

Fluent creator: place this field inside an already-placed Scrollable, growing itself taller than its viewport and track()ing itself in, wired to scroll past a fixed clip.

scroller is entirely the caller's: build and configure it first - Scrollable::place(), and optionally indicator()/background_color()/ wheel_speed(), all fluent - then pass it here by reference. This method reads scroller.bounds() for the viewport region, places this field at a content region content_multiplier times that viewport's height (top-aligned, same width), and calls scroller.track() with this field's own buf as clip_buf and reposition() as the reflow callback. The same three-call composition shown in the class doc, done once here so callers building the common single-field case do not have to repeat it - nothing about the viewport, its buffer, or any indicator passes through this call, because Scrollable already owns all of that.

Also wires scroller.wheel_handler() onto this field's own element: the field sits on top of the viewport and is added to the Layer after it, so it hit-tests first, and Context::handle_scroll only ever dispatches to the topmost element under the cursor - without this, the wheel would do nothing while the cursor sits directly over the field's own text instead of the viewport's empty margin.

Also relate()s element_id under scroller.viewport_id, so Portal::Forma::destroy(surface, element_id) tears down the scroller's viewport too, even though scroller itself is never owned or stored here - only its Layer-side element needs freeing this way.

Parameters
in_bufPre-created target for the field's text.
surfaceSurface to register the field's element on - must be the same Surface scroller was placed on.
scrollerAlready-placed Scrollable to grow and track into.
in_paramsShared render params. A default-constructed one is allocated if null.
initial_textStarting text. Cursor starts at its end.
content_multiplierContent height as a multiple of scroller's viewport height. Default 3x: enough headroom to type past the viewport before hitting the limit, not so much that most content sits unreachable below a near-empty field.
Returns
*this, with results populated.

Definition at line 249 of file TextField.cpp.

256{
257 const Kinesis::AABB2D viewport = scroller.bounds();
258 const Kinesis::AABB2D content_bounds {
259 .min = glm::vec2(viewport.min.x, viewport.max.y - viewport.height() * content_multiplier),
260 .max = glm::vec2(viewport.max.x, viewport.max.y)
261 };
262
263 place(std::move(in_buf), surface, content_bounds, std::move(in_params), std::move(initial_text));
264
265 TextField field = *this;
266 scroller.track(
267 surface.layer(), element_id, content_bounds,
268 [field](Kinesis::AABB2D shifted) mutable { field.reposition(shifted); },
269 buf);
270
271 surface.layer().relate(element_id, scroller.viewport_id);
272 surface.ctx().on_scroll(element_id, scroller.wheel_handler(surface));
273
274 return *this;
275}
uint32_t element_id
Element id of the text field. Valid after place().
Definition TextField.hpp:94
MAYAFLUX_API TextField & place(FormaTarget in_buf, Surface &surface, Kinesis::AABB2D bounds, std::shared_ptr< Portal::Text::PressParams > in_params, std::string initial_text={})
Register the text field element and wire text editing onto it.
FormaTarget buf
Target the text and caret draw into.

References MayaFlux::Portal::Forma::Scrollable::bounds(), buf, MayaFlux::Portal::Forma::Surface::ctx(), element_id, MayaFlux::Kinesis::AABB2D::height(), MayaFlux::Portal::Forma::Surface::layer(), MayaFlux::Kinesis::AABB2D::max, MayaFlux::Kinesis::AABB2D::min, MayaFlux::Portal::Forma::Context::on_scroll(), place(), MayaFlux::Portal::Forma::Layer::relate(), MayaFlux::Portal::Forma::Scrollable::track(), MayaFlux::Portal::Forma::Scrollable::viewport_id, and MayaFlux::Portal::Forma::Scrollable::wheel_handler().

Referenced by MayaFlux::Portal::Forma::create_text_field().

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