rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
ui_widgets.h
Go to the documentation of this file.
1
11
12#pragma once
13
14#include <stdbool.h>
15
16#include "gfx.h"
17#include "ui_icons.h"
18#include "ui_theme.h"
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
25void ui_panel(gfx_canvas_t *c, gfx_rect_t r, const char *title,
26 gfx_color_t accent);
27
29void ui_panel_header(gfx_canvas_t *c, gfx_rect_t r, const char *title,
30 gfx_color_t accent);
31
42void ui_button(gfx_canvas_t *c, gfx_rect_t r, const char *label,
43 gfx_color_t fill, bool pressed, bool enabled);
44
53gfx_color_t ui_button_off_fill(void);
54
65void ui_button_font(gfx_canvas_t *c, gfx_rect_t r, const char *label,
66 gfx_color_t fill, bool pressed, bool enabled,
67 const gfx_font_t *f);
68
70bool ui_is_light(gfx_color_t c);
71
87bool ui_text_fits(const gfx_font_t *f, const char *s, int w, int h, int pad);
88
100const gfx_font_t *ui_button_face(const char *label, int w, int h, int pad,
101 const gfx_font_t *big,
102 const gfx_font_t *small);
103
111#define UI_KEYS_FOOT (UI_ALERT_Y - UI_BAND_H - 4)
112
114void ui_card(gfx_canvas_t *c, gfx_rect_t r, gfx_color_t fill);
115
123int ui_text_wrap(gfx_canvas_t *c, gfx_rect_t first, int pitch, const char *t,
124 const gfx_font_t *f, gfx_color_t col);
125
131typedef struct {
132 int16_t icon_dy;
133 int16_t icon;
134 int16_t name_dy;
135 int16_t line_dy;
136 int16_t line_pitch;
141
143#define UI_TILE_PAD 8
144
165void ui_tile(gfx_canvas_t *c, gfx_rect_t r, const ui_tile_look_t *look,
166 ui_icon_fn icon, const char *name, const char *line,
167 bool pressed);
168
171#define UI_PILL_INSET 24
180void ui_pill(gfx_canvas_t *c, gfx_rect_t r, const char *label,
181 gfx_color_t dot, gfx_color_t fill);
182
195void ui_pill_font(gfx_canvas_t *c, gfx_rect_t r, const char *label,
196 gfx_color_t dot, gfx_color_t fill, int inset,
197 const gfx_font_t *f);
198
211void ui_pill_ink(gfx_canvas_t *c, gfx_rect_t r, const char *label,
212 gfx_color_t dot, gfx_color_t fill, gfx_color_t ink,
213 int inset, const gfx_font_t *f);
214
216void ui_bar(gfx_canvas_t *c, gfx_rect_t r, float frac, float peak_frac,
217 gfx_color_t color);
218
220void ui_value(gfx_canvas_t *c, gfx_rect_t box, const char *number,
221 const char *unit, gfx_color_t color);
222
225void ui_fmt(char *out, size_t n, float value, int decimals);
226
232void ui_clock(char *out, size_t n, uint32_t seconds);
233
234/*
235 * The home tag, at the same place at the top left of every screen that has
236 * one: 44px tall (6.6mm), 8px from the band's top and left edges, the
237 * title in UI_FONT_TAG (20 x 36). The router hit-tests it before the
238 * screen sees the event.
239 */
241#define UI_TAG_X 8
243#define UI_TAG_Y 8
245#define UI_TAG_H 44
246
253gfx_rect_t ui_home_tag_rect(const char *title);
254
261void ui_home_tag(gfx_canvas_t *c, const char *title, bool pressed);
262
271void ui_wordmark(gfx_canvas_t *c, const char *text, gfx_color_t fill);
272
274void ui_chevron_left(gfx_canvas_t *c, int x, int cy, int size, gfx_color_t color);
275
284void ui_rule(gfx_canvas_t *c, int x, int y, int w, gfx_color_t color);
285
286/* ----------------------------------------------------------- choice list */
287
288/*
289 * A list that opens over the screen: a face that names the choice, and the
290 * rows it opens into. The chevron on the face says it opens rather than
291 * steps, which is the difference between this and a settings row. The
292 * outputs screen's protocol list and the pin picker's are this one.
293 *
294 * A face or a row UI_CHOICE_ROW_H (56px, 8.4mm) tall or taller draws its
295 * text in the type scale's head face, 20 x 36 (UI_FONT_TAG), when the text
296 * fits; a shorter one, and a text that does not fit, in the 16 x 28 face
297 * (UI_FONT_HEAD). A screen takes the larger face with the row height its
298 * own layout gives. The text is centred in the face's and each row's
299 * height. A face takes 10px before its text and 33px after it for a
300 * 7px chevron, 12px and 43px for an 11px one when tall; a row 12px
301 * before and after its text. Each face and row picks its own face: the
302 * rows of one list can differ where one name does not fit.
303 */
306#define UI_CHOICE_ROW_H 56
307
314const gfx_font_t *ui_choice_font(int h);
315
324const gfx_font_t *ui_choice_text_font(int h, int w, const char *text);
325
326void ui_choice_face(gfx_canvas_t *c, gfx_rect_t r, const char *text,
327 bool pressed, bool open);
328
331void ui_choice_face_locked(gfx_canvas_t *c, gfx_rect_t r, const char *text);
332
340
342void ui_choice_row(gfx_canvas_t *c, gfx_rect_t r, const char *text,
343 bool chosen, bool pressed);
344
345/* ------------------------------------------------------- hold-to-confirm */
346
347/*
348 * A button that is held rather than pressed, and what it looks like while it
349 * is held.
350 *
351 * Two seconds of contact, the fill fading from where it starts to where it
352 * ends across them, and the whole button flashing twice as the command goes.
353 * ARM uses it because a bench should not spin a propeller on a touch that
354 * could have been an elbow; the bus-fault screen uses it because an
355 * acknowledgement that can be given by brushing the panel is not one.
356 *
357 * The timing, the colours and the rules are all here: two screens can arm
358 * the bench, and a safety control that behaves differently on one of them is
359 * a control the operator has to learn twice.
360 */
361#define UI_HOLD_S 2.0f
362
363/*
364 * The most one frame can add to a hold. A frame's duration is measured at
365 * its top and applied at its end, so without a cap a single late frame
366 * completes a hold that began inside that same frame. 0.25s puts at least
367 * eight frames with the press standing between a press and an arm.
368 */
369#define UI_HOLD_MAX_CREDIT_S 0.25f
370
376#define UI_HOLD_FLASH_PHASE_MS 25
378#define UI_HOLD_FLASH_CYCLE 3
380#define UI_HOLD_FLASH_TIMES 2
382#define UI_HOLD_FLASH_MS \
383 (UI_HOLD_FLASH_PHASE_MS * UI_HOLD_FLASH_CYCLE * UI_HOLD_FLASH_TIMES)
384
390gfx_color_t ui_hold_fill(gfx_color_t base, gfx_color_t target, float held_s);
391
403gfx_color_t ui_hold_flash(gfx_color_t settled, int ms_left);
404
415typedef struct {
416 float held_s;
417 bool down;
418 bool fired;
421} ui_hold_t;
422
424void ui_hold_reset(ui_hold_t *h);
425
427void ui_hold_begin(ui_hold_t *h);
428
435bool ui_hold_leave(ui_hold_t *h);
436
439bool ui_hold_end(ui_hold_t *h);
440
447float ui_hold_credit(float dt_s);
448
451bool ui_hold_tick(ui_hold_t *h, float dt_s);
452
462
474bool ui_hold_left(ui_hold_t *h);
475
486void ui_hold_flash_step(ui_hold_t *h, float dt_s);
487
498int ui_hold_flash_left(int ms_left, float dt_s);
499
500#ifdef __cplusplus
501}
502#endif
#define s
Short name for esc_stick_s inside the five stick-class files.
Definition esc_stick_panel_int.h:295
gfx: an RGB565 (16-bit red, green, blue) rasteriser with no dependencies.
Definition gfx.h:129
Definition gfx.h:250
Definition gfx.h:81
Definition ui_widgets.h:415
bool flash_new
Definition ui_widgets.h:420
float held_s
Definition ui_widgets.h:416
int flash_ms
Definition ui_widgets.h:419
bool fired
Definition ui_widgets.h:418
bool down
Definition ui_widgets.h:417
Where a tile places its parts and in which faces: one look per grid, the menu's and SETUP's....
Definition ui_widgets.h:131
int16_t icon_dy
Definition ui_widgets.h:132
const gfx_font_t * name_f
Definition ui_widgets.h:138
int16_t line_pitch
Definition ui_widgets.h:136
const gfx_font_t * line_f
Definition ui_widgets.h:139
int16_t icon
Definition ui_widgets.h:133
int16_t line_dy
Definition ui_widgets.h:135
int16_t name_dy
Definition ui_widgets.h:134
Icons drawn with primitives rather than stored as bitmaps.
void(*) ui_icon_fn(gfx_canvas_t *c, int x, int y, int size, gfx_color_t color)
An icon centred on (x, y), inside a box of size x size px around it. Every ui_icon_ function below ha...
Definition ui_icons.h:26
The visual language of the bench, resolved at runtime.
void ui_choice_list(gfx_canvas_t *c, gfx_rect_t r)
The open list's ground: a shadow 4px down and right, then the panel.
Definition ui_widgets.c:467
float ui_hold_credit(float dt_s)
Definition ui_widgets.c:513
const gfx_font_t * ui_choice_text_font(int h, int w, const char *text)
The face a choice face or row draws text in.
Definition ui_widgets.c:414
bool ui_hold_tick(ui_hold_t *h, float dt_s)
Definition ui_widgets.c:568
void ui_pill_font(gfx_canvas_t *c, gfx_rect_t r, const char *label, gfx_color_t dot, gfx_color_t fill, int inset, const gfx_font_t *f)
ui_pill() with the label in face f, inset px from the left edge and centred in the pill's height.
Definition ui_widgets.c:207
void ui_button_font(gfx_canvas_t *c, gfx_rect_t r, const char *label, gfx_color_t fill, bool pressed, bool enabled, const gfx_font_t *f)
ui_button() with its label in face f.
Definition ui_widgets.c:89
gfx_color_t ui_button_off_fill(void)
The fill of a button that takes no press: the theme's ground (UI_BG), so with its faint label it read...
Definition ui_widgets.c:120
bool ui_text_fits(const gfx_font_t *f, const char *s, int w, int h, int pad)
Whether s in face f fits a box w x h px with pad px to spare at each side.
Definition ui_widgets.c:68
void ui_pill_ink(gfx_canvas_t *c, gfx_rect_t r, const char *label, gfx_color_t dot, gfx_color_t fill, gfx_color_t ink, int inset, const gfx_font_t *f)
ui_pill_font() with the label in colour ink, for a fill the theme's text colour does not read on.
Definition ui_widgets.c:191
bool ui_hold_leave(ui_hold_t *h)
Definition ui_widgets.c:544
int ui_text_wrap(gfx_canvas_t *c, gfx_rect_t first, int pitch, const char *t, const gfx_font_t *f, gfx_color_t col)
Definition ui_widgets.c:144
void ui_panel_header(gfx_canvas_t *c, gfx_rect_t r, const char *title, gfx_color_t accent)
Definition ui_widgets.c:20
void ui_rule(gfx_canvas_t *c, int x, int y, int w, gfx_color_t color)
A 1px horizontal rule.
Definition ui_widgets.c:404
gfx_color_t ui_hold_flash(gfx_color_t settled, int ms_left)
The fill while the flash runs.
Definition ui_widgets.c:639
int ui_hold_flash_left(int ms_left, float dt_s)
The flash's time left, ms_left, after dt_s seconds.
Definition ui_widgets.c:608
void ui_panel(gfx_canvas_t *c, gfx_rect_t r, const char *title, gfx_color_t accent)
Definition ui_widgets.c:37
void ui_hold_flash_step(ui_hold_t *h, float dt_s)
Time passed for the flash.
Definition ui_widgets.c:627
void ui_card(gfx_canvas_t *c, gfx_rect_t r, gfx_color_t fill)
Definition ui_widgets.c:128
void ui_tile(gfx_canvas_t *c, gfx_rect_t r, const ui_tile_look_t *look, ui_icon_fn icon, const char *name, const char *line, bool pressed)
A tile of a grid that opens what it names: the menu's, and SETUP's.
Definition ui_widgets.c:320
void ui_home_tag(gfx_canvas_t *c, const char *title, bool pressed)
Draw the home tag: a chevron and title in UI_FONT_TAG.
Definition ui_widgets.c:380
gfx_color_t ui_hold_fill(gfx_color_t base, gfx_color_t target, float held_s)
Definition ui_widgets.c:489
void ui_wordmark(gfx_canvas_t *c, const char *text, gfx_color_t fill)
The home tag's shape without the chevron: an identity mark, not a control.
Definition ui_widgets.c:393
const gfx_font_t * ui_choice_font(int h)
The face a choice face or row h px tall draws its text in.
Definition ui_widgets.c:409
void ui_choice_row(gfx_canvas_t *c, gfx_rect_t r, const char *text, bool chosen, bool pressed)
Definition ui_widgets.c:477
void ui_value(gfx_canvas_t *c, gfx_rect_t box, const char *number, const char *unit, gfx_color_t color)
Definition ui_widgets.c:238
gfx_rect_t ui_home_tag_rect(const char *title)
Where the home tag with title is drawn and hit.
Definition ui_widgets.c:315
void ui_bar(gfx_canvas_t *c, gfx_rect_t r, float frac, float peak_frac, gfx_color_t color)
Definition ui_widgets.c:220
void ui_chevron_left(gfx_canvas_t *c, int x, int cy, int size, gfx_color_t color)
Definition ui_widgets.c:289
bool ui_hold_end(ui_hold_t *h)
Definition ui_widgets.c:556
void ui_hold_begin(ui_hold_t *h)
Definition ui_widgets.c:535
void ui_hold_reset(ui_hold_t *h)
Definition ui_widgets.c:501
void ui_button(gfx_canvas_t *c, gfx_rect_t r, const char *label, gfx_color_t fill, bool pressed, bool enabled)
Filled rounded button, its label in UI_FONT_LABEL.
Definition ui_widgets.c:83
bool ui_hold_left(ui_hold_t *h)
Definition ui_widgets.c:594
bool ui_is_light(gfx_color_t c)
Definition ui_widgets.c:56
void ui_fmt(char *out, size_t n, float value, int decimals)
Definition ui_widgets.c:269
void ui_pill(gfx_canvas_t *c, gfx_rect_t r, const char *label, gfx_color_t dot, gfx_color_t fill)
A status pill in the label face, its label UI_PILL_INSET px in.
Definition ui_widgets.c:214
void ui_hold_reached(ui_hold_t *h)
Definition ui_widgets.c:584
void ui_choice_face_locked(gfx_canvas_t *c, gfx_rect_t r, const char *text)
Definition ui_widgets.c:459
const gfx_font_t * ui_button_face(const char *label, int w, int h, int pad, const gfx_font_t *big, const gfx_font_t *small)
The face for a button label: big when the label keeps pad px at each side of a w x h px key in it,...
Definition ui_widgets.c:76
void ui_clock(char *out, size_t n, uint32_t seconds)
Definition ui_widgets.c:254