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

A numeric keypad over part of a screen, for a value a slider is too coarse to place. More...

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

Go to the source code of this file.

Data Structures

struct  ui_keypad_t
 A numeric keypad: what it was opened with, what is typed, and the press it holds. More...

Macros

#define UI_KEYPAD_ENTRY_MAX   7
 Characters an entry holds, a minus sign included: "21.00" with room for a longer integer part, "-200".

Enumerations

enum  ui_key_t {
  UI_KEY_7 = 0 , UI_KEY_8 , UI_KEY_9 , UI_KEY_DEL ,
  UI_KEY_4 , UI_KEY_5 , UI_KEY_6 , UI_KEY_CLR ,
  UI_KEY_1 , UI_KEY_2 , UI_KEY_3 , UI_KEY_CANCEL ,
  UI_KEY_0 , UI_KEY_DOT , UI_KEY_OK , UI_KEY_SIGN ,
  UI_KEY_COUNT
}
 The keys, in reading order; OK spans the last two columns, or the last one on a signed keypad, where UI_KEY_SIGN takes the third. An unsigned keypad has no UI_KEY_SIGN: its rectangle is empty.
enum  ui_keypad_result_t { UI_KEYPAD_NONE = 0 , UI_KEYPAD_OK , UI_KEYPAD_CANCEL }
 What an event on the keypad came to. More...

Functions

void ui_keypad_open (ui_keypad_t *k, gfx_rect_t area, const char *title, const char *unit, float value, float min, float max, int decimals)
void ui_keypad_open_signed (ui_keypad_t *k, gfx_rect_t area, const char *title, const char *unit, float value, float min, float max, int decimals)
 Open k as ui_keypad_open() does, with the +/- key: for a value whose range reaches below 0 by more than a "not set" -1.
void ui_keypad_close (ui_keypad_t *k)
void ui_keypad_cancel_press (ui_keypad_t *k)
ui_keypad_result_t ui_keypad_event (ui_keypad_t *k, const touch_event_t *evt, float *out)
void ui_keypad_refuse (ui_keypad_t *k)
 Refuse the value the last OK handed back, after the caller has judged it by a rule of its own: the keypad opens again with the entry as typed and the range in the warning colour, as OK on a value outside the range leaves it.
void ui_keypad_refuse_why (ui_keypad_t *k, const char *reason)
 Refuse as ui_keypad_refuse() does, with the reason drawn in place of the range, in the warning colour, until the next key.
gfx_rect_t ui_keypad_key_rect (const ui_keypad_t *k, ui_key_t key)
 Where a key is drawn and hit: the grid ends 8px inside the area, or at UI_KEYS_FOOT (4px above the alert band, body coordinates) where the area reaches further.
const gfx_font_t * ui_keypad_digit_font (const ui_keypad_t *k)
 The face of the digits and the point: the largest of 20 x 36, 16 x 28, 12 x 24 and 10 x 20 whose cell fits a digit key with 6px on each side, else 8 x 16. Over SUPPLY's 620 x 476px a key is 145 x 76px and takes 20 x 36.
const gfx_font_t * ui_keypad_word_font (const ui_keypad_t *k)
 The face of the word keys (DEL, CLR, CANCEL, OK, +/-) in the language shown: the largest of 20 x 36, 16 x 28, 12 x 24 and 10 x 20, never larger than ui_keypad_digit_font(), in which every one of them fits its key with 6px each side, so the words of one keypad share one face; else 8 x 16.
const char * ui_keypad_range (const ui_keypad_t *k, char *buf, size_t n)
 The range line of the keypad's header: "3.30 to 21.00V", the unit joined to a symbol and after a space to a word (ui_unit_gap()), with the keypad's decimals. A pin word (ui_unit_is_prefix()) leads: "GPIO 0 to 54".
void ui_keypad_render (const ui_keypad_t *k, gfx_canvas_t *c)
 The whole keypad over its area: the title and the range in 10 x 20 (8 x 16 where they do not fit side by side), the entry in the 32 x 44 numerals with its unit in 12 x 24 (24 x 30 and 10 x 20 where those do not fit), the digits in ui_keypad_digit_font() and the words in ui_keypad_word_font(); the +/- key only on a signed keypad. Nothing while it is closed.

Detailed Description

A numeric keypad over part of a screen, for a value a slider is too coarse to place.

Digits, a decimal point, DEL and CLR, CANCEL and OK. The value is typed fresh: the entry starts empty with the current value shown faint behind it, and OK on an empty entry leaves the value as it was. OK on a value outside the range keeps the keypad open and names the range in the warning colour, so the caller is only ever handed a value inside it.

A keypad opened signed (ui_keypad_open_signed()) has a +/- key between the point and OK, which takes one column there: it puts a minus sign in front of the entry or takes it away. An unsigned keypad has no such key and its keys are where they always were.

Like the other widgets it owns nothing of the screen: the screen routes events to it while it is open and draws it last.

SPDX-License-Identifier: MIT

Enumeration Type Documentation

◆ ui_keypad_result_t

What an event on the keypad came to.

Enumerator
UI_KEYPAD_NONE 

still open, or the event was not its

UI_KEYPAD_OK 

closed with a value inside the range

UI_KEYPAD_CANCEL 

closed, the value as it was

Function Documentation

◆ ui_keypad_cancel_press()

void ui_keypad_cancel_press ( ui_keypad_t * k)

A press under way is dropped: the touch stream lost an event. The keypad stays open and what was typed stays typed.

◆ ui_keypad_digit_font()

const gfx_font_t * ui_keypad_digit_font ( const ui_keypad_t * k)

The face of the digits and the point: the largest of 20 x 36, 16 x 28, 12 x 24 and 10 x 20 whose cell fits a digit key with 6px on each side, else 8 x 16. Over SUPPLY's 620 x 476px a key is 145 x 76px and takes 20 x 36.

Parameters
kThe keypad, opened.
Returns
The face; 8 x 16 for NULL.

◆ ui_keypad_event()

ui_keypad_result_t ui_keypad_event ( ui_keypad_t * k,
const touch_event_t * evt,
float * out )

One touch event. A key acts on the release of the contact that pressed it, over the same key; a second contact is ignored while one is down. UI_KEYPAD_OK writes the value to out.

◆ ui_keypad_key_rect()

gfx_rect_t ui_keypad_key_rect ( const ui_keypad_t * k,
ui_key_t key )

Where a key is drawn and hit: the grid ends 8px inside the area, or at UI_KEYS_FOOT (4px above the alert band, body coordinates) where the area reaches further.

Parameters
kThe keypad.
keyThe key.
Returns
Its rectangle; an empty one for UI_KEY_SIGN on an unsigned keypad and for a key out of range.

◆ ui_keypad_open()

void ui_keypad_open ( ui_keypad_t * k,
gfx_rect_t area,
const char * title,
const char * unit,
float value,
float min,
float max,
int decimals )

Open over area for a value of min .. max, showing value.

◆ ui_keypad_open_signed()

void ui_keypad_open_signed ( ui_keypad_t * k,
gfx_rect_t area,
const char * title,
const char * unit,
float value,
float min,
float max,
int decimals )

Open k as ui_keypad_open() does, with the +/- key: for a value whose range reaches below 0 by more than a "not set" -1.

Parameters
kThe keypad.
areaWhere it is drawn and hit.
titleIts title.
unitThe value's unit.
valueThe value as it is, shown faint.
minThe range's lower end, below 0.
maxIts upper end.
decimalsThe digits it takes after the point.

◆ ui_keypad_range()

const char * ui_keypad_range ( const ui_keypad_t * k,
char * buf,
size_t n )

The range line of the keypad's header: "3.30 to 21.00V", the unit joined to a symbol and after a space to a word (ui_unit_gap()), with the keypad's decimals. A pin word (ui_unit_is_prefix()) leads: "GPIO 0 to 54".

Parameters
kThe keypad.
bufTakes the line.
nBytes at buf.
Returns
buf; "" for a NULL k, buf or a zero n.

◆ ui_keypad_refuse()

void ui_keypad_refuse ( ui_keypad_t * k)

Refuse the value the last OK handed back, after the caller has judged it by a rule of its own: the keypad opens again with the entry as typed and the range in the warning colour, as OK on a value outside the range leaves it.

Parameters
kThe keypad that returned UI_KEYPAD_OK.

◆ ui_keypad_refuse_why()

void ui_keypad_refuse_why ( ui_keypad_t * k,
const char * reason )

Refuse as ui_keypad_refuse() does, with the reason drawn in place of the range, in the warning colour, until the next key.

Parameters
kThe keypad that returned UI_KEYPAD_OK.
reasonWhy, one line; NULL or "" draws the range. A reason of 64 bytes or more is cut to at most 63 at the start of a UTF-8 character, so no character is drawn half.

◆ ui_keypad_render()

void ui_keypad_render ( const ui_keypad_t * k,
gfx_canvas_t * c )

The whole keypad over its area: the title and the range in 10 x 20 (8 x 16 where they do not fit side by side), the entry in the 32 x 44 numerals with its unit in 12 x 24 (24 x 30 and 10 x 20 where those do not fit), the digits in ui_keypad_digit_font() and the words in ui_keypad_word_font(); the +/- key only on a signed keypad. Nothing while it is closed.

Parameters
kThe keypad.
cThe canvas.

◆ ui_keypad_word_font()

const gfx_font_t * ui_keypad_word_font ( const ui_keypad_t * k)

The face of the word keys (DEL, CLR, CANCEL, OK, +/-) in the language shown: the largest of 20 x 36, 16 x 28, 12 x 24 and 10 x 20, never larger than ui_keypad_digit_font(), in which every one of them fits its key with 6px each side, so the words of one keypad share one face; else 8 x 16.

Parameters
kThe keypad, opened.
Returns
The face; 8 x 16 for NULL.