MayaFlux 0.5.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 /**
28 * @brief Construct a cursor at @p y_start scoped to a horizontal column.
29 *
30 * Bounds returned by advance() span [@p x_min, @p x_max] rather than the
31 * full NDC width. The default extents reproduce the previous behaviour,
32 * so existing call sites are unaffected.
33 *
34 * @param y_start Starting NDC Y baseline.
35 * @param x_min Left edge of the column in NDC.
36 * @param x_max Right edge of the column in NDC.
37 */
38 explicit LayoutCursor(float y_start, float x_min = -1.F, float x_max = 1.F)
39 : m_x_min(x_min)
40 , m_x_max(x_max)
41 {
42 m_state = std::make_shared<MappedState<float>>();
43 m_state->write(y_start);
44 }
45
46 /**
47 * @brief Shared baseline state. Close over this in GeometryFn to reflow
48 * when any preceding primitive changes height.
49 */
50 [[nodiscard]] std::shared_ptr<MappedState<float>> state() const { return m_state; }
51
52 [[nodiscard]] float y() const { return m_state->value; }
53
54 [[nodiscard]] float x_min() const noexcept { return m_x_min; }
55 [[nodiscard]] float x_max() const noexcept { return m_x_max; }
56
57 /**
58 * @brief Reset both cursors to the lower of their two current Y values.
59 *
60 * Used after a row spanning several columns so that independent column
61 * cursors resume from a common baseline.
62 *
63 * @note LayoutCursor copies share one MappedState. Calling sync_to on two
64 * cursors copied from one another is a no-op, since both already
65 * reference the same baseline.
66 */
67 void sync_to(LayoutCursor& other)
68 {
69 const float y = std::min(m_state->value, other.m_state->value);
70 m_state->write(y);
71 other.m_state->write(y);
72 }
73
74 /**
75 * @brief Advance the cursor downward by @p height and return the NDC
76 * AABB occupied by the primitive just placed, scoped to the
77 * cursor's column extents.
78 */
80 {
81 const float top = m_state->value;
82 const float bot = top - height;
83 m_state->write(bot);
84 return Kinesis::AABB2D { .min = { m_x_min, bot }, .max = { m_x_max, top } };
85 }
86
87 /**
88 * @brief Advance without returning bounds. Use for padding between primitives.
89 */
90 void skip(float height) { m_state->write(m_state->value - height); }
91
92 /**
93 * @brief Reset to @p y_start. Existing closures over state() will reflow
94 * on their next sync() tick.
95 */
96 void reset(float y_start = 1.F) { m_state->write(y_start); }
97
98private:
99 std::shared_ptr<MappedState<float>> m_state;
100 float m_x_min { -1.F };
101 float m_x_max { 1.F };
102};
103
104} // namespace MayaFlux::Portal::Forma
uint32_t height
std::shared_ptr< MappedState< float > > state() const
Shared baseline state.
void sync_to(LayoutCursor &other)
Reset both cursors to the lower of their two current Y values.
void reset(float y_start=1.F)
Reset to y_start.
LayoutCursor(float y_start, float x_min=-1.F, float x_max=1.F)
Construct a cursor at y_start scoped to a horizontal column.
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