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

◆ make_entry() [2/2]

MAYAFLUX_API Entry MayaFlux::Portal::Forma::make_entry ( const EntrySpec &  spec,
EntryBuffer  row_buf,
Surface &  surface,
LayoutCursor &  cursor,
float  x_min,
float  x_max,
float  row_h,
glm::vec3  bg = glm::vec3(0.15F) 
)

Construct one labeled entry row, advance the cursor, and return it.

The row is one slice of glyph quads: bg is drawn as the fill beneath the text (Portal::Text::PressParams::background), so one slice carries both. The link's compose function runs immediately (establish) so the row shows correctly from the first frame, and again on every subsequent link.tap(), drawing "label: entry" into the row's buffer. The buffer is pre-created by the caller as row_buf.

Bounds come from cursor.advance()'s return (scroll-offset aware, per LayoutCursor::bind_scroll), with x_min/x_max substituted in afterward for this call's own column override - not from cursor.y() read directly, so a row placed through a scroll-bound cursor lands at the correct position immediately.

Parameters
specLabel and reader for the row.
row_bufPre-created text-capable buffer.
surfaceSurface to register the row on.
cursorLayout cursor. Advanced by row_h on return.
x_minLeft edge in NDC.
x_maxRight edge in NDC.
row_hRow height in NDC units.
bgBackground fill drawn beneath the row's text.

Definition at line 32 of file Entry.cpp.

39{
40 const Kinesis::AABB2D advanced = cursor.advance(row_h);
41 const Kinesis::AABB2D row_rect { .min = { x_min, advanced.min.y }, .max = { x_max, advanced.max.y } };
42
43 const glm::uvec2 dims = row_pixel_dims(surface.window(), x_min, x_max, row_h);
44
45 auto params = std::make_shared<Portal::Text::PressParams>(Portal::Text::PressParams {
46 .color = { 1.F, 1.F, 1.F, 1.F },
47 .background = { bg, 1.F },
48 .render_bounds = dims,
49 });
50
51 Element el;
52 el.buffer = row_buf.buf;
53 el.bounds_hint = row_rect;
54 el.interactive = false;
55 el.name = spec.label;
56 el.with_text(spec.label, *params, row_rect);
57 const uint32_t id = surface.layer().add(el);
58
59 auto compose = [reader = spec.reader,
60 label = spec.label,
61 el,
62 params,
63 last = std::optional<std::string> {}]() mutable {
64 if (!reader)
65 return;
66
67 std::string text = label + ": " + reader();
68 if (last && *last == text)
69 return;
70 last = text;
71
72 el.set_text(text, *params);
73 };
74
75 surface.ctx().on_resize(id,
76 [el, surface, params, label = spec.label, reader = spec.reader,
77 x_min, x_max, row_h](uint32_t, uint32_t) mutable {
78 params->render_bounds = row_pixel_dims(surface.window(), x_min, x_max, row_h);
79 el.set_text(reader ? (label + ": " + reader()) : label, *params);
80 });
81
82 Link link(compose, compose);
83
84 return Entry {
85 .element_id = id,
86 .buf = std::move(row_buf.buf),
87 .link = std::move(link),
88 .row_bounds = row_rect,
89 };
90}
uint32_t label
Definition Contours.cpp:16
void on_resize(uint32_t id, ResizeFn fn)
Called on every window resize.
Definition Context.cpp:136
Slot add(Element element)
Add an element to the layer.
Definition Layer.cpp:9
Kinesis::AABB2D advance(float height)
Advance the cursor downward by height and return the NDC AABB occupied by the primitive just placed,...
const std::shared_ptr< Core::Window > & window() const noexcept
Access the rendering target window.
Definition Surface.hpp:178
Context & ctx() noexcept
Access the event router.
Definition Surface.hpp:170
Layer & layer() noexcept
Access the spatial registry.
Definition Surface.hpp:159
Axis-aligned bounding rectangle in a 2D coordinate space.
Definition Bounds.hpp:63
std::function< std::string()> reader
Definition Entry.hpp:31

References MayaFlux::Portal::Forma::Layer::add(), MayaFlux::Portal::Forma::LayoutCursor::advance(), MayaFlux::Portal::Forma::EntryBuffer::buf, MayaFlux::Portal::Forma::Element::buffer, MayaFlux::Portal::Text::PressParams::color, MayaFlux::Portal::Forma::Surface::ctx(), MayaFlux::Portal::Forma::Entry::element_id, label, MayaFlux::Portal::Forma::EntrySpec::label, MayaFlux::Portal::Forma::Surface::layer(), MayaFlux::Kinesis::AABB2D::max, MayaFlux::Kinesis::AABB2D::min, MayaFlux::Portal::Forma::Context::on_resize(), MayaFlux::Portal::Forma::EntrySpec::reader, row_pixel_dims(), and MayaFlux::Portal::Forma::Surface::window().

Referenced by make_entry(), and make_entry_group().

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