rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
ui_slider.h File Reference

A draggable value with presets: the throttle, and any other control that needs coarse reach and fine adjustment in one place. More...

#include <stdbool.h>
#include "gfx.h"
#include "touch_types.h"

Go to the source code of this file.

Data Structures

struct  ui_slider_t

Macros

#define UI_SLIDER_MAX_PRESETS   8
#define UI_SLIDER_OVERHANG   5

Functions

void ui_slider_init (ui_slider_t *s, gfx_rect_t track, float min, float max, gfx_color_t color)
void ui_slider_set_ticks (ui_slider_t *s, int n)
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.
void ui_slider_set (ui_slider_t *s, float value)
void ui_slider_set_tap_to_set (ui_slider_t *s, bool on)
void ui_slider_release (ui_slider_t *s)
bool ui_slider_event (ui_slider_t *s, const touch_event_t *evt)
void ui_slider_render (const ui_slider_t *s, gfx_canvas_t *c)
gfx_rect_t ui_slider_painted_rect (const ui_slider_t *s)

Detailed Description

A draggable value with presets: the throttle, and any other control that needs coarse reach and fine adjustment in one place.

Two contracts about presses that do not end where they began, because those are the presses that command a motor by accident:

a press that starts on the track owns the value until it is released, wherever it moves, so a finger sliding off the track does not hand the value to whatever is underneath;

a press that starts anywhere else never becomes a drag, however far it travels across the track.

SPDX-License-Identifier: MIT

Function Documentation

◆ ui_slider_event()

bool ui_slider_event ( ui_slider_t * s,
const touch_event_t * evt )

Returns true when the value changed as a result of this event.

◆ ui_slider_painted_rect()

gfx_rect_t ui_slider_painted_rect ( const ui_slider_t * s)

Every pixel ui_slider_render may touch, the thumb's overhang and its shadow included. A caller that repaints the slider without repainting everything around it clears this and not the track, or the thumb's old positions stay on the screen.

◆ ui_slider_release()

void ui_slider_release ( ui_slider_t * s)

Abandon a drag that will get no release, on leaving a screen.

◆ ui_slider_set_presets()

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.

Parameters
sthe slider
valuesthe presets' values
labelstheir labels
counthow many
rowthe row they take

◆ ui_slider_set_tap_to_set()

void ui_slider_set_tap_to_set ( ui_slider_t * s,
bool on )

Let a press set the value under it. Off by default; a throttle must not take a value from one contact.

◆ ui_slider_set_ticks()

void ui_slider_set_ticks ( ui_slider_t * s,
int n )

Draw n scale divisions across the track. 0 turns them off.