MayaFlux 0.4.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 // =========================================================================
57 // Configuration - set before place()
58 // =========================================================================
59
60 /// @brief Starting toggle state. Default: true (open).
61 bool m_initially_open { true };
62
63 /// @brief Background color when closed. Default: glm::vec3(0.25F).
64 glm::vec3 m_color_closed { 0.25F };
65
66 /// @brief Background color when open. Default: glm::vec3(0.35F).
67 glm::vec3 m_color_open { 0.35F };
68
69 /// @brief Optional GPU image overlaid as a text label. nullptr = color only.
70 std::shared_ptr<Core::VKImage> m_label;
71
72 // =========================================================================
73 // Configuration setters
74 // =========================================================================
75
77 {
79 return *this;
80 }
81
83 {
85 return *this;
86 }
87
88 Collapsible& open_color(glm::vec3 c)
89 {
90 m_color_open = c;
91 return *this;
92 }
93
94 /**
95 * @brief Attach a GPU image overlaid on the header as a text label.
96 *
97 * When set, the FormaBuffer is created with a "text" texture binding
98 * and the geometry emits 12 vertices (background + overlay quad).
99 * When null (default), a plain color-only buffer is used with 6 vertices.
100 */
101 Collapsible& label(std::shared_ptr<Core::VKImage> img)
102 {
103 m_label = std::move(img);
104 return *this;
105 }
106
107 // =========================================================================
108 // Placement
109 // =========================================================================
110
111 /**
112 * @brief Register the header element and wire the toggle callback.
113 *
114 * Advances @p cursor by @p row_h. Populates header_id, open, buf,
115 * and cursor_out on this struct.
116 *
117 * @param buf Pre-created FormaBuffer sized for this header.
118 * @param surface Surface to register the header on.
119 * @param cursor Layout cursor. Advanced by row_h on return.
120 * @param x_min Left edge in NDC.
121 * @param x_max Right edge in NDC.
122 * @param row_h Header strip height in NDC units.
123 * @return *this, with results populated.
124 */
125 MAYAFLUX_API Collapsible& place(
126 std::shared_ptr<Buffers::FormaBuffer> buf,
127 Surface& surface,
128 LayoutCursor& cursor,
129 float x_min, float x_max, float row_h);
130
131 // =========================================================================
132 // Post-placement helpers
133 // =========================================================================
134
135 /**
136 * @brief Relate a body element to this collapsible and sync its visibility
137 * to the current open state.
138 *
139 * @param layer Layer the body element lives on.
140 * @param body_id Element id returned from layer.add(...).
141 */
142 MAYAFLUX_API void attach(Layer& layer, uint32_t body_id) const;
143};
144
145// =============================================================================
146// Free function escape hatch
147// =============================================================================
148
149/**
150 * @brief Construct a collapsible header strip.
151 *
152 * Thin wrapper delegating to Collapsible::place(). Preserved as an escape
153 * hatch; existing callsites require no changes. The @p bridge parameter is
154 * accepted but ignored - Forma::bridge() is called internally.
155 */
156[[nodiscard]] MAYAFLUX_API Collapsible make_collapsible(
157 std::shared_ptr<Buffers::FormaBuffer> buf,
158 Surface& surface,
159 LayoutCursor& cursor,
160 float x_min,
161 float x_max,
162 float row_h,
163 bool initially_open = true,
164 glm::vec3 color_closed = glm::vec3(0.25F),
165 glm::vec3 color_open = glm::vec3(0.35F),
166 std::shared_ptr<Core::VKImage> label = nullptr);
167
168} // 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)
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).
LayoutCursor cursor_out
Cursor positioned below the header, ready for body elements. Valid after place().
A collapsible header strip.