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

The text keyboard. See ui_textkey.h. More...

#include "ui_textkey.h"
#include <stdio.h>
#include <string.h>
#include "card_tree.h"
#include "fm_name.h"
#include "ui_text.h"
#include "ui_theme.h"
#include "ui_widgets.h"

Macros

#define TK_PAD   8
 The room around the title, the text and the keys: 8px.
#define TK_HDR   32
 The title row: the 10 x 20 face and 6px above it.
#define TK_ENTRY_H   52
 The text: the 20 x 36 face and 8px above and below.
#define TK_GAP   6
 The gap between the text and the keys, and between keys.
#define TK_COLS   10
 The key grid: 10 columns ...
#define TK_ROWS   5
 ... and 5 rows, the last the bottom row of words.
#define TK_KEY_PAD   4
 The room a key keeps left and right of its label: 4px.
#define TK_FACES   ((int)(sizeof(k_faces) / sizeof(k_faces[0])))
 The count of k_faces.

Functions

void ui_textkey_open (ui_textkey_t *k, gfx_rect_t area, const char *title, const char *text, int max_len)
 Open over area on text.
void ui_textkey_open_search (ui_textkey_t *k, gfx_rect_t area, const char *title, const char *text, int max_len)
 Open for a search pattern; see the top of this file.
void ui_textkey_open_folder (ui_textkey_t *k, gfx_rect_t area, const char *title, const char *text)
 Open for a folder of the card; see the top of this file. Up to UI_TEXTKEY_MAX characters.
void ui_textkey_open_wifi (ui_textkey_t *k, gfx_rect_t area, const char *title, const char *text, bool secret)
 Open for a Wi-Fi password or network name; see the top of this file. Lower case first.
void ui_textkey_open_file (ui_textkey_t *k, gfx_rect_t area, const char *title, const char *text)
 Open for a file name; see the top of this file. Lower case first.
void ui_textkey_close (ui_textkey_t *k)
 Close, dropping a press under way.
void ui_textkey_cancel_press (ui_textkey_t *k)
 A press under way is dropped: the touch stream lost an event. What was typed stays typed.
const char * ui_textkey_label (int key)
 A key's label as a name keyboard shows it.
const char * ui_textkey_key_label (const ui_textkey_t *k, int key)
 A key's label as k shows it.
static char wifi_char (const ui_textkey_t *k, int key)
 The character a Wi-Fi key types.
gfx_rect_t ui_textkey_key_rect (const ui_textkey_t *k, int 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.
static void add (ui_textkey_t *k, char ch)
 ch after the text, while it is shorter than its most.
static ui_textkey_result_t press (ui_textkey_t *k, int key, char *out, size_t n)
 Key key pressed and released.
ui_textkey_result_t ui_textkey_event (ui_textkey_t *k, const touch_event_t *evt, char *out, size_t n)
 One touch event.
static const char * folder_why (uint8_t why)
 Why a folder was refused, in the words of its line.
static const char * file_why (uint8_t why)
 Why a file name was refused, in the words of its line.
static const gfx_font_t * entry_face (gfx_rect_t box)
 The face of the text field: 20 x 36 when UI_TEXTKEY_MAX characters and the caret fit box with 10px each side and the face's height fits it, else 16 x 28. A Wi-Fi text longer than the field shows its end in either.
static bool is_word (const ui_textkey_t *k, int key)
 Whether key key of k is a word rather than one character: the bottom row, DEL, and the Wi-Fi layer keys (the capitals key types "}" on the marks layer, a character there).
static int char_face (const ui_textkey_t *k)
 Where the character keys' face is in k_faces: the first whose cell fits a character key with TK_KEY_PAD on each of its 4 sides.
const gfx_font_t * ui_textkey_char_font (const ui_textkey_t *k)
 The face of the character keys: the largest of 20 x 36, 16 x 28, 12 x 24 and 10 x 20 whose cell fits a character key with 4px on each side, else 8 x 16. Over the WI-FI screen's 1008 x 484px a key is 93 x 71px and takes 20 x 36.
const gfx_font_t * ui_textkey_word_font (const ui_textkey_t *k)
 The face of the word keys (the bottom row, DEL, and the Wi-Fi layer keys) in the language shown: the largest of 20 x 36, 16 x 28, 12 x 24 and 10 x 20, never larger than ui_textkey_char_font(), in which every one of them fits its key with 4px each side, in every state it can show (SHOW and HIDE, ABC, abc and #+=), so the words of one keyboard share one face and a press does not change it; else 8 x 16.
void ui_textkey_render (const ui_textkey_t *k, gfx_canvas_t *c)
 The whole keyboard over its area: the title and the count in 10 x 20 (8 x 16 where they do not fit side by side), the text in 20 x 36 (16 x 28 in a field narrower than UI_TEXTKEY_MAX characters and the caret), the character keys in ui_textkey_char_font() and the word keys in ui_textkey_word_font(). Nothing while it is closed.

Variables

static const char k_chars [UI_TEXTKEY_CHARS+1]
 The character rows, in reading order; the last is DEL.
static const char k_wifi [3][UI_TEXTKEY_CHARS+1]
 The Wi-Fi layers. Key UI_TK_SHIFT and key UI_TK_LAYER switch them and type nothing; a blank ("\0") types nothing either. The marks are the 32 printable ASCII characters that are neither a letter, a digit nor a space, in code order.
static const ui_text_id_t k_bottom_tx []
 The bottom row's texts: SPACE and CANCEL are translated.
static const char *const k_bottom [] = { NULL, "CLR", NULL, "OK" }
 The bottom row's legends: CLR and OK, the same in every language.
static const int k_bottom_span [] = { 4, 2, 2, 2 }
 How many columns each bottom key spans, for a name.
static const int k_search_span [] = { 3, 2, 3, 2 }
 How many columns each bottom key spans, for a search and a Wi-Fi name.
static const int k_secret_col [] = { 0, 4, 6, 8, 2 }
 A password's bottom row, in key order SPACE, CLR, CANCEL, OK, SHOW: where each starts, two columns each, SHOW second from the left.
static const gfx_font_t *const k_faces []
 The key faces, largest first: 20 x 36, 16 x 28, 12 x 24, 10 x 20 and 8 x 16.

Detailed Description

The text keyboard. See ui_textkey.h.

SPDX-License-Identifier: MIT

Function Documentation

◆ add()

void add ( ui_textkey_t * k,
char ch )
static

ch after the text, while it is shorter than its most.

Parameters
kThe keyboard.
chThe character.

◆ char_face()

int char_face ( const ui_textkey_t * k)
static

Where the character keys' face is in k_faces: the first whose cell fits a character key with TK_KEY_PAD on each of its 4 sides.

Parameters
kThe keyboard.
Returns
The index; the last, 8 x 16, when none fits.

◆ entry_face()

const gfx_font_t * entry_face ( gfx_rect_t box)
static

The face of the text field: 20 x 36 when UI_TEXTKEY_MAX characters and the caret fit box with 10px each side and the face's height fits it, else 16 x 28. A Wi-Fi text longer than the field shows its end in either.

Parameters
boxThe field.
Returns
The face.

◆ file_why()

const char * file_why ( uint8_t why)
static

Why a file name was refused, in the words of its line.

Parameters
whyAn fm_name_t.
Returns
The line.

◆ folder_why()

const char * folder_why ( uint8_t why)
static

Why a folder was refused, in the words of its line.

Parameters
whyA card_folder_t.
Returns
The line.

◆ is_word()

bool is_word ( const ui_textkey_t * k,
int key )
static

Whether key key of k is a word rather than one character: the bottom row, DEL, and the Wi-Fi layer keys (the capitals key types "}" on the marks layer, a character there).

Parameters
kThe keyboard.
keyThe key.
Returns
True for a word key.

◆ press()

ui_textkey_result_t press ( ui_textkey_t * k,
int key,
char * out,
size_t n )
static

Key key pressed and released.

Parameters
kThe keyboard.
keyThe key.
outWhere OK writes what it takes.
nThe bytes at out.
Returns
UI_TEXTKEY_OK or UI_TEXTKEY_CANCELLED when it closed, UI_TEXTKEY_NONE otherwise, a refusal included.

◆ ui_textkey_cancel_press()

void ui_textkey_cancel_press ( ui_textkey_t * k)

A press under way is dropped: the touch stream lost an event. What was typed stays typed.

Parameters
kThe keyboard; NULL does nothing.

◆ ui_textkey_char_font()

const gfx_font_t * ui_textkey_char_font ( const ui_textkey_t * k)

The face of the character keys: the largest of 20 x 36, 16 x 28, 12 x 24 and 10 x 20 whose cell fits a character key with 4px on each side, else 8 x 16. Over the WI-FI screen's 1008 x 484px a key is 93 x 71px and takes 20 x 36.

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

◆ ui_textkey_close()

void ui_textkey_close ( ui_textkey_t * k)

Close, dropping a press under way.

Parameters
kThe keyboard; NULL does nothing.

◆ ui_textkey_event()

ui_textkey_result_t ui_textkey_event ( ui_textkey_t * k,
const touch_event_t * evt,
char * out,
size_t n )

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.

Parameters
kThe keyboard.
evtThe event, in the keyboard's coordinates.
outWhere OK writes the name, ends trimmed; a search's text as typed; a folder in upper case, as card_folder_check() writes it.
nThe bytes at out: CARD_DIR_MAX or more for a folder.
Returns
UI_TEXTKEY_OK or UI_TEXTKEY_CANCELLED when it closed, UI_TEXTKEY_NONE otherwise and for a NULL or closed keyboard.

◆ ui_textkey_key_label()

const char * ui_textkey_key_label ( const ui_textkey_t * k,
int key )

A key's label as k shows it.

Parameters
kThe keyboard.
keyThe key.
Returns
"*" for UI_TK_MARK in a search, "/" for UI_TK_DOT for a folder, the layer's character on a Wi-Fi keyboard, "" for a blank key, else ui_textkey_label().

◆ ui_textkey_key_rect()

gfx_rect_t ui_textkey_key_rect ( const ui_textkey_t * k,
int 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 keyboard.
keyThe key: 0 to UI_TK_OK, or UI_TK_SHOW on a password.
Returns
Its rectangle; zero size for one out of range.

◆ ui_textkey_label()

const char * ui_textkey_label ( int key)

A key's label as a name keyboard shows it.

Parameters
keyThe key.
Returns
The label, or "" for one out of range.

◆ ui_textkey_open()

void ui_textkey_open ( ui_textkey_t * k,
gfx_rect_t area,
const char * title,
const char * text,
int max_len )

Open over area on text.

Parameters
kThe keyboard; NULL does nothing.
areaWhere it draws and takes presses.
titleWhat is typed, top left.
textThe text it starts with, cut to max_len.
max_lenThe most characters it takes; 0, less, or more than UI_TEXTKEY_MAX is UI_TEXTKEY_MAX.

◆ ui_textkey_open_file()

void ui_textkey_open_file ( ui_textkey_t * k,
gfx_rect_t area,
const char * title,
const char * text )

Open for a file name; see the top of this file. Lower case first.

Parameters
kThe keyboard; NULL does nothing.
areaWhere it draws.
titleWhat is typed.
textThe name it starts with, cut to FM_NAME_MAX bytes between two characters.

◆ ui_textkey_open_folder()

void ui_textkey_open_folder ( ui_textkey_t * k,
gfx_rect_t area,
const char * title,
const char * text )

Open for a folder of the card; see the top of this file. Up to UI_TEXTKEY_MAX characters.

Parameters
kThe keyboard; NULL does nothing.
areaWhere it draws.
titleThe setting's name.
textThe folder in force.

◆ ui_textkey_open_search()

void ui_textkey_open_search ( ui_textkey_t * k,
gfx_rect_t area,
const char * title,
const char * text,
int max_len )

Open for a search pattern; see the top of this file.

Parameters
kThe keyboard; NULL does nothing.
areaWhere it draws.
titleWhat is searched for.
textThe pattern it starts with.
max_lenThe most characters, as ui_textkey_open() takes it.

◆ ui_textkey_open_wifi()

void ui_textkey_open_wifi ( ui_textkey_t * k,
gfx_rect_t area,
const char * title,
const char * text,
bool secret )

Open for a Wi-Fi password or network name; see the top of this file. Lower case first.

Parameters
kThe keyboard; NULL does nothing.
areaWhere it draws.
titleWhat is typed.
textThe text it starts with.
secretA password: masked, 8 to 63 characters; else a name of 1 to 32 bytes.

◆ ui_textkey_render()

void ui_textkey_render ( const ui_textkey_t * k,
gfx_canvas_t * c )

The whole keyboard over its area: the title and the count in 10 x 20 (8 x 16 where they do not fit side by side), the text in 20 x 36 (16 x 28 in a field narrower than UI_TEXTKEY_MAX characters and the caret), the character keys in ui_textkey_char_font() and the word keys in ui_textkey_word_font(). Nothing while it is closed.

Parameters
kThe keyboard.
cCanvas.

◆ ui_textkey_word_font()

const gfx_font_t * ui_textkey_word_font ( const ui_textkey_t * k)

The face of the word keys (the bottom row, DEL, and the Wi-Fi layer keys) in the language shown: the largest of 20 x 36, 16 x 28, 12 x 24 and 10 x 20, never larger than ui_textkey_char_font(), in which every one of them fits its key with 4px each side, in every state it can show (SHOW and HIDE, ABC, abc and #+=), so the words of one keyboard share one face and a press does not change it; else 8 x 16.

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

◆ wifi_char()

char wifi_char ( const ui_textkey_t * k,
int key )
static

The character a Wi-Fi key types.

Parameters
kThe keyboard.
keyThe key.
Returns
The character of the layer shown, or 0 for a layer key, a blank and DEL.

Variable Documentation

◆ k_bottom_tx

const ui_text_id_t k_bottom_tx[]
static
Initial value:
= { TX_SPACE, TX_COUNT, TX_CANCEL,
TX_COUNT }

The bottom row's texts: SPACE and CANCEL are translated.

◆ k_chars

const char k_chars[UI_TEXTKEY_CHARS+1]
static
Initial value:
=
"1234567890" "QWERTYUIOP" "ASDFGHJKL-" "ZXCVBNM_."

The character rows, in reading order; the last is DEL.

◆ k_faces

const gfx_font_t* const k_faces[]
static
Initial value:
= {
}
const gfx_font_t gfx_font_16x28
const gfx_font_t gfx_font_12x24
12x24 monospaced, ASCII 0x20..0x7E and the German letters. Cap height 15px. Prose: help text,...
const gfx_font_t gfx_font_20x36
20x36 monospaced, ASCII 0x20..0x7E and the German letters. Cap height 23px. Headings,...
const gfx_font_t gfx_font_10x20
10x20 monospaced, ASCII 0x20..0x7E and the German letters. Cap height 12px. Labels,...
const gfx_font_t gfx_font_8x16

The key faces, largest first: 20 x 36, 16 x 28, 12 x 24, 10 x 20 and 8 x 16.

◆ k_wifi

const char k_wifi[3][UI_TEXTKEY_CHARS+1]
static
Initial value:
= {
"1234567890" "qwertyuiop" "asdfghjkl-" " zxcvbnm ",
"1234567890" "QWERTYUIOP" "ASDFGHJKL-" " ZXCVBNM ",
"!\"#$%&'()*" "+,-./:;<=>" "?@[\\]^_`{|" "}~ ",
}

The Wi-Fi layers. Key UI_TK_SHIFT and key UI_TK_LAYER switch them and type nothing; a blank ("\0") types nothing either. The marks are the 32 printable ASCII characters that are neither a letter, a digit nor a space, in code order.