MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
LayoutCursor.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "Mapped.hpp"
4
6
7/**
8 * @brief Reactive Y-position accumulator for vertical primitive stacking.
9 *
10 * Holds a shared MappedState<float> carrying the current NDC Y baseline.
11 * Any primitive whose GeometryFn closes over the state pointer will reflow
12 * automatically when the cursor advances, via the normal version-bump path.
13 *
14 * NDC Y runs +1 (top) to -1 (bottom). advance() subtracts height.
15 *
16 * Default construction places the cursor at the top of the screen (y=1).
17 * This matches the most common starting position and allows LayoutCursor
18 * to be a plain member of structs that use aggregate or value initialization.
19 */
21public:
23 : LayoutCursor(1.F)
24 {
25 }
26
27 explicit LayoutCursor(float y_start)
28 {
29 m_state = std::make_shared<MappedState<float>>();
30 m_state->write(y_start);
31 }
32
33 /**
34 * @brief Shared baseline state. Close over this in GeometryFn to reflow
35 * when any preceding primitive changes height.
36 */
37 [[nodiscard]] std::shared_ptr<MappedState<float>> state() const { return m_state; }
38
39 [[nodiscard]] float y() const { return m_state->value; }
40
41 /**
42 * @brief Advance the cursor downward by @p height and return the NDC
43 * AABB occupied by the primitive just placed.
44 */
46 {
47 const float top = m_state->value;
48 const float bot = top - height;
49 m_state->write(bot);
50 return Kinesis::AABB2D { .min = { -1.F, bot }, .max = { 1.F, top } };
51 }
52
53 /**
54 * @brief Advance without returning bounds. Use for padding between primitives.
55 */
56 void skip(float height) { m_state->write(m_state->value - height); }
57
58 /**
59 * @brief Reset to @p y_start. Existing closures over state() will reflow
60 * on their next sync() tick.
61 */
62 void reset(float y_start = 1.F) { m_state->write(y_start); }
63
64private:
65 std::shared_ptr<MappedState<float>> m_state;
66};
67
68} // namespace MayaFlux::Portal::Forma
std::shared_ptr< MappedState< float > > state() const
Shared baseline state.
void reset(float y_start=1.F)
Reset to y_start.
Kinesis::AABB2D advance(float height)
Advance the cursor downward by height and return the NDC AABB occupied by the primitive just placed.
std::shared_ptr< MappedState< float > > m_state
void skip(float height)
Advance without returning bounds.
Reactive Y-position accumulator for vertical primitive stacking.
Axis-aligned bounding rectangle in a 2D coordinate space.
Definition Bounds.hpp:21