ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_widget_reflow_view.c
Go to the documentation of this file.
1
22
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_reflow_view";
32
37typedef enum : uint16_t {
41
60static ra8_ui_rect_t internal_rv_body(const ra8_ui_rect_t* rect, int16_t mx, int16_t my)
61{
62 const int32_t x = (int32_t)mx;
63 const int32_t y = (int32_t)my;
64 ra8_ui_rect_t body = {};
65 body.x = rect->x + x;
66 body.y = rect->y + y;
67 body.w = rect->w - (x + x);
68 body.h = rect->h - (y + y);
69 return body;
70}
71
89static uint16_t internal_rv_clamp(uint16_t page, uint16_t count)
90{
91 if (count == (uint16_t)k_ra8_widget_rv_first) {
92 return (uint16_t)k_ra8_widget_rv_first;
93 }
94 if (page >= count) {
95 return (uint16_t)(count - (uint16_t)k_ra8_widget_rv_one);
96 }
97 return page;
98}
99
120static bool internal_rv_turn(ra8_widget_reflow_view_t* v, int32_t px, int32_t mid)
121{
122 if (px < mid) {
123 if (v->page == (uint16_t)k_ra8_widget_rv_first) {
124 return false;
125 }
126 v->page = (uint16_t)(v->page - (uint16_t)k_ra8_widget_rv_one);
127 return true;
128 }
129 if ((uint16_t)(v->page + (uint16_t)k_ra8_widget_rv_one) >= v->page_count) {
130 return false;
131 }
132 v->page = (uint16_t)(v->page + (uint16_t)k_ra8_widget_rv_one);
133 return true;
134}
135
153{
155 if (v == nullptr) {
156 return;
157 }
158 if (v->paint != nullptr) {
159 priv_widget_fill_box(v->paint, &w->rect, v->bg, v->bg, (int16_t)0);
160 }
161 if ((v->ops == nullptr) || (v->ops->render_page == nullptr)) {
162 return;
163 }
164 const ra8_ui_rect_t body = internal_rv_body(&w->rect, v->margin_x, v->margin_y);
165 v->ops->render_page(v->ops->user, v->page, &body);
166}
167
188static bool
190{
191 if ((v->ops == nullptr) || (v->ops->follow_link == nullptr)) {
192 return false;
193 }
194 uint16_t dest = v->page;
195 if (!v->ops->follow_link(v->ops->user, v->page, ev->x, ev->y, &dest)) {
196 return false;
197 }
198 v->page = internal_rv_clamp(dest, v->page_count);
200 return true;
201}
202
223{
225 if (v == nullptr) {
226 return false;
227 }
228 if (ev->kind != k_ra8_widget_ev_touch) {
229 return false;
230 }
231 if (internal_rv_link(w, v, ev)) {
232 return true;
233 }
234 const int32_t mid = w->rect.x + (w->rect.w / 2);
235 if (internal_rv_turn(v, ev->x, mid)) {
237 }
238 return true;
239}
240
243 .measure = nullptr,
244 .render = internal_rv_render,
245 .on_input = internal_rv_on_input,
246};
247
252
254{
255 RA8_CHECK_NULL_PTR(w, s_tag, "w must not be nullptr");
256 RA8_CHECK_NULL_PTR(view, s_tag, "view must not be nullptr");
258 w->ctx = view;
259 w->visible = true;
260 return k_ra8_ok;
261}
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_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
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.
static const ra8_widget_vtable_t s_rv_vt
The single immutable vtable shared by every reflow view.
static bool internal_rv_link(ra8_widget_t *w, ra8_widget_reflow_view_t *v, const ra8_widget_event_t *ev)
Try to follow a link at the tap through the seam.
static void internal_rv_render(ra8_widget_t *w)
Reflow-view vtable render: clear the body, ask the seam to paint it.
static uint16_t internal_rv_clamp(uint16_t page, uint16_t count)
Clamp a page index into [0, count - 1].
static ra8_ui_rect_t internal_rv_body(const ra8_ui_rect_t *rect, int16_t mx, int16_t my)
Body rectangle: the widget rect inset by the view margins.
ra8_widget_rv_geom_t
Paging constants (no magic numbers).
@ k_ra8_widget_rv_first
First page index / empty book.
@ k_ra8_widget_rv_one
One-page step / minimum count.
const ra8_widget_vtable_t * ra8_widget_reflow_view_vtable(void)
Return the shared vtable backing every reflow-view widget.
static bool internal_rv_turn(ra8_widget_reflow_view_t *v, int32_t px, int32_t mid)
Turn the page by a tap side, clamped at both ends.
static bool internal_rv_on_input(ra8_widget_t *w, const ra8_widget_event_t *ev)
Reflow-view vtable input: follow a link, else turn the page.
ra8_err_t ra8_widget_reflow_view_init(ra8_widget_t *w, ra8_widget_reflow_view_t *view)
Bind a widget instance to a reflow view.
Reflowed-reading-body leaf widget for the ra8_widget tree (#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
A paginated reflowed-text body: page state + margins + engine seam.
One widget instance (caller-owned, no allocation).
Behaviour table shared by all widgets of one kind.
Definition ra8_widget.h:121