MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Collapsible.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "LayoutCursor.hpp"
4
5namespace MayaFlux::Core {
6class Window;
7class VKImage;
8}
9
10namespace MayaFlux::Buffers {
11class FormaBuffer;
12}
13
15
16class Layer;
17class Context;
18class Surface;
19
20/**
21 * @struct Collapsible
22 * @brief A collapsible header strip.
23 *
24 * Before place() is called, the struct carries only configuration.
25 * After place(), header_id, open, buf, and cursor_out are populated.
26 * This mirrors the Element pattern: configure with setters, register
27 * with a single explicit call.
28 *
29 * @code
30 * auto col = Collapsible{}
31 * .initially_open(false)
32 * .closed_color({ 0.2F, 0.2F, 0.2F })
33 * .label(header_img)
34 * .place(window, layer, ctx, cursor, x_min, x_max, row_h);
35 *
36 * col.attach(layer, body_id);
37 * @endcode
38 */
40 // =========================================================================
41 // Results - populated by place()
42 // =========================================================================
43
44 /// @brief Element id of the header strip. Valid after place().
45 uint32_t header_id {};
46
47 /// @brief Open/closed state. Valid after place(). Write to toggle.
48 std::shared_ptr<MappedState<bool>> open;
49
50 /// @brief FormaBuffer backing the header geometry. Valid after place().
51 std::shared_ptr<Buffers::FormaBuffer> buf;
52
53 /// @brief Cursor positioned below the header, ready for body elements. Valid after place().
55
56 /// @brief NDC region occupied by the header strip. Valid after place().
58
59 /// @brief Header strip region, satisfying Kinesis::HasBounds.
60 [[nodiscard]] Kinesis::AABB2D bounds() const noexcept { return header_bounds; }
61
62 // =========================================================================
63 // Configuration - set before place()
64 // =========================================================================
65
66 /// @brief Starting toggle state. Default: true (open).
67 bool m_initially_open { true };
68
69 /// @brief Background color when closed. Default: glm::vec3(0.25F).
70 glm::vec3 m_color_closed { 0.25F };
71
72 /// @brief Background color when open. Default: glm::vec3(0.35F).
73 glm::vec3 m_color_open { 0.35F };
74
75 /// @brief Optional GPU image overlaid as a text label. nullptr = color only.
76 std::shared_ptr<Core::VKImage> m_label;
77
78 // =========================================================================
79 // Configuration setters
80 // =========================================================================
81
83 {
85 return *this;
86 }
87
89 {
91 return *this;
92 }
93
94 Collapsible& open_color(glm::vec3 c)
95 {
96 m_color_open = c;
97 return *this;
98 }
99
100 /**
101 * @brief Attach a GPU image overlaid on the header as a text label.
102 *
103 * When set, the FormaBuffer is created with a "text" texture binding
104 * and the geometry emits 12 vertices (background + overlay quad).
105 * When null (default), a plain color-only buffer is used with 6 vertices.
106 */
107 Collapsible& label(std::shared_ptr<Core::VKImage> img)
108 {
109 m_label = std::move(img);
110 return *this;
111 }
112
113 // =========================================================================
114 // Placement
115 // =========================================================================
116
117 /**
118 * @brief Register the header element and wire the toggle callback.
119 *
120 * Advances @p cursor by @p row_h. Populates header_id, open, buf,
121 * and cursor_out on this struct.
122 *
123 * @param buf Pre-created FormaBuffer sized for this header.
124 * @param surface Surface to register the header on.
125 * @param cursor Layout cursor. Advanced by row_h on return.
126 * @param x_min Left edge in NDC.
127 * @param x_max Right edge in NDC.
128 * @param row_h Header strip height in NDC units.
129 * @return *this, with results populated.
130 */
131 MAYAFLUX_API Collapsible& place(
132 std::shared_ptr<Buffers::FormaBuffer> buf,
133 Surface& surface,
134 LayoutCursor& cursor,
135 float x_min, float x_max, float row_h);
136
137 /**
138 * @brief Register the header element using the cursor's column extents.
139 *
140 * Equivalent to the explicit-extent overload with x_min and x_max taken
141 * from @p cursor. Use with a column-scoped LayoutCursor so the header
142 * spans exactly the column the cursor advances within.
143 *
144 * @param buf Pre-created FormaBuffer sized for this header.
145 * @param surface Surface to register the header on.
146 * @param cursor Layout cursor. Supplies column extents and is advanced
147 * by @p row_h on return.
148 * @param row_h Header strip height in NDC units.
149 * @return *this, with results populated.
150 */
151 MAYAFLUX_API Collapsible& place(
152 std::shared_ptr<Buffers::FormaBuffer> buf,
153 Surface& surface,
154 LayoutCursor& cursor,
155 float row_h);
156
157 // =========================================================================
158 // Post-placement helpers
159 // =========================================================================
160
161 /**
162 * @brief Relate a body element to this collapsible and sync its visibility
163 * to the current open state.
164 *
165 * @param layer Layer the body element lives on.
166 * @param body_id Element id returned from layer.add(...).
167 */
168 MAYAFLUX_API void attach(Layer& layer, uint32_t body_id) const;
169};
170
171// =============================================================================
172// Free function escape hatch
173// =============================================================================
174
175/**
176 * @brief Construct a collapsible header strip.
177 *
178 * Thin wrapper delegating to Collapsible::place(). Preserved as an escape
179 * hatch; existing callsites require no changes. The @p bridge parameter is
180 * accepted but ignored - Forma::bridge() is called internally.
181 */
182[[nodiscard]] MAYAFLUX_API Collapsible make_collapsible(
183 std::shared_ptr<Buffers::FormaBuffer> buf,
184 Surface& surface,
185 LayoutCursor& cursor,
186 float x_min,
187 float x_max,
188 float row_h,
189 bool initially_open = true,
190 glm::vec3 color_closed = glm::vec3(0.25F),
191 glm::vec3 color_open = glm::vec3(0.35F),
192 std::shared_ptr<Core::VKImage> label = nullptr);
193
194} // namespace MayaFlux::Portal::Forma
Flat registry of Elements on a surface.
Definition Layer.hpp:21
Reactive Y-position accumulator for vertical primitive stacking.
Named owner of a (Window, Layer, Context) triple - the Forma canvas.
Definition Surface.hpp:58
Context
Execution contexts for log messages.
Collapsible make_collapsible(std::shared_ptr< Buffers::FormaBuffer > buf, Surface &surface, LayoutCursor &cursor, float x_min, float x_max, float row_h, bool initially_open, glm::vec3 color_closed, glm::vec3 color_open)
Axis-aligned bounding rectangle in a 2D coordinate space.
Definition Bounds.hpp:21
Kinesis::AABB2D header_bounds
NDC region occupied by the header strip. Valid after place().
std::shared_ptr< MappedState< bool > > open
Open/closed state. Valid after place(). Write to toggle.
std::shared_ptr< Buffers::FormaBuffer > buf
FormaBuffer backing the header geometry. Valid after place().
uint32_t header_id
Element id of the header strip. Valid after place().
Collapsible & closed_color(glm::vec3 c)
glm::vec3 m_color_closed
Background color when closed. Default: glm::vec3(0.25F).
std::shared_ptr< Core::VKImage > m_label
Optional GPU image overlaid as a text label. nullptr = color only.
Collapsible & open_color(glm::vec3 c)
Collapsible & label(std::shared_ptr< Core::VKImage > img)
Attach a GPU image overlaid on the header as a text label.
MAYAFLUX_API Collapsible & place(std::shared_ptr< Buffers::FormaBuffer > buf, Surface &surface, LayoutCursor &cursor, float x_min, float x_max, float row_h)
Register the header element and wire the toggle callback.
Collapsible & initially_open(bool v)
glm::vec3 m_color_open
Background color when open. Default: glm::vec3(0.35F).
MAYAFLUX_API void attach(Layer &layer, uint32_t body_id) const
Relate a body element to this collapsible and sync its visibility to the current open state.
bool m_initially_open
Starting toggle state. Default: true (open).
Kinesis::AABB2D bounds() const noexcept
Header strip region, satisfying Kinesis::HasBounds.
LayoutCursor cursor_out
Cursor positioned below the header, ready for body elements. Valid after place().
A collapsible header strip.