MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ place()

Collapsible & MayaFlux::Portal::Forma::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.

Advances cursor by row_h. Populates header_id, open, buf, and cursor_out on this struct.

Parameters
bufPre-created FormaBuffer sized for this header.
surfaceSurface to register the header on.
cursorLayout cursor. Advanced by row_h on return.
x_minLeft edge in NDC.
x_maxRight edge in NDC.
row_hHeader strip height in NDC units.
Returns
*this, with results populated.

Definition at line 73 of file Collapsible.cpp.

78{
79 buf = std::move(in_buf);
80
81 const float y_top = cursor.y();
82 cursor.advance(row_h);
83
84 auto open_state = std::make_shared<MappedState<bool>>();
85 open_state->write(m_initially_open);
86
87 Mapped<bool> mapped;
88 mapped.state = open_state;
89 mapped.geometry_fn = collapsible_header_geom(
90 y_top, x_min, x_max, row_h, m_color_closed, m_color_open, m_label != nullptr);
91 mapped.element.buffer = buf;
92 mapped.element.bounds_hint = Kinesis::AABB2D {
93 .min = { x_min, cursor.y() },
94 .max = { x_max, y_top },
95 };
96
97 const uint32_t hid = surface.layer().add(mapped.element);
98 mapped.element.id = hid;
99 open_state->id = hid;
100 mapped.sync();
101
102 surface.ctx().on_press(hid, IO::MouseButtons::Left,
103 [m = std::move(mapped), open = open_state, surface, hid](uint32_t, glm::vec2) mutable {
104 const bool next = !open->value;
105 open->write(next);
106 for (auto rel_id : surface.layer().related_ids(hid))
107 surface.layer().set_visible(rel_id, next);
108 m.sync();
109 });
110
111 header_id = hid;
112 open = open_state;
113 cursor_out = cursor;
114 return *this;
115}
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().
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.
glm::vec3 m_color_open
Background color when open. Default: glm::vec3(0.35F).
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().

References MayaFlux::Portal::Forma::Layer::add(), MayaFlux::Portal::Forma::LayoutCursor::advance(), MayaFlux::Portal::Forma::Element::bounds_hint, buf, MayaFlux::Portal::Forma::Element::buffer, MayaFlux::Portal::Forma::Surface::ctx(), cursor_out, MayaFlux::Portal::Forma::Mapped< T >::element, MayaFlux::Portal::Forma::Mapped< T >::geometry_fn, header_id, MayaFlux::Portal::Forma::Element::id, MayaFlux::Portal::Forma::Surface::layer(), MayaFlux::IO::Left, m_color_closed, m_color_open, m_initially_open, m_label, MayaFlux::Kinesis::AABB2D::min, MayaFlux::Portal::Forma::Context::on_press(), open, MayaFlux::Portal::Forma::Layer::related_ids(), MayaFlux::Portal::Forma::Layer::set_visible(), MayaFlux::Portal::Forma::Mapped< T >::state, MayaFlux::Portal::Forma::Mapped< T >::sync(), and MayaFlux::Portal::Forma::LayoutCursor::y().

Referenced by MayaFlux::Portal::Forma::make_collapsible(), and MayaFlux::Portal::Forma::make_value_group().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: