GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_widget_tbox.h
Go to the documentation of this file.
1//SPDX-License-Identifier: LGPL-2.0-or-later
2
3/*
4
5 Copyright (c) 2014-2024 Cyril Hrubis <metan@ucw.cz>
6
7 */
8
27#ifndef GP_WIDGET_TBOX_H
28#define GP_WIDGET_TBOX_H
29
30#include <utils/gp_seek.h>
31#include <utils/gp_utf_pos.h>
32
69
125
126#define GP_TBOX_FILTER_INT "0123456789"
127#define GP_TBOX_FILTER_HEX "0123456789abcdefABCDEF"
128
142 unsigned int len, unsigned int max_len,
143 const char *filter, enum gp_widget_tbox_type type);
144
154int gp_widget_tbox_printf(gp_widget *self, const char *fmt, ...)
155 __attribute__((format (printf, 2, 3)));
156
157
164void gp_widget_tbox_set(gp_widget *self, const char *str);
165
172
181
189static inline int gp_widget_tbox_is_empty(gp_widget *self)
190{
191 const char *text = gp_widget_tbox_text(self);
192
193 if (!text || !text[0])
194 return 1;
195
196 return 0;
197}
198
207
219void gp_widget_tbox_cursor_set(gp_widget *self, ssize_t off,
220 enum gp_seek_whence whence);
221
235void gp_widget_tbox_ins(gp_widget *self, ssize_t off,
236 enum gp_seek_whence whence, const char *str);
237
244static inline void gp_widget_tbox_append(gp_widget *self, const char *str)
245{
246 gp_widget_tbox_ins(self, 0, GP_SEEK_CUR, str);
247}
248
262void gp_widget_tbox_del(gp_widget *self, ssize_t off,
263 enum gp_seek_whence whence, size_t len);
264
275void gp_widget_tbox_sel_set(gp_widget *self, ssize_t off,
276 enum gp_seek_whence whence, size_t len);
277
286
293
300
309
317
325static inline int gp_widget_tbox_sel(gp_widget *self)
326{
327 return !!gp_widget_tbox_sel_len(self).bytes;
328}
329
341void gp_widget_tbox_sel_delim_set(gp_widget *self, const char *delim);
342
355
366void gp_widget_tbox_help_set(gp_widget *self, const char *help);
367
374
384void gp_widget_tbox_filter_set(gp_widget *self, const char *filter);
385
386#endif /* GP_WIDGET_TBOX_H */
Seek contants and transformations.
gp_seek_whence
Seek constants.
Definition gp_seek.h:24
An iterator for an UTF-8 string.
gp_widget_tattr
Text attribute flags.
void gp_widget_tbox_help_set(gp_widget *self, const char *help)
Sets textbox help text.
void gp_widget_tbox_ins(gp_widget *self, ssize_t off, enum gp_seek_whence whence, const char *str)
Inserts a string into a tbox.
void gp_widget_tbox_sel_all(gp_widget *self)
Selects whole textbox text.
void gp_widget_tbox_clear_on_input(gp_widget *self)
Sets one time flag that clears the text on next input event.
const char * gp_widget_tbox_text(gp_widget *self)
Returns a tbox string.
void gp_widget_tbox_sel_set(gp_widget *self, ssize_t off, enum gp_seek_whence whence, size_t len)
Sets selection.
void gp_widget_tbox_sel_delim_set(gp_widget *self, const char *delim)
Sets textbox selection delimiters.
static int gp_widget_tbox_is_empty(gp_widget *self)
Returns true if tbox is empty.
void gp_widget_tbox_sel_del(gp_widget *self)
Deletes selected characters.
void gp_widget_tbox_cursor_set(gp_widget *self, ssize_t off, enum gp_seek_whence whence)
Moves a cursor to a defined position.
static void gp_widget_tbox_append(gp_widget *self, const char *str)
Appends a string to the textbox.
int gp_widget_tbox_printf(gp_widget *self, const char *fmt,...) __attribute__((format(printf
A printf-like function to set a tbox text.
gp_widget * gp_widget_tbox_new(const char *text, gp_widget_tattr tattr, unsigned int len, unsigned int max_len, const char *filter, enum gp_widget_tbox_type type)
Create a tbox widget.
gp_widget_tbox_event_type
A gp_widget_event::sub_type for tbox widget events.
@ GP_WIDGET_TBOX_POST_FILTER
Emitted to filter out a character after text modified.
@ GP_WIDGET_TBOX_SET
Emitted when text box is modified.
@ GP_WIDGET_TBOX_EDIT
Emitted after text is entered.
@ GP_WIDGET_TBOX_PRE_FILTER
Emitted to filter out a character before text was modified.
@ GP_WIDGET_TBOX_TRIGGER
Emitted when enter is pressed.
@ GP_WIDGET_TBOX_PASTE
Emitted before text is pasted.
gp_utf8_pos gp_widget_tbox_cursor_get(gp_widget *self)
Returns current cursor postion.
gp_utf8_pos gp_widget_tbox_sel_off(gp_widget *self)
Returns selection offset, i.e. first character.
void gp_widget_tbox_type_set(gp_widget *self, enum gp_widget_tbox_type type)
Sets textbox type.
static int gp_widget_tbox_sel(gp_widget *self)
Returns true if text is selected.
void gp_widget_tbox_sel_clr(gp_widget *self)
Clears selection.
int void gp_widget_tbox_set(gp_widget *self, const char *str)
Sets a tbox text.
gp_utf8_pos gp_widget_tbox_sel_len(gp_widget *self)
Returns selection lenght.
void gp_widget_tbox_filter_set(gp_widget *self, const char *filter)
Sets a textbox filter string.
gp_widget_tbox_type
Text box type.
@ GP_WIDGET_TBOX_PATH
A filesystem path.
@ GP_WIDGET_TBOX_FILENAME
A file name.
@ GP_WIDGET_TBOX_HIDDEN
Hidden text, e.g. password.
@ GP_WIDGET_TBOX_NONE
No type, this is default.
@ GP_WIDGET_TBOX_URL
An URL.
void gp_widget_tbox_clear(gp_widget *self)
Clears the tbox text.
void gp_widget_tbox_del(gp_widget *self, ssize_t off, enum gp_seek_whence whence, size_t len)
Deletes a len characters from a tbox.
Position in an UTF-8 string.
Definition gp_utf_pos.h:25
size_t bytes
Definition gp_utf_pos.h:27
A widget base.
Definition gp_widget.h:28