ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_widget_status_bar.c
Go to the documentation of this file.
1
21
23
24#include "ra8_check.h"
25#include "ra8_widget.h"
26#include "ra8_widget_internal.h"
27
29static const char* s_tag = "ra8_widget_status_bar";
30
34typedef enum : int16_t {
37
59static void internal_sb_label(const ra8_widget_paint_t* paint,
60 const ra8_ui_rect_t* rect,
61 const char* text,
62 int16_t pad,
64 uint32_t fg,
65 uint32_t bg)
66{
67 if (text == nullptr) {
68 return;
69 }
70 if (paint->draw_text == nullptr) {
71 return;
72 }
73 int32_t tx = 0;
74 int32_t ty = 0;
75 priv_widget_text_pos(paint, rect, text, pad, align, &tx, &ty);
76 paint->draw_text(paint->user, tx, ty, text, fg, bg);
77}
78
96{
98 if (sb == nullptr) {
99 return;
100 }
101 if (sb->paint == nullptr) {
102 return;
103 }
104 const ra8_ui_rect_t* r = &w->rect;
105 priv_widget_fill_box(sb->paint, r, sb->bg, sb->bg, (int16_t)k_ra8_widget_sb_no_rule);
106 internal_sb_label(sb->paint, r, sb->left, sb->pad, k_ra8_widget_align_left, sb->fg, sb->bg);
107 internal_sb_label(sb->paint,
108 r,
109 sb->right,
110 sb->pad,
112 sb->fg_right,
113 sb->bg);
114 if (sb->rule_h <= (int16_t)k_ra8_widget_sb_no_rule) {
115 return;
116 }
117 if (sb->paint->fill_rect == nullptr) {
118 return;
119 }
120 sb->paint->fill_rect(sb->paint->user,
121 r->x,
122 (r->y + r->h) - (int32_t)sb->rule_h,
123 r->w,
124 (int32_t)sb->rule_h,
125 sb->rule);
126}
127
130 .measure = nullptr,
131 .render = internal_sb_render,
132 .on_input = nullptr,
133};
134
136{
137 return &s_sb_vt;
138}
139
141{
142 RA8_CHECK_NULL_PTR(w, s_tag, "w must not be nullptr");
143 RA8_CHECK_NULL_PTR(bar, s_tag, "bar must not be nullptr");
145 w->ctx = bar;
146 w->visible = true;
147 return k_ra8_ok;
148}
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_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.
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 const ra8_widget_vtable_t s_sb_vt
The single immutable vtable shared by every status bar.
ra8_err_t ra8_widget_status_bar_init(ra8_widget_t *w, ra8_widget_status_bar_t *bar)
Bind a widget instance to a status bar.
static void internal_sb_label(const ra8_widget_paint_t *paint, const ra8_ui_rect_t *rect, const char *text, int16_t pad, ra8_widget_align_t align, uint32_t fg, uint32_t bg)
Draw one aligned label on the status band through the paint backend.
static void internal_sb_render(ra8_widget_t *w)
Status-bar vtable render: fill, left + right labels, bottom hairline.
ra8_widget_sb_geom_t
No hairline: a rule_h at or below this draws no bottom rule.
@ k_ra8_widget_sb_no_rule
Threshold below which the rule is skipped.
const ra8_widget_vtable_t * ra8_widget_status_bar_vtable(void)
Return the shared vtable backing every status-bar widget.
Status-bar 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
Drawing backend the concrete leaf widgets paint through (a DI seam).
A status band: a fill, a left + right label, and a bottom hairline.
One widget instance (caller-owned, no allocation).
Behaviour table shared by all widgets of one kind.
Definition ra8_widget.h:121