ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_widget_paint.c
Go to the documentation of this file.
1
27
28#include "ra8_widget_internal.h"
29
31 const ra8_ui_rect_t* rect,
32 const char* text,
33 int16_t pad,
35 int32_t* out_x,
36 int32_t* out_y)
37{
38 *out_x = rect->x + (int32_t)pad;
39 *out_y = rect->y + (int32_t)pad;
40 if (align == k_ra8_widget_align_left) {
41 return;
42 }
43 if (paint->text_size == nullptr) {
44 return;
45 }
46 int32_t tw = 0;
47 int32_t th = 0;
48 paint->text_size(paint->user, text, &tw, &th);
49 *out_y = rect->y + ((rect->h - th) / 2);
50 if (align == k_ra8_widget_align_right) {
51 *out_x = (rect->x + rect->w) - (int32_t)pad - tw;
52 return;
53 }
54 *out_x = rect->x + ((rect->w - tw) / 2);
55}
56
58 const ra8_ui_rect_t* rect,
59 uint32_t fill,
60 uint32_t border,
61 int16_t border_w)
62{
63 if (paint->fill_rect == nullptr) {
64 return;
65 }
66 if (border_w <= 0) {
67 paint->fill_rect(paint->user, rect->x, rect->y, rect->w, rect->h, fill);
68 return;
69 }
70 const int32_t bw = (int32_t)border_w;
71 paint->fill_rect(paint->user, rect->x, rect->y, rect->w, rect->h, border);
72 paint->fill_rect(paint->user,
73 rect->x + bw,
74 rect->y + bw,
75 rect->w - (bw + bw),
76 rect->h - (bw + bw),
77 fill);
78}
79
81typedef enum : int32_t {
84
85RA8_PRIV int32_t priv_widget_fill_frac(uint32_t value, uint32_t total, int32_t width)
86{
87 if (total == 0U) {
88 return (int32_t)k_ra8_widget_frac_empty;
89 }
90 if (width <= (int32_t)k_ra8_widget_frac_empty) {
91 return (int32_t)k_ra8_widget_frac_empty;
92 }
93 uint32_t v = value;
94 if (v > total) {
95 v = total;
96 }
97 return (int32_t)(((uint32_t)width * v) / total);
98}
#define RA8_PRIV
Module-private helper: shared across TUs but only inside one library.
ra8_widget_align_t
Horizontal placement of a leaf widget's text within its rect.
Definition ra8_widget.h:540
@ 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.
ra8_widget_frac_geom_t
No filled pixels (0% or a degenerate rect).
@ k_ra8_widget_frac_empty
RA8 widget frac empty.
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.
int32_t priv_widget_fill_frac(uint32_t value, uint32_t total, int32_t width)
Filled width in pixels for a value / total bar spanning width.
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.
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
Drawing backend the concrete leaf widgets paint through (a DI seam).