29static const char*
const s_tag =
"ra8_box";
57 r.
w = outer.
w - (2 * pad);
58 r.
h = outer.
h - (2 * pad);
143 if (child->
fixed > 0) {
144 fixed += (int32_t)child->
fixed;
146 flex += (uint32_t)child->
flex;
183 const int32_t gap = (int32_t)p->
gap;
190 const int32_t main_extent = horizontal ? cont.
w : cont.
h;
191 const int32_t gaps = (n > 0U) ? ((int32_t)(n - 1U) * gap) : 0;
192 int32_t flex_space = main_extent - fixed - gaps;
193 if (flex_space < 0) {
197 int32_t cursor = horizontal ? cont.
x : cont.
y;
202 if (child->
fixed > 0) {
203 main_sz = (int32_t)child->
fixed;
204 }
else if (flex > 0U) {
205 main_sz = (flex_space * (int32_t)child->
flex) / (int32_t)flex;
210 child->
rect.
x = cursor;
212 child->
rect.
w = main_sz;
216 child->
rect.
y = cursor;
218 child->
rect.
h = main_sz;
220 cursor += main_sz + gap;
250 const int32_t gap = (int32_t)p->
gap;
258 const int32_t rows = ((int32_t)n + cols - 1) / cols;
259 const int32_t row_cnt = (rows > 0) ? rows : 1;
260 int32_t cell_w = (cont.
w - ((cols - 1) * gap)) / cols;
264 int32_t cell_h = (cont.
h - ((row_cnt - 1) * gap)) / row_cnt;
273 const int32_t col = idx % cols;
274 const int32_t row = idx / cols;
275 child->
rect.
x = cont.
x + (col * (cell_w + gap));
276 child->
rect.
y = cont.
y + (row * (cell_h + gap));
277 child->
rect.
w = cell_w;
291 tree->
nodes = storage;
299 if ((tree ==
nullptr) || (node ==
nullptr)) {
305 if ((parent != (int16_t)
k_ra8_box_none) && ((parent < 0) || (parent >= (int16_t)tree->
count))) {
309 const int16_t idx = (int16_t)tree->
count;
310 tree->
nodes[idx] = *node;
335 if ((tree->
count == 0U) || (root < 0) || (root >= (int16_t)tree->
count)) {
340 for (uint16_t i = 0U; i < tree->
count; ++i) {
static const char * s_tag
Logging / check tag.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
ra8_err_t ra8_box_tree_init(ra8_box_tree_t *tree, ra8_box_t *storage, uint16_t cap)
Bind a tree builder to caller-owned node storage.
static void internal_tally(const ra8_box_tree_t *tree, int16_t parent, uint16_t *out_count, int32_t *out_fixed, uint32_t *out_flex)
Sum child count, fixed extent, and flex weight of a container.
static ra8_ui_rect_t internal_inset(ra8_ui_rect_t outer, int32_t pad)
Inset a rectangle by a uniform padding, clamping size to >= 0.
ra8_err_t ra8_box_layout(ra8_box_tree_t *tree, int16_t root, const ra8_ui_rect_t *frame)
Lay out the tree, filling every node's rect.
int16_t ra8_box_add(ra8_box_tree_t *tree, int16_t parent, const ra8_box_t *node)
Append a node and link it as a child of parent.
static void internal_layout_grid(ra8_box_tree_t *tree, int16_t parent)
Lay out a grid container's children row-major.
static void internal_layout_stack(ra8_box_tree_t *tree, int16_t parent, bool horizontal)
Lay out a stack container's children along one axis.
static bool internal_iter_live(int32_t link, uint16_t guard, uint16_t count)
Child-walk loop guard: link is live and the bound is not hit.
Bounded, allocation-free box-model layout for e-reader chrome.
@ k_ra8_box_none
No child / no sibling link.
ra8_box_kind_t
Box layout kind.
@ k_ra8_box_stack_v
Vertical stack: children stack top->bottom.
@ k_ra8_box_grid
Fixed-column grid, row-major.
@ k_ra8_box_leaf
Terminal box (no children laid out).
@ k_ra8_box_stack_h
Horizontal stack: children left->right.
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Error Code Definitions for ra8-firmware.
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Bounded UI interaction core: hit-testing, screen stack, paging.
One node in a box tree (caller-owned).
uint8_t grid_cols
Columns for k_ra8_box_grid (>= 1).
uint8_t kind
ra8_box_kind_t.
uint16_t flex
Flex weight when not fixed.
int32_t first_child
First child index, or k_ra8_box_none.
int16_t fixed
Fixed main-axis extent; 0 => use flex.
int16_t gap
Gap between children.
int32_t next
Next sibling index, or k_ra8_box_none.
int16_t pad
Inner padding (all four sides).
ra8_ui_rect_t rect
OUTPUT: computed rectangle.
Append-only builder over caller-owned node storage.
uint16_t cap
Capacity of nodes.
ra8_box_t * nodes
Caller storage.
uint16_t count
Nodes used.
Axis-aligned rectangle in framebuffer pixel coordinates.
int32_t w
Width (pixels, >= 0).
int32_t h
Height (pixels, >= 0).
int32_t x
Left edge (pixels).
int32_t y
Top edge (pixels).