rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
ui_slider.h
Go to the documentation of this file.
1
18#pragma once
19
20#include <stdbool.h>
21
22#include "gfx.h"
23#include "touch_types.h"
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29#define UI_SLIDER_MAX_PRESETS 8
30
31/*
32 * How far ui_slider_render paints outside its track, above and below, in
33 * pixels.
34 *
35 * The thumb stands proud of the track, and a caller that clears only the
36 * track rectangle before redrawing leaves that overhang behind. The thumb's
37 * shadow is offset 2px below it, so the painted region is not symmetric and
38 * this constant alone does not describe it: use ui_slider_painted_rect().
39 */
40#define UI_SLIDER_OVERHANG 5
41
42typedef struct {
43 gfx_rect_t track;
44 gfx_rect_t presets[UI_SLIDER_MAX_PRESETS];
45 float preset_value[UI_SLIDER_MAX_PRESETS];
46 const char *preset_label[UI_SLIDER_MAX_PRESETS];
47 int preset_count;
48 int ticks;
49
50 float min, max, step;
51 float value;
52 gfx_color_t color;
53
54 /*
55 * Whether a press sets the value under it. Off by default, because the
56 * control this widget was written for is a throttle: a touch at the far
57 * end of the track would command full travel in one contact. A slider
58 * that commands nothing dangerous can turn it on and keep the tap.
59 */
60 bool tap_to_set;
61
62 /* Drawn dimmed, as a button that takes no press is. The drawing only:
63 * the owner decides which events the slider is given. */
64 bool dim;
65
66 bool dragging;
67 uint8_t drag_id;
68 int16_t drag_x;
69 float drag_value;
71 uint8_t preset_id;
73
74void ui_slider_init(ui_slider_t *s, gfx_rect_t track, float min, float max,
75 gfx_color_t color);
78
87void ui_slider_set_presets(ui_slider_t *s, const float *values,
88 const char *const *labels, int count,
89 gfx_rect_t row);
90
91void ui_slider_set(ui_slider_t *s, float value);
92
98
101
103bool ui_slider_event(ui_slider_t *s, const touch_event_t *evt);
104
105void ui_slider_render(const ui_slider_t *s, gfx_canvas_t *c);
106
114
115#ifdef __cplusplus
116}
117#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:81
A DOWN, MOVE or UP of one contact.
Definition touch_types.h:69
Definition ui_slider.h:42
int ticks
Definition ui_slider.h:48
int pressed_preset
Definition ui_slider.h:70
float drag_value
Definition ui_slider.h:69
int16_t drag_x
Definition ui_slider.h:68
Plain data types shared by the touch controller driver, the coordinate mapper and the event tracker....
void ui_slider_set_presets(ui_slider_t *s, const float *values, const char *const *labels, int count, gfx_rect_t row)
Sets the presets, laid out in a row inside row with 4px gaps.
Definition ui_slider.c:43
bool ui_slider_event(ui_slider_t *s, const touch_event_t *evt)
Definition ui_slider.c:125
void ui_slider_release(ui_slider_t *s)
Definition ui_slider.c:95
void ui_slider_set_ticks(ui_slider_t *s, int n)
Definition ui_slider.c:36
gfx_rect_t ui_slider_painted_rect(const ui_slider_t *s)
Definition ui_slider.c:214
void ui_slider_set_tap_to_set(ui_slider_t *s, bool on)
Definition ui_slider.c:88