ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_widget_nav_bar.c
Go to the documentation of this file.
1
21
22#include "ra8_widget_nav_bar.h"
23
24#include "ra8_check.h"
25#include "ra8_ui.h"
26#include "ra8_widget.h"
27#include "ra8_widget_internal.h"
28
30static const char* s_tag = "ra8_widget_nav_bar";
31
35typedef enum : uint16_t {
38
57static ra8_ui_rect_t internal_nav_cell(const ra8_ui_rect_t* strip, uint16_t idx, uint16_t count)
58{
59 const int32_t x0 = (strip->w * (int32_t)idx) / (int32_t)count;
60 const int32_t x1 = (strip->w * (int32_t)(idx + 1U)) / (int32_t)count;
61 ra8_ui_rect_t r = {};
62 r.x = strip->x + x0;
63 r.y = strip->y;
64 r.w = x1 - x0;
65 r.h = strip->h;
66 return r;
67}
68
87static void internal_nav_item(const ra8_widget_paint_t* paint,
88 const ra8_ui_rect_t* cell,
89 const char* text,
90 uint32_t fg,
91 uint32_t bg)
92{
93 if (text == nullptr) {
94 return;
95 }
96 int32_t tx = 0;
97 int32_t ty = 0;
98 priv_widget_text_pos(paint, cell, text, (int16_t)0, k_ra8_widget_align_center, &tx, &ty);
99 paint->draw_text(paint->user, tx, ty, text, fg, bg);
100}
101
119{
121 if (nav == nullptr) {
122 return;
123 }
124 if (nav->paint == nullptr) {
125 return;
126 }
127 const ra8_widget_paint_t* p = nav->paint;
128 const ra8_ui_rect_t* strip = &w->rect;
129 priv_widget_fill_box(p, strip, nav->bg, nav->bg, (int16_t)0);
130 if (nav->count == (uint16_t)k_ra8_widget_nav_empty) {
131 return;
132 }
133 if ((p->draw_text == nullptr) || (nav->items == nullptr)) {
134 return;
135 }
136 for (uint16_t i = 0U; i < nav->count; ++i) {
137 const ra8_ui_rect_t cell = internal_nav_cell(strip, i, nav->count);
138 const uint32_t fg = (i == nav->active) ? nav->fg_active : nav->fg_muted;
139 internal_nav_item(p, &cell, nav->items[i], fg, nav->bg);
140 }
141}
142
164static bool internal_nav_hit(const ra8_ui_rect_t* strip, uint16_t count, int32_t px, uint16_t* out)
165{
166 if (count == (uint16_t)k_ra8_widget_nav_empty) {
167 return false;
168 }
169 if (strip->w <= 0) {
170 return false;
171 }
172 if ((px < strip->x) || (px >= (strip->x + strip->w))) {
173 return false;
174 }
175 const int32_t idx = ((px - strip->x) * (int32_t)count) / strip->w;
176 *out = (uint16_t)idx;
177 return true;
178}
179
199{
201 if (nav == nullptr) {
202 return false;
203 }
204 if (ev->kind != k_ra8_widget_ev_touch) {
205 return false;
206 }
207 uint16_t idx = 0U;
208 if (!internal_nav_hit(&w->rect, nav->count, ev->x, &idx)) {
209 return false;
210 }
211 nav->selected = idx;
213 if (nav->on_select != nullptr) {
214 nav->on_select(w, idx);
215 }
216 return true;
217}
218
221 .measure = nullptr,
222 .render = internal_nav_render,
223 .on_input = internal_nav_on_input,
224};
225
227{
228 return &s_nav_vt;
229}
230
232{
233 RA8_CHECK_NULL_PTR(w, s_tag, "w must not be nullptr");
234 RA8_CHECK_NULL_PTR(nav, s_tag, "nav must not be nullptr");
236 w->ctx = nav;
237 w->visible = true;
238 return k_ra8_ok;
239}
static const char * s_tag
Logging / check tag.
Definition ra8_app.c:17
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
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.
Definition ra8_check.h:243
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
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.
Zero-heap composable widget layer (dwm-style) over ra8_box + ra8_ui.
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
@ k_ra8_widget_refresh_fast
Partial / A2 (text-only change).
Definition ra8_widget.h:100
@ k_ra8_widget_ev_touch
A touch / tap at (x, y).
Definition ra8_widget.h:69
@ k_ra8_widget_align_center
Centre horizontally in the rect.
Definition ra8_widget.h:542
Module-private paint helpers shared by the concrete leaf-widget TUs.
void priv_widget_fill_box(const ra8_widget_paint_t *paint, const ra8_ui_rect_t *rect, uint32_t fill, uint32_t border, int16_t border_w)
Fill a widget rect with an optional 1-or-more-pixel border.
void priv_widget_text_pos(const ra8_widget_paint_t *paint, const ra8_ui_rect_t *rect, const char *text, int16_t pad, ra8_widget_align_t align, int32_t *out_x, int32_t *out_y)
Compute where a leaf widget's text should start within its rect.
static void internal_nav_item(const ra8_widget_paint_t *paint, const ra8_ui_rect_t *cell, const char *text, uint32_t fg, uint32_t bg)
Draw one nav item's centred label in its cell.
static bool internal_nav_on_input(ra8_widget_t *w, const ra8_widget_event_t *ev)
Nav-strip vtable input: route a touch to the cell it hit.
static const ra8_widget_vtable_t s_nav_vt
The single immutable vtable shared by every nav strip.
const ra8_widget_vtable_t * ra8_widget_nav_bar_vtable(void)
Return the shared vtable backing every navigation-strip widget.
static bool internal_nav_hit(const ra8_ui_rect_t *strip, uint16_t count, int32_t px, uint16_t *out)
Map a touch X to a cell index within a count-cell strip.
static ra8_ui_rect_t internal_nav_cell(const ra8_ui_rect_t *strip, uint16_t idx, uint16_t count)
Compute cell idx of a count-cell strip laid inside strip.
static void internal_nav_render(ra8_widget_t *w)
Nav-strip vtable render: fill the strip, centre each cell's label.
ra8_widget_nav_geom_t
Empty sentinel: an empty strip (no items) draws / routes nothing.
@ k_ra8_widget_nav_empty
A count of this many is a no-op.
ra8_err_t ra8_widget_nav_bar_init(ra8_widget_t *w, ra8_widget_nav_bar_t *nav)
Bind a widget instance to a navigation strip.
Navigation-strip leaf widget for the ra8_widget tree model (#145 Phase 2).
Axis-aligned rectangle in framebuffer pixel coordinates.
Definition ra8_ui.h:72
int32_t w
Width (pixels, >= 0).
Definition ra8_ui.h:75
int32_t h
Height (pixels, >= 0).
Definition ra8_ui.h:76
int32_t x
Left edge (pixels).
Definition ra8_ui.h:73
int32_t y
Top edge (pixels).
Definition ra8_ui.h:74
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
An equal-cell navigation strip: N labels, one active, each tappable.
Drawing backend the concrete leaf widgets paint through (a DI seam).
One widget instance (caller-owned, no allocation).
Behaviour table shared by all widgets of one kind.
Definition ra8_widget.h:121