ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_widget_toolbar.c
Go to the documentation of this file.
1
22
23#include "ra8_widget_toolbar.h"
24
25#include "ra8_check.h"
26#include "ra8_ui.h"
27#include "ra8_widget.h"
28#include "ra8_widget_internal.h"
29
31static const char* s_tag = "ra8_widget_toolbar";
32
52 const ra8_ui_rect_t* band)
53{
54 const int32_t pad = (int32_t)bar->pad;
55 const int32_t chip = (int32_t)bar->count_w;
56 const int32_t field_w = band->w - (pad + pad) - chip - pad;
57 ra8_ui_rect_t r = {};
58 r.x = band->x + pad;
59 r.y = band->y + pad;
60 r.w = (field_w > 0) ? field_w : 0;
61 r.h = band->h - (pad + pad);
62 return r;
63}
64
82{
84 if (bar == nullptr) {
85 return;
86 }
87 if (bar->paint == nullptr) {
88 return;
89 }
90 const ra8_widget_paint_t* p = bar->paint;
91 const ra8_ui_rect_t* band = &w->rect;
92 const ra8_ui_rect_t field = internal_tb_field_rect(bar, band);
93 priv_widget_fill_box(p, band, bar->bg, bar->bg, (int16_t)0);
94 priv_widget_fill_box(p, &field, bar->field, bar->border, bar->border_w);
95 if (p->draw_text == nullptr) {
96 return;
97 }
98 if (bar->hint != nullptr) {
99 int32_t hx = 0;
100 int32_t hy = 0;
101 priv_widget_text_pos(p, &field, bar->hint, bar->pad, k_ra8_widget_align_left, &hx, &hy);
102 p->draw_text(p->user, hx, hy, bar->hint, bar->hint_fg, bar->field);
103 }
104 if (bar->count != nullptr) {
105 int32_t cx = 0;
106 int32_t cy = 0;
107 priv_widget_text_pos(p, band, bar->count, bar->pad, k_ra8_widget_align_right, &cx, &cy);
108 p->draw_text(p->user, cx, cy, bar->count, bar->count_fg, bar->bg);
109 }
110}
111
132{
134 if (bar == nullptr) {
135 return false;
136 }
137 if (ev->kind != k_ra8_widget_ev_touch) {
138 return false;
139 }
140 const ra8_ui_rect_t field = internal_tb_field_rect(bar, &w->rect);
141 if (!ra8_ui_rect_contains(&field, ev->x, ev->y)) {
142 return false;
143 }
144 bar->searches++;
146 if (bar->on_search != nullptr) {
147 bar->on_search(w);
148 }
149 return true;
150}
151
154 .measure = nullptr,
155 .render = internal_tb_render,
156 .on_input = internal_tb_on_input,
157};
158
160{
161 return &s_tb_vt;
162}
163
165{
166 RA8_CHECK_NULL_PTR(w, s_tag, "w must not be nullptr");
167 RA8_CHECK_NULL_PTR(bar, s_tag, "bar must not be nullptr");
169 w->ctx = bar;
170 w->visible = true;
171 return k_ra8_ok;
172}
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.
bool ra8_ui_rect_contains(const ra8_ui_rect_t *r, int32_t px, int32_t py)
Test whether a point lies inside a rectangle.
Definition ra8_ui.c:34
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_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
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 bool internal_tb_on_input(ra8_widget_t *w, const ra8_widget_event_t *ev)
Toolbar vtable input: latch a touch inside the search field.
static ra8_ui_rect_t internal_tb_field_rect(const ra8_widget_toolbar_t *bar, const ra8_ui_rect_t *band)
Compute the search-field sub-rectangle inside a toolbar band.
static void internal_tb_render(ra8_widget_t *w)
Toolbar vtable render: band fill, bordered field + hint, count chip.
const ra8_widget_vtable_t * ra8_widget_toolbar_vtable(void)
Return the shared vtable backing every toolbar widget.
static const ra8_widget_vtable_t s_tb_vt
The single immutable vtable shared by every toolbar.
ra8_err_t ra8_widget_toolbar_init(ra8_widget_t *w, ra8_widget_toolbar_t *bar)
Bind a widget instance to a toolbar.
Toolbar 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
int32_t y
Touch Y (for k_ra8_widget_ev_touch).
Definition ra8_widget.h:82
Drawing backend the concrete leaf widgets paint through (a DI seam).
One widget instance (caller-owned, no allocation).
A search-field + count-chip toolbar band with a tappable field.
Behaviour table shared by all widgets of one kind.
Definition ra8_widget.h:121