MayaFlux 0.4.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
51/**
52 * @brief Header collapsible with N value rows related to it.
53 *
54 * Rows are added as elements to the layer and related to the header,
55 * so the existing visibility cascade hides them on collapse.
56 */
57struct ValueGroup {
59 std::vector<ValueRow> rows;
60};
61
62/**
63 * @brief Convert an NDC row rect into integer pixel dimensions.
64 *
65 * Clamps width to at least 1 pixel and height to at least the default
66 * atlas pixel size to avoid degenerate textures.
67 *
68 * @param window Target window for pixel dimension calculation.
69 * @param x_min Left edge in NDC.
70 * @param x_max Right edge in NDC.
71 * @param row_h Row height in NDC units.
72 */
73[[nodiscard]] MAYAFLUX_API glm::uvec2 row_pixel_dims(
74 const std::shared_ptr<Core::Window>& window,
75 float x_min, float x_max, float row_h);
76
77/**
78 * @brief Construct one labeled value row, advance the cursor, and return it.
79 *
80 * The returned row's link reads @p spec.reader each tick, represses
81 * "label: value" into the text image, and binds the image to the row's
82 * FormaBuffer. The buffer and text image are pre-created by the caller
83 * and travel together as @p row_buf.
84 *
85 * @param spec Label and reader for the row.
86 * @param row_buf Pre-created buffer and bound text image.
87 * @param surface Surface to register the row on.
88 * @param cursor Layout cursor. Advanced by @p row_h on return.
89 * @param x_min Left edge in NDC.
90 * @param x_max Right edge in NDC.
91 * @param row_h Row height in NDC units.
92 * @param bg Background color for the row quad.
93 */
94[[nodiscard]] ValueRow make_value_row(
95 const ValueSpec& spec,
96 RowBuffer row_buf,
97 Surface& surface,
98 LayoutCursor& cursor,
99 float x_min, float x_max, float row_h,
100 glm::vec3 bg = glm::vec3(0.15F));
101
102/**
103 * @brief Construct a collapsible header followed by N value rows under it.
104 *
105 * The header and all row buffers are pre-created by the caller. Once
106 * expanded, all rows in @p values become visible via the relation cascade.
107 * Visibility tracks the header's open state.
108 *
109 * @param values Specs for each body row. Order is preserved top-to-bottom.
110 * @param header_buf Pre-created buffer and text image for the header strip.
111 * @param row_bufs Pre-created buffers and text images, one per entry in @p values.
112 * @param surface Surface to register the header and rows on.
113 * @param cursor Layout cursor. Advanced across header and all rows 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 initially_open Default false so deep trees stay collapsed at construction.
118 */
119[[nodiscard]] ValueGroup make_value_group(
120 std::span<const ValueSpec> values,
121 RowBuffer header_buf,
122 std::span<const RowBuffer> row_bufs,
123 Surface& surface,
124 LayoutCursor& cursor,
125 float x_min, float x_max, float row_h,
126 bool initially_open = false);
127
128} // namespace MayaFlux::Portal::Forma
Reactive Y-position accumulator for vertical primitive stacking.
Named owner of a (Window, Layer, Context) triple - the Forma canvas.
Definition Surface.hpp:58
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.
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
Header collapsible with N value rows related to it.
std::shared_ptr< Buffers::FormaBuffer > buf
std::shared_ptr< Core::VKImage > text
One value row in a ValueGroup body.
std::function< std::string()> reader
A single value to display in a ValueGroup body row.