MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
QueryUtils.hpp
Go to the documentation of this file.
1#pragma once
2
5
6namespace MayaFlux::Core {
7class Window;
8class VKImage;
9}
10
11namespace MayaFlux::Buffers {
12class FormaBuffer;
13}
14
16
17/**
18 * @brief A pre-created buffer and its bound text image, passed to make_value_row.
19 */
20struct RowBuffer {
21 std::shared_ptr<Buffers::FormaBuffer> buf;
22 std::shared_ptr<Core::VKImage> text_image;
23};
24
25constexpr float k_inspect_indent = 0.03F;
26
27/**
28 * @brief A single value to display in a ValueGroup body row.
29 *
30 * @c reader is invoked once per graphics tick to produce the current
31 * stringified value. The row text becomes "label: <reader()>".
32 */
33struct ValueSpec {
34 std::string label;
35 std::function<std::string()> reader;
36};
37
38/**
39 * @brief One value row in a ValueGroup body.
40 *
41 * Owns the FormaBuffer for the row background, the VKImage holding the
42 * composited text, and the Link that repress's the text each tick.
43 */
44struct ValueRow {
45 uint32_t element_id {};
46 std::shared_ptr<Buffers::FormaBuffer> buf;
47 std::shared_ptr<Core::VKImage> text;
49
50 /// @brief NDC region occupied by this row. Valid after make_value_row.
52
53 /// @brief Row region, satisfying Kinesis::HasBounds.
54 [[nodiscard]] Kinesis::AABB2D bounds() const noexcept { return row_bounds; }
55};
56
57/**
58 * @brief Header collapsible with N value rows related to it.
59 *
60 * Rows are added as elements to the layer and related to the header,
61 * so the existing visibility cascade hides them on collapse.
62 */
63struct ValueGroup {
65 std::vector<ValueRow> rows;
66
67 /**
68 * @brief Union of the header strip and every row region.
69 *
70 * Collapses to the header region alone when the group has no rows.
71 */
72 [[nodiscard]] Kinesis::AABB2D bounds() const noexcept
73 {
75 for (const auto& r : rows) {
76 const auto rb = r.bounds();
77 b.min = glm::min(b.min, rb.min);
78 b.max = glm::max(b.max, rb.max);
79 }
80 return b;
81 }
82};
83
84/**
85 * @brief Convert an NDC row rect into integer pixel dimensions.
86 *
87 * Clamps width to at least 1 pixel and height to at least the default
88 * atlas pixel size to avoid degenerate textures.
89 *
90 * @param window Target window for pixel dimension calculation.
91 * @param x_min Left edge in NDC.
92 * @param x_max Right edge in NDC.
93 * @param row_h Row height in NDC units.
94 */
95[[nodiscard]] MAYAFLUX_API glm::uvec2 row_pixel_dims(
96 const std::shared_ptr<Core::Window>& window,
97 float x_min, float x_max, float row_h);
98
99/**
100 * @brief Construct one labeled value row, advance the cursor, and return it.
101 *
102 * The returned row's link reads @p spec.reader each tick, represses
103 * "label: value" into the text image, and binds the image to the row's
104 * FormaBuffer. The buffer and text image are pre-created by the caller
105 * and travel together as @p row_buf.
106 *
107 * @param spec Label and reader for the row.
108 * @param row_buf Pre-created buffer and bound text image.
109 * @param surface Surface to register the row on.
110 * @param cursor Layout cursor. Advanced by @p row_h on return.
111 * @param x_min Left edge in NDC.
112 * @param x_max Right edge in NDC.
113 * @param row_h Row height in NDC units.
114 * @param bg Background color for the row quad.
115 */
116[[nodiscard]] ValueRow make_value_row(
117 const ValueSpec& spec,
118 RowBuffer row_buf,
119 Surface& surface,
120 LayoutCursor& cursor,
121 float x_min, float x_max, float row_h,
122 glm::vec3 bg = glm::vec3(0.15F));
123
124/**
125 * @brief make_value_row using the cursor's column extents.
126 *
127 * Equivalent to the explicit-extent overload with x_min and x_max taken
128 * from @p cursor.
129 */
130[[nodiscard]] ValueRow make_value_row(
131 const ValueSpec& spec,
132 RowBuffer row_buf,
133 Surface& surface,
134 LayoutCursor& cursor,
135 float row_h,
136 glm::vec3 bg = glm::vec3(0.15F));
137
138/**
139 * @brief Construct a collapsible header followed by N value rows under it.
140 *
141 * The header and all row buffers are pre-created by the caller. Once
142 * expanded, all rows in @p values become visible via the relation cascade.
143 * Visibility tracks the header's open state.
144 *
145 * @param values Specs for each body row. Order is preserved top-to-bottom.
146 * @param header_buf Pre-created buffer and text image for the header strip.
147 * @param row_bufs Pre-created buffers and text images, one per entry in @p values.
148 * @param surface Surface to register the header and rows on.
149 * @param cursor Layout cursor. Advanced across header and all rows on return.
150 * @param x_min Left edge in NDC.
151 * @param x_max Right edge in NDC.
152 * @param row_h Row height in NDC units.
153 * @param initially_open Default false so deep trees stay collapsed at construction.
154 */
155[[nodiscard]] ValueGroup make_value_group(
156 std::span<const ValueSpec> values,
157 RowBuffer header_buf,
158 std::span<const RowBuffer> row_bufs,
159 Surface& surface,
160 LayoutCursor& cursor,
161 float x_min, float x_max, float row_h,
162 bool initially_open = false);
163
164/**
165 * @brief make_value_group using the cursor's column extents.
166 *
167 * Equivalent to the explicit-extent overload with x_min and x_max taken
168 * from @p cursor.
169 */
170[[nodiscard]] ValueGroup make_value_group(
171 std::span<const ValueSpec> values,
172 RowBuffer header_buf,
173 std::span<const RowBuffer> row_bufs,
174 Surface& surface,
175 LayoutCursor& cursor,
176 float row_h,
177 bool initially_open = false);
178
179} // namespace MayaFlux::Portal::Forma
size_t b
ValueGroup make_value_group(std::span< const ValueSpec > values, RowBuffer header_buf, std::span< const RowBuffer > 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 value rows under it.
constexpr float k_inspect_indent
ValueRow make_value_row(const ValueSpec &spec, RowBuffer row_buf, Surface &surface, LayoutCursor &cursor, float x_min, float x_max, float row_h, glm::vec3 bg)
Construct one labeled value row, advance the cursor, and return it.
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.
Axis-aligned bounding rectangle in a 2D coordinate space.
Definition Bounds.hpp:21
Kinesis::AABB2D bounds() const noexcept
Header strip region, satisfying Kinesis::HasBounds.
A collapsible header strip.
std::shared_ptr< Buffers::FormaBuffer > buf
std::shared_ptr< Core::VKImage > text_image
A pre-created buffer and its bound text image, passed to make_value_row.
std::vector< ValueRow > rows
Kinesis::AABB2D bounds() const noexcept
Union of the header strip and every row region.
Header collapsible with N value rows related to it.
Kinesis::AABB2D row_bounds
NDC region occupied by this row. Valid after make_value_row.
std::shared_ptr< Buffers::FormaBuffer > buf
std::shared_ptr< Core::VKImage > text
Kinesis::AABB2D bounds() const noexcept
Row region, satisfying Kinesis::HasBounds.
One value row in a ValueGroup body.
std::function< std::string()> reader
A single value to display in a ValueGroup body row.