MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Entry.cpp
Go to the documentation of this file.
1#include "Entry.hpp"
2
7
9
11
12glm::uvec2 row_pixel_dims(
13 const std::shared_ptr<Core::Window>& window,
14 float x_min, float x_max, float row_h)
15{
16 const auto& ws = window->get_state();
17 const auto w = static_cast<uint32_t>(
18 (x_max - x_min) * 0.5F * static_cast<float>(ws.current_width));
19 const auto h = static_cast<uint32_t>(
20 row_h * 0.5F * static_cast<float>(ws.current_height));
22 if (!atlas) {
24 std::source_location::current(),
25 "Failed to get default glyph atlas for row pixel dimension calculation");
26 }
27 const uint32_t min_h = atlas->pixel_size();
28
29 return { std::max(w, 1U), std::max(h, min_h) };
30}
31
33 const EntrySpec& spec,
34 EntryBuffer row_buf,
35 Surface& surface,
36 LayoutCursor& cursor,
37 float x_min, float x_max, float row_h,
38 glm::vec3 bg)
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}
91
93 const EntrySpec& spec,
94 EntryBuffer row_buf,
95 Surface& surface,
96 LayoutCursor& cursor,
97 float row_h,
98 glm::vec3 bg)
99{
100 return make_entry(spec, std::move(row_buf), surface, cursor,
101 cursor.x_min(), cursor.x_max(), row_h, bg);
102}
103
105 std::span<const EntrySpec> entrys,
106 std::string_view header_label,
107 FormaTarget header_buf,
108 std::span<const EntryBuffer> row_bufs,
109 Surface& surface,
110 LayoutCursor& cursor,
111 float x_min, float x_max, float row_h,
112 bool initially_open)
113{
114 auto header = Collapsible {}
115 .initially_open(initially_open)
116 .closed_color(glm::vec3(0.25F))
117 .open_color(glm::vec3(0.35F))
118 .label(std::string(header_label))
119 .place(std::move(header_buf), surface, cursor, x_min, x_max, row_h);
120
121 std::vector<Entry> rows;
122 rows.reserve(entrys.size());
123 for (size_t i = 0; i < entrys.size(); ++i) {
124 auto row = make_entry(entrys[i], row_bufs[i], surface, cursor, x_min, x_max, row_h);
125 header.attach(surface.layer(), row.element_id);
126 rows.push_back(std::move(row));
127 }
128
129 header.cursor_out = cursor;
130
131 return EntryGroup {
132 .header = std::move(header),
133 .rows = std::move(rows),
134 };
135}
136
138 std::span<const EntrySpec> entrys,
139 std::string_view header_label,
140 FormaTarget header_buf,
141 std::span<const EntryBuffer> row_bufs,
142 Surface& surface,
143 LayoutCursor& cursor,
144 float row_h,
145 bool initially_open)
146{
147 return make_entry_group(entrys, header_label, std::move(header_buf), row_bufs,
148 surface, cursor, cursor.x_min(), cursor.x_max(), row_h, initially_open);
149}
150
151} // namespace MayaFlux::Portal::Forma
uint32_t label
Definition Contours.cpp:16
uint32_t rows
uint32_t h
Definition InkPress.cpp:29
std::weak_ptr< Core::Window > window
Definition Picker.cpp:23
void on_resize(uint32_t id, ResizeFn fn)
Called on every window resize.
Definition Context.cpp:136
Where an element's geometry and texture are written.
Definition Target.hpp:22
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,...
Reactive Y-position accumulator for vertical primitive stacking.
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
Named owner of a (Window, Layer, Context) triple: the Forma canvas.
Definition Surface.hpp:121
GlyphAtlas * get_default_glyph_atlas() const
Return the default GlyphAtlas, or nullptr if set_default_font() has not been called successfully.
@ Runtime
General runtime operations (default fallback)
@ Portal
High-level user-facing API layer.
EntryGroup make_entry_group(std::span< const EntrySpec > entrys, std::string_view header_label, FormaTarget header_buf, std::span< const EntryBuffer > row_bufs, Surface &surface, LayoutCursor &cursor, float x_min, float x_max, float row_h, bool initially_open)
Construct a collapsible header followed by N entry rows under it.
Definition Entry.cpp:104
Entry make_entry(const EntrySpec &spec, EntryBuffer row_buf, Surface &surface, LayoutCursor &cursor, float x_min, float x_max, float row_h, glm::vec3 bg)
Construct one labeled entry row, advance the cursor, and return it.
Definition Entry.cpp:32
glm::uvec2 row_pixel_dims(const std::shared_ptr< Core::Window > &window, float x_min, float x_max, float row_h)
Convert an NDC row rect into integer pixel dimensions.
Definition Entry.cpp:12
Axis-aligned bounding rectangle in a 2D coordinate space.
Definition Bounds.hpp:63
MAYAFLUX_API Collapsible & place(FormaTarget buf, Surface &surface, LayoutCursor &cursor, float x_min, float x_max, float row_h)
Register the header element and wire the toggle callback.
Collapsible & closed_color(glm::vec3 c)
Collapsible & open_color(glm::vec3 c)
Collapsible & label(std::string text)
Draw a text label over the header, background included.
Collapsible & initially_open(bool v)
A collapsible header strip.
FormaTarget buffer
Where this region's rendered output is written: a buffer of its own, or a slice of one it shares.
Definition Element.hpp:82
A bounded, renderable region on a window surface.
Definition Element.hpp:61
A pre-created text-capable buffer, passed to make_entry.
Definition Entry.hpp:19
Header collapsible with N entry rows related to it.
Definition Entry.hpp:58
std::function< std::string()> reader
Definition Entry.hpp:31
A single entry to display in a EntryGroup body row.
Definition Entry.hpp:29
One entry row in a EntryGroup body.
Definition Entry.hpp:40
glm::vec4 color
RGBA color applied to all glyphs not covered by a span in spans.
Definition InkPress.hpp:70
Construction parameters for press().
Definition InkPress.hpp:65