ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_widget_keyboard.c
Go to the documentation of this file.
1
22
23#include "ra8_widget_keyboard.h"
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_keyboard";
31
42
61{
62 const ra8_widget_paint_t* p = kbd->paint;
63 priv_widget_fill_box(p, &info->rect, kbd->key_face, kbd->key_border, kbd->border_w);
64 if (p->draw_text == nullptr) {
65 return;
66 }
67 char glyph_buf[k_ra8_widget_kbd_glyph_len] = {};
68 const char* text = info->label;
69 if (info->glyph != (char)k_ra8_widget_kbd_no_glyph) {
70 glyph_buf[k_ra8_widget_kbd_glyph_char] = info->glyph;
71 glyph_buf[k_ra8_widget_kbd_glyph_nul] = '\0';
72 text = glyph_buf;
73 }
74 if (text == nullptr) {
75 return;
76 }
77 int32_t tx = 0;
78 int32_t ty = 0;
79 priv_widget_text_pos(p, &info->rect, text, (int16_t)0, k_ra8_widget_align_center, &tx, &ty);
80 p->draw_text(p->user, tx, ty, text, kbd->key_fg, kbd->key_face);
81}
82
100{
102 if (kbd == nullptr) {
103 return;
104 }
105 if (kbd->paint == nullptr) {
106 return;
107 }
108 priv_widget_fill_box(kbd->paint, &w->rect, kbd->bg, kbd->bg, (int16_t)0);
109 if ((kbd->ops == nullptr) || (kbd->ops->count == nullptr) || (kbd->ops->key_info == nullptr)) {
110 return;
111 }
112 const uint8_t n = kbd->ops->count(kbd->ops->user);
113 for (uint8_t i = 0U; i < n; ++i) {
114 ra8_widget_key_info_t info = {};
115 kbd->ops->key_info(kbd->ops->user, i, &info);
116 internal_kbd_key(kbd, &info);
117 }
118}
119
141{
143 if (kbd == nullptr) {
144 return false;
145 }
146 if (ev->kind != k_ra8_widget_ev_touch) {
147 return false;
148 }
149 if ((kbd->ops == nullptr) || (kbd->ops->hit == nullptr) || (kbd->ops->apply == nullptr)) {
150 return true;
151 }
152 const uint8_t key = kbd->ops->hit(kbd->ops->user, ev->x, ev->y);
153 if (key == (uint8_t)k_ra8_widget_key_no_hit) {
154 return true;
155 }
156 const bool committed = kbd->ops->apply(kbd->ops->user, key);
158 if (committed && (kbd->on_commit != nullptr)) {
159 kbd->on_commit(w);
160 }
161 return true;
162}
163
166 .measure = nullptr,
167 .render = internal_kbd_render,
168 .on_input = internal_kbd_on_input,
169};
170
172{
173 return &s_kbd_vt;
174}
175
177{
178 RA8_CHECK_NULL_PTR(w, s_tag, "w must not be nullptr");
179 RA8_CHECK_NULL_PTR(kbd, s_tag, "kbd must not be nullptr");
181 w->ctx = kbd;
182 w->visible = true;
183 return k_ra8_ok;
184}
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_quality
Full / GC16 (whole-area redraw).
Definition ra8_widget.h:101
@ 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_kbd_render(ra8_widget_t *w)
Keyboard vtable render: fill the background, draw every key.
static bool internal_kbd_on_input(ra8_widget_t *w, const ra8_widget_event_t *ev)
Keyboard vtable input: hit a key, apply it, fire the commit edge.
static const ra8_widget_vtable_t s_kbd_vt
The single immutable vtable shared by every on-screen keyboard.
ra8_err_t ra8_widget_keyboard_init(ra8_widget_t *w, ra8_widget_keyboard_t *kbd)
Bind a widget instance to an on-screen keyboard.
const ra8_widget_vtable_t * ra8_widget_keyboard_vtable(void)
Return the shared vtable backing every on-screen-keyboard widget.
static void internal_kbd_key(const ra8_widget_keyboard_t *kbd, const ra8_widget_key_info_t *info)
Draw one key: a bordered face plus its centred glyph or label.
ra8_widget_kbd_geom_t
Glyph-buffer indices (no magic numbers).
@ k_ra8_widget_kbd_glyph_nul
NUL terminator slot.
@ k_ra8_widget_kbd_glyph_char
Glyph char slot in the 2-byte buffer.
@ k_ra8_widget_kbd_no_glyph
glyph == 0: not a character key.
@ k_ra8_widget_kbd_glyph_len
Single-glyph string buffer length.
On-screen-keyboard leaf widget for the ra8_widget tree (#145 Phase 2).
@ k_ra8_widget_key_no_hit
The tap hit no key (a gap / off-grid).
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
One key's drawable geometry + glyph, supplied by the keyboard seam.
An on-screen keyboard: key styling + engine seam + commit callback.
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