The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
text_field.c File Reference

idunn: a one-line text field: a slightly inset well with a placeholder, a blinking caret, selection with the mouse and the keys, the clipboard, and scrolling when the text is longer than the field. More...

#include "idunn_internal.h"
#include <stdlib.h>
#include <string.h>

Macros

#define HEIGHT   32
#define PILL_H   40
#define PADDING   12
#define PLAIN_PAD   3
#define ICON_SIZE   16
#define ICON_GAP   8
#define WIDTH   240
#define BLINK_MS   500
#define BULLET   "\xe2\x80\xa2"
#define BULLET_BYTES   3
#define SECRET_MAX   128

Functions

void idunn_draw_well (idunn_widget_t *w, gfx_buffer_t *buf)
 the well of a text input: fill, inset shadow, border and ring (text_field.c)
idunn_widget_t * idunn_text_field (const char *placeholder)
 a one-line text field, 32 pixels high.
const char * idunn_text_field_text (const idunn_widget_t *field)
 the text (UTF-8); valid until the text changes
void idunn_text_field_set_text (idunn_widget_t *field, const char *text)
void idunn_text_field_set_icon (idunn_widget_t *field, const char *icon)
 an icon (a Lucide name) at the start, as in a search field
void idunn_text_field_set_plain (idunn_widget_t *field, bool plain)
 select bytes start to end (the caret at end); typing replaces them.
void idunn_text_field_set_pill (idunn_widget_t *field, bool pill)
 a pill: round ends, see-through (over a picture, as on a login screen), no border, the text in the middle while it fits.
void idunn_text_field_set_secret (idunn_widget_t *field, bool secret)
 a password field: a bullet for each character, and no Copy or Cut
int32_t idunn_text_field_text_width (idunn_widget_t *field)
 the width of the field's text in pixels (0 before it is in a window)
void idunn_text_field_on_change (idunn_widget_t *field, idunn_callback_t on_change, void *data)
 on_change after every change of the text; on_submit on Enter
void idunn_text_field_on_blur (idunn_widget_t *field, idunn_callback_t on_blur, void *data)
 on_blur when the field loses the keyboard
void idunn_text_field_on_submit (idunn_widget_t *field, idunn_callback_t on_submit, void *data)
void idunn_text_field_select (idunn_widget_t *field, size_t start, size_t end)

Detailed Description

idunn: a one-line text field: a slightly inset well with a placeholder, a blinking caret, selection with the mouse and the keys, the clipboard, and scrolling when the text is longer than the field.

Macro Definition Documentation

◆ HEIGHT

#define HEIGHT   32

◆ PILL_H

#define PILL_H   40

◆ PADDING

#define PADDING   12

◆ PLAIN_PAD

#define PLAIN_PAD   3

◆ ICON_SIZE

#define ICON_SIZE   16

◆ ICON_GAP

#define ICON_GAP   8

◆ WIDTH

#define WIDTH   240

◆ BLINK_MS

#define BLINK_MS   500

◆ BULLET

#define BULLET   "\xe2\x80\xa2"

◆ BULLET_BYTES

#define BULLET_BYTES   3

◆ SECRET_MAX

#define SECRET_MAX   128

Function Documentation

◆ idunn_draw_well()

void idunn_draw_well ( idunn_widget_t * w,
gfx_buffer_t * buf )

the well of a text input: fill, inset shadow, border and ring (text_field.c)

◆ idunn_text_field()

idunn_widget_t * idunn_text_field ( const char * placeholder)

a one-line text field, 32 pixels high.

Parameters
placeholderthe muted text it shows when it is empty, or NULL.

◆ idunn_text_field_text()

const char * idunn_text_field_text ( const idunn_widget_t * field)

the text (UTF-8); valid until the text changes

◆ idunn_text_field_set_text()

void idunn_text_field_set_text ( idunn_widget_t * field,
const char * text )

◆ idunn_text_field_set_icon()

void idunn_text_field_set_icon ( idunn_widget_t * field,
const char * icon )

an icon (a Lucide name) at the start, as in a search field

◆ idunn_text_field_set_plain()

void idunn_text_field_set_plain ( idunn_widget_t * field,
bool plain )

select bytes start to end (the caret at end); typing replaces them.

(size_t)-1 is the end of the text. a plain field: a thin box around the text, with little padding and no ring (a name that is changed in place, as in a file list).

◆ idunn_text_field_set_pill()

void idunn_text_field_set_pill ( idunn_widget_t * field,
bool pill )

a pill: round ends, see-through (over a picture, as on a login screen), no border, the text in the middle while it fits.

◆ idunn_text_field_set_secret()

void idunn_text_field_set_secret ( idunn_widget_t * field,
bool secret )

a password field: a bullet for each character, and no Copy or Cut

◆ idunn_text_field_text_width()

int32_t idunn_text_field_text_width ( idunn_widget_t * field)

the width of the field's text in pixels (0 before it is in a window)

◆ idunn_text_field_on_change()

void idunn_text_field_on_change ( idunn_widget_t * field,
idunn_callback_t on_change,
void * data )

on_change after every change of the text; on_submit on Enter

◆ idunn_text_field_on_blur()

void idunn_text_field_on_blur ( idunn_widget_t * field,
idunn_callback_t on_blur,
void * data )

on_blur when the field loses the keyboard

◆ idunn_text_field_on_submit()

void idunn_text_field_on_submit ( idunn_widget_t * field,
idunn_callback_t on_submit,
void * data )

◆ idunn_text_field_select()

void idunn_text_field_select ( idunn_widget_t * field,
size_t start,
size_t end )