ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_widget.h
Go to the documentation of this file.
1
41
42#pragma once
43
44#ifdef __cplusplus
45extern "C" {
46#endif
47
48#include <stdint.h>
49
50#include "ra8_box.h"
51#include "ra8_err.h"
52#include "ra8_ui.h"
53
54/* ===========================================================================
55 * Events + refresh hints
56 * ===========================================================================
57 */
58
72
77typedef struct {
79 uint8_t reserved;
80 uint16_t button_id;
81 int32_t x;
82 int32_t y;
84
103
104/* ===========================================================================
105 * Widget + vtable
106 * ===========================================================================
107 */
108
109struct ra8_widget; /* fwd */
110
121typedef struct {
130 void (*measure)(struct ra8_widget* w,
131 int32_t avail_w,
132 int32_t avail_h,
133 int32_t* out_w,
134 int32_t* out_h);
139 void (*render)(struct ra8_widget* w);
146 bool (*on_input)(struct ra8_widget* w, const ra8_widget_event_t* ev);
148
159typedef struct ra8_widget {
161 void* ctx;
163 int16_t fixed;
164 uint16_t flex;
165 uint16_t action_id;
166 uint8_t refresh;
167 bool visible;
168 bool dirty;
170
179
180/* ===========================================================================
181 * Container operations (all pure except the render dispatch)
182 * ===========================================================================
183 */
184
216[[nodiscard]] ra8_err_t ra8_widget_layout_stack(ra8_widget_t* widgets,
217 uint16_t count,
218 const ra8_ui_rect_t* frame,
220 int16_t gap,
221 int16_t pad,
222 ra8_box_t* box_scratch,
223 uint16_t box_cap);
224
250[[nodiscard]] ra8_err_t ra8_widget_dispatch(ra8_widget_t* widgets,
251 uint16_t count,
252 const ra8_widget_event_t* ev,
253 bool* out_handled);
254
273
300[[nodiscard]] ra8_err_t ra8_widget_damage(const ra8_widget_t* widgets,
301 uint16_t count,
302 ra8_ui_rect_t* out_rect,
303 ra8_widget_refresh_t* out_hint,
304 uint16_t* out_count);
305
328[[nodiscard]] ra8_err_t ra8_widget_render_dirty(ra8_widget_t* widgets, uint16_t count);
329
330/* ===========================================================================
331 * Container panel: a composite widget that nests a child widget array
332 * ===========================================================================
333 */
334
378
406
436
478[[nodiscard]] ra8_err_t ra8_widget_panel_compose(ra8_widget_t* panel_w,
479 const ra8_ui_rect_t* frame,
480 ra8_ui_rect_t* out_damage,
481 ra8_widget_refresh_t* out_hint,
482 uint16_t* out_dirty);
483
484/* ===========================================================================
485 * Concrete leaf widgets: text label + push button (DI paint backend)
486 * ===========================================================================
487 */
488
521typedef struct ra8_widget_paint {
523 void* user;
525 void (*fill_rect)(void* user, int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color);
527 void (*draw_text)(void* user, int32_t x, int32_t y, const char* str, uint32_t fg, uint32_t bg);
529 void (*text_size)(void* user, const char* str, int32_t* out_w, int32_t* out_h);
531
545
562typedef struct ra8_widget_label {
564 const char* text;
565 uint32_t fg;
566 uint32_t bg;
567 int16_t pad;
569 uint8_t reserved;
571
591typedef struct ra8_widget_button {
593 const char* text;
594 void (*on_press)(struct ra8_widget* w);
595 uint32_t fg;
596 uint32_t face;
597 uint32_t face_pressed;
598 uint32_t border;
599 uint32_t presses;
600 int16_t pad;
601 int16_t border_w;
603 bool pressed;
604 uint8_t reserved;
606
629
656
679
707
708#ifdef __cplusplus
709}
710#endif
Bounded, allocation-free box-model layout for e-reader chrome.
Error Code Definitions for ra8-firmware.
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
Bounded UI interaction core: hit-testing, screen stack, paging.
const ra8_widget_vtable_t * ra8_widget_panel_vtable(void)
Return the shared vtable that every container panel uses.
ra8_widget_axis_t
Main axis a container stacks its children along.
Definition ra8_widget.h:175
@ k_ra8_widget_axis_row
Horizontal stack (left -> right).
Definition ra8_widget.h:177
@ k_ra8_widget_axis_col
Vertical stack (top -> bottom).
Definition ra8_widget.h:176
ra8_err_t ra8_widget_layout_stack(ra8_widget_t *widgets, uint16_t count, const ra8_ui_rect_t *frame, ra8_widget_axis_t axis, int16_t gap, int16_t pad, ra8_box_t *box_scratch, uint16_t box_cap)
Lay a stack of widgets out inside a frame (delegates to ra8_box).
Definition ra8_widget.c:215
ra8_err_t ra8_widget_damage(const ra8_widget_t *widgets, uint16_t count, ra8_ui_rect_t *out_rect, ra8_widget_refresh_t *out_hint, uint16_t *out_count)
Compute the minimal damage rectangle + refresh hint to flush.
Definition ra8_widget.c:299
ra8_err_t ra8_widget_panel_init(ra8_widget_t *w, ra8_widget_panel_t *panel)
Bind a widget instance to a container panel.
ra8_err_t ra8_widget_label_init(ra8_widget_t *w, ra8_widget_label_t *label)
Bind a widget instance to a text label.
ra8_err_t ra8_widget_panel_compose(ra8_widget_t *panel_w, const ra8_ui_rect_t *frame, ra8_ui_rect_t *out_damage, ra8_widget_refresh_t *out_hint, uint16_t *out_dirty)
Run one top-level compose cycle over a panel and report the flush.
const ra8_widget_vtable_t * ra8_widget_label_vtable(void)
Return the shared vtable backing every text-label widget.
ra8_err_t ra8_widget_invalidate(ra8_widget_t *w, ra8_widget_refresh_t refresh)
Mark a widget dirty with a refresh hint (folds upward in strength).
Definition ra8_widget.c:286
struct ra8_widget_paint ra8_widget_paint_t
struct ra8_widget ra8_widget_t
ra8_widget_refresh_t
E-ink-style refresh hint carried by a dirty widget.
Definition ra8_widget.h:98
@ k_ra8_widget_refresh_fast
Partial / A2 (text-only change).
Definition ra8_widget.h:100
@ k_ra8_widget_refresh_none
Clean – not dirty.
Definition ra8_widget.h:99
@ k_ra8_widget_refresh_quality
Full / GC16 (whole-area redraw).
Definition ra8_widget.h:101
const ra8_widget_vtable_t * ra8_widget_button_vtable(void)
Return the shared vtable backing every push-button widget.
ra8_widget_ev_kind_t
Input event kind routed to widgets.
Definition ra8_widget.h:68
@ k_ra8_widget_ev_touch
A touch / tap at (x, y).
Definition ra8_widget.h:69
@ k_ra8_widget_ev_button
A physical button press (button_id).
Definition ra8_widget.h:70
ra8_err_t ra8_widget_render_dirty(ra8_widget_t *widgets, uint16_t count)
Render every visible + dirty widget, clearing its damage.
Definition ra8_widget.c:331
ra8_widget_align_t
Horizontal placement of a leaf widget's text within its rect.
Definition ra8_widget.h:540
@ k_ra8_widget_align_left
Hug the left inner inset.
Definition ra8_widget.h:541
@ k_ra8_widget_align_right
Hug the right inner inset.
Definition ra8_widget.h:543
@ k_ra8_widget_align_center
Centre horizontally in the rect.
Definition ra8_widget.h:542
ra8_err_t ra8_widget_dispatch(ra8_widget_t *widgets, uint16_t count, const ra8_widget_event_t *ev, bool *out_handled)
Route an event to the widget that should handle it.
Definition ra8_widget.c:252
ra8_err_t ra8_widget_button_init(ra8_widget_t *w, ra8_widget_button_t *button)
Bind a widget instance to a push button.
One node in a box tree (caller-owned).
Definition ra8_box.h:90
Axis-aligned rectangle in framebuffer pixel coordinates.
Definition ra8_ui.h:72
A push-button leaf widget: a bordered face + label that latches on tap.
ra8_widget_align_t align
Label alignment.
Definition ra8_widget.h:602
void(* on_press)(struct ra8_widget *w)
Press callback (optional / NULL).
Definition ra8_widget.h:594
uint32_t fg
Label colour, 0xRRGGBB.
Definition ra8_widget.h:595
uint32_t face
Face fill when released, 0xRRGGBB.
Definition ra8_widget.h:596
const char * text
Label (NULL -> face only).
Definition ra8_widget.h:593
uint32_t border
Outline colour, 0xRRGGBB.
Definition ra8_widget.h:598
uint32_t face_pressed
Face fill when pressed, 0xRRGGBB.
Definition ra8_widget.h:597
bool pressed
Latched pressed state.
Definition ra8_widget.h:603
uint8_t reserved
Padding to a 4-byte boundary.
Definition ra8_widget.h:604
uint32_t presses
Count of taps consumed (observable).
Definition ra8_widget.h:599
const ra8_widget_paint_t * paint
Draw backend (NULL -> no draw).
Definition ra8_widget.h:592
int16_t border_w
Outline thickness, pixels (>= 0).
Definition ra8_widget.h:601
int16_t pad
Inner label inset, pixels.
Definition ra8_widget.h:600
One input event delivered to ra8_widget_dispatch.
Definition ra8_widget.h:77
int32_t x
Touch X (for k_ra8_widget_ev_touch).
Definition ra8_widget.h:81
ra8_widget_ev_kind_t kind
Touch or button.
Definition ra8_widget.h:78
uint16_t button_id
Button id (for k_ra8_widget_ev_button).
Definition ra8_widget.h:80
uint8_t reserved
Padding.
Definition ra8_widget.h:79
int32_t y
Touch Y (for k_ra8_widget_ev_touch).
Definition ra8_widget.h:82
A text-label leaf widget: a background fill plus an aligned string.
uint32_t bg
Background fill colour, 0xRRGGBB.
Definition ra8_widget.h:566
int16_t pad
Inner text inset, pixels.
Definition ra8_widget.h:567
const ra8_widget_paint_t * paint
Draw backend (NULL -> draws nothing).
Definition ra8_widget.h:563
const char * text
NUL-terminated ASCII (NULL -> bg only).
Definition ra8_widget.h:564
uint32_t fg
Text colour, 0xRRGGBB.
Definition ra8_widget.h:565
uint8_t reserved
Padding to a 4-byte boundary.
Definition ra8_widget.h:569
ra8_widget_align_t align
Horizontal text alignment.
Definition ra8_widget.h:568
Drawing backend the concrete leaf widgets paint through (a DI seam).
void * user
Opaque backend handle handed back to every callback below.
Definition ra8_widget.h:523
void(* draw_text)(void *user, int32_t x, int32_t y, const char *str, uint32_t fg, uint32_t bg)
Draw a NUL-terminated ASCII string in fg over bg.
Definition ra8_widget.h:527
void(* text_size)(void *user, const char *str, int32_t *out_w, int32_t *out_h)
Measure a string's pixel size; NULL disables centre/right align.
Definition ra8_widget.h:529
void(* fill_rect)(void *user, int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color)
Fill an axis-aligned rectangle with one solid colour.
Definition ra8_widget.h:525
A container widget's child array + stack-layout parameters (#145).
ra8_widget_axis_t axis
Stack main axis (col / row).
Definition ra8_widget.h:375
int16_t pad
Inner padding inset on the panel (pixels).
Definition ra8_widget.h:374
uint8_t reserved
Padding to a 4-byte boundary.
Definition ra8_widget.h:376
ra8_box_t * box_scratch
Layout scratch (>= count + 1 ra8_box_t).
Definition ra8_widget.h:370
uint16_t count
Number of children.
Definition ra8_widget.h:371
ra8_widget_t * children
Child widget array (caller-owned).
Definition ra8_widget.h:369
int16_t gap
Gap between children (pixels).
Definition ra8_widget.h:373
uint16_t box_cap
Capacity of box_scratch.
Definition ra8_widget.h:372
One widget instance (caller-owned, no allocation).
Behaviour table shared by all widgets of one kind.
Definition ra8_widget.h:121
void(* render)(struct ra8_widget *w)
Draw the widget within its current rect (on-target only).
Definition ra8_widget.h:139
bool(* on_input)(struct ra8_widget *w, const ra8_widget_event_t *ev)
Handle an input event.
Definition ra8_widget.h:146
void(* measure)(struct ra8_widget *w, int32_t avail_w, int32_t avail_h, int32_t *out_w, int32_t *out_h)
Report the widget's desired size within an available box.
Definition ra8_widget.h:130
ra8_ui_rect_t rect
Current bounds (layout output).
Definition ra8_widget.h:162
uint16_t flex
Flex weight when not fixed.
Definition ra8_widget.h:164
uint8_t refresh
ra8_widget_refresh_t (pending).
Definition ra8_widget.h:166
const ra8_widget_vtable_t * vt
Behaviour table (non-NULL).
Definition ra8_widget.h:160
int16_t fixed
Fixed main-axis extent, or 0.
Definition ra8_widget.h:163
uint16_t action_id
Hit-routing id (0 = none).
Definition ra8_widget.h:165
bool visible
Laid out / drawn when true.
Definition ra8_widget.h:167
bool dirty
Needs a redraw + flush.
Definition ra8_widget.h:168
void * ctx
Widget-specific state.
Definition ra8_widget.h:161