MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Entry.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "Collapsible.hpp"
5
6namespace MayaFlux::Core {
7class Window;
8}
9
10namespace MayaFlux::Buffers {
11class FormaBuffer;
12}
13
15
16/**
17 * @brief A pre-created text-capable buffer, passed to make_entry.
18 */
22
23/**
24 * @brief A single entry to display in a EntryGroup body row.
25 *
26 * @c reader is invoked once per graphics tick to produce the current
27 * stringified entry. The row text becomes "label: <reader()>".
28 */
29struct EntrySpec {
30 std::string label;
31 std::function<std::string()> reader;
32};
33
34/**
35 * @brief One entry row in a EntryGroup body.
36 *
37 * Owns the target the row draws into and the Link that redraws the text
38 * each tick.
39 */
40struct Entry {
41 uint32_t element_id {};
44
45 /// @brief NDC region occupied by this row. Valid after make_entry.
47
48 /// @brief Row region, satisfying Kinesis::HasBounds.
49 [[nodiscard]] Kinesis::AABB2D bounds() const noexcept { return row_bounds; }
50};
51
52/**
53 * @brief Header collapsible with N entry rows related to it.
54 *
55 * Rows are added as elements to the layer and related to the header,
56 * so the existing visibility cascade hides them on collapse.
57 */
58struct EntryGroup {
60 std::vector<Entry> rows;
61
62 /**
63 * @brief Union of the header strip and every row region.
64 *
65 * Collapses to the header region alone when the group has no rows.
66 */
67 [[nodiscard]] Kinesis::AABB2D bounds() const noexcept
68 {
70 for (const auto& r : rows) {
71 const auto rb = r.bounds();
72 b.min = glm::min(b.min, rb.min);
73 b.max = glm::max(b.max, rb.max);
74 }
75 return b;
76 }
77};
78
79/**
80 * @brief Convert an NDC row rect into integer pixel dimensions.
81 *
82 * Clamps width to at least 1 pixel and height to at least the default
83 * atlas pixel size to avoid degenerate layouts.
84 *
85 * @param window Target window for pixel dimension calculation.
86 * @param x_min Left edge in NDC.
87 * @param x_max Right edge in NDC.
88 * @param row_h Row height in NDC units.
89 */
90[[nodiscard]] MAYAFLUX_API glm::uvec2 row_pixel_dims(
91 const std::shared_ptr<Core::Window>& window,
92 float x_min, float x_max, float row_h);
93
94/**
95 * @brief Construct one labeled entry row, advance the cursor, and return it.
96 *
97 * The row is one slice of glyph quads: @p bg is drawn as the fill beneath
98 * the text (Portal::Text::PressParams::background), so one slice carries
99 * both. The link's compose function runs immediately (establish) so the row
100 * shows correctly from the first frame, and again on every subsequent
101 * link.tap(), drawing "label: entry" into the row's buffer. The buffer is
102 * pre-created by the caller as @p row_buf.
103 *
104 * Bounds come from cursor.advance()'s return (scroll-offset aware, per
105 * LayoutCursor::bind_scroll), with x_min/x_max substituted in afterward for
106 * this call's own column override - not from cursor.y() read directly, so
107 * a row placed through a scroll-bound cursor lands at the correct position
108 * immediately.
109 *
110 * @param spec Label and reader for the row.
111 * @param row_buf Pre-created text-capable buffer.
112 * @param surface Surface to register the row on.
113 * @param cursor Layout cursor. Advanced by @p row_h on return.
114 * @param x_min Left edge in NDC.
115 * @param x_max Right edge in NDC.
116 * @param row_h Row height in NDC units.
117 * @param bg Background fill drawn beneath the row's text.
118 */
119[[nodiscard]] MAYAFLUX_API Entry make_entry(
120 const EntrySpec& spec,
121 EntryBuffer row_buf,
122 Surface& surface,
123 LayoutCursor& cursor,
124 float x_min, float x_max, float row_h,
125 glm::vec3 bg = glm::vec3(0.15F));
126
127/**
128 * @brief make_entry using the cursor's column extents.
129 *
130 * Equivalent to the explicit-extent overload with x_min and x_max taken
131 * from @p cursor.
132 */
133[[nodiscard]] MAYAFLUX_API Entry make_entry(
134 const EntrySpec& spec,
135 EntryBuffer row_buf,
136 Surface& surface,
137 LayoutCursor& cursor,
138 float row_h,
139 glm::vec3 bg = glm::vec3(0.15F));
140
141/**
142 * @brief Construct a collapsible header followed by N entry rows under it.
143 *
144 * The header draws @p header_label itself (Collapsible::label),
145 * background included, so header_buf needs only a "text" additional_textures
146 * slot. Once expanded, all
147 * rows in @p entrys become visible via the relation cascade. Visibility
148 * tracks the header's open state.
149 *
150 * @param entrys Specs for each body row. Order is preserved top-to-bottom.
151 * @param header_label Text drawn into the header strip.
152 * @param header_buf Pre-created buffer for the header strip, "text" slot empty.
153 * @param row_bufs Pre-created text-capable buffers, one per entry in @p entrys.
154 * @param surface Surface to register the header and rows on.
155 * @param cursor Layout cursor. Advanced across header and all rows on return.
156 * @param x_min Left edge in NDC.
157 * @param x_max Right edge in NDC.
158 * @param row_h Row height in NDC units.
159 * @param initially_open Default false so deep trees stay collapsed at construction.
160 */
161[[nodiscard]] MAYAFLUX_API EntryGroup make_entry_group(
162 std::span<const EntrySpec> entrys,
163 std::string_view header_label,
164 FormaTarget header_buf,
165 std::span<const EntryBuffer> row_bufs,
166 Surface& surface,
167 LayoutCursor& cursor,
168 float x_min, float x_max, float row_h,
169 bool initially_open = false);
170
171/**
172 * @brief make_entry_group using the cursor's column extents.
173 *
174 * Equivalent to the explicit-extent overload with x_min and x_max taken
175 * from @p cursor.
176 */
177[[nodiscard]] MAYAFLUX_API EntryGroup make_entry_group(
178 std::span<const EntrySpec> entrys,
179 std::string_view header_label,
180 FormaTarget header_buf,
181 std::span<const EntryBuffer> row_bufs,
182 Surface& surface,
183 LayoutCursor& cursor,
184 float row_h,
185 bool initially_open = false);
186
187} // namespace MayaFlux::Portal::Forma
std::weak_ptr< Core::Window > window
Definition Picker.cpp:23
size_t b
Where an element's geometry and texture are written.
Definition Target.hpp:22
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
Kinesis::AABB2D bounds() const noexcept
Header strip region, satisfying Kinesis::HasBounds.
A collapsible header strip.
A pre-created text-capable buffer, passed to make_entry.
Definition Entry.hpp:19
std::vector< Entry > rows
Definition Entry.hpp:60
Kinesis::AABB2D bounds() const noexcept
Union of the header strip and every row region.
Definition Entry.hpp:67
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
Kinesis::AABB2D row_bounds
NDC region occupied by this row. Valid after make_entry.
Definition Entry.hpp:46
Kinesis::AABB2D bounds() const noexcept
Row region, satisfying Kinesis::HasBounds.
Definition Entry.hpp:49
One entry row in a EntryGroup body.
Definition Entry.hpp:40