ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_widget_button.c
Go to the documentation of this file.
1
24
25#include "ra8_check.h"
26#include "ra8_widget.h"
27#include "ra8_widget_internal.h"
28
30static const char* s_tag = "ra8_widget_button";
31
49{
50 if (b->pressed) {
51 return b->face_pressed;
52 }
53 return b->face;
54}
55
73{
75 if (b == nullptr) {
76 return;
77 }
78 if (b->paint == nullptr) {
79 return;
80 }
81 const uint32_t face = internal_button_face(b);
82 priv_widget_fill_box(b->paint, &w->rect, face, b->border, b->border_w);
83 if (b->text == nullptr) {
84 return;
85 }
86 if (b->paint->draw_text == nullptr) {
87 return;
88 }
89 int32_t tx = 0;
90 int32_t ty = 0;
91 priv_widget_text_pos(b->paint, &w->rect, b->text, b->pad, b->align, &tx, &ty);
92 b->paint->draw_text(b->paint->user, tx, ty, b->text, b->fg, face);
93}
94
116{
118 if (b == nullptr) {
119 return false;
120 }
121 if (ev->kind != k_ra8_widget_ev_touch) {
122 return false;
123 }
124 b->pressed = !b->pressed;
125 b->presses++;
127 if (b->on_press != nullptr) {
128 b->on_press(w);
129 }
130 return true;
131}
132
135 .measure = nullptr,
136 .render = internal_button_render,
137 .on_input = internal_button_on_input,
138};
139
141{
142 return &s_button_vt;
143}
144
146{
147 RA8_CHECK_NULL_PTR(w, s_tag, "w must not be nullptr");
148 RA8_CHECK_NULL_PTR(button, s_tag, "button must not be nullptr");
149 w->vt = ra8_widget_button_vtable();
150 w->ctx = button;
151 w->visible = true;
152 return k_ra8_ok;
153}
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
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
static bool internal_button_on_input(ra8_widget_t *w, const ra8_widget_event_t *ev)
Button vtable input: latch a touch, decline everything else.
static uint32_t internal_button_face(const ra8_widget_button_t *b)
Pick the face fill colour for the button's current state.
static const ra8_widget_vtable_t s_button_vt
The single immutable vtable shared by every push button.
static void internal_button_render(ra8_widget_t *w)
Button vtable render: paint the bordered face, then the label.
const ra8_widget_vtable_t * ra8_widget_button_vtable(void)
Return the shared vtable backing every push-button widget.
ra8_err_t ra8_widget_button_init(ra8_widget_t *w, ra8_widget_button_t *button)
Bind a widget instance to a push button.
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.
A push-button leaf widget: a bordered face + label that latches on tap.
One input event delivered to ra8_widget_dispatch.
Definition ra8_widget.h:77
ra8_widget_ev_kind_t kind
Touch or button.
Definition ra8_widget.h:78
One widget instance (caller-owned, no allocation).
Behaviour table shared by all widgets of one kind.
Definition ra8_widget.h:121