Edit
This page has been automatically translated using the Google Translate API services. We are working on improving texts. Thank you for your understanding and patience.
Functions
Edit* | edit_create (void) |
Edit* | edit_multiline (void) |
void | edit_OnFilter (...) |
void | edit_OnChange (...) |
void | edit_text (...) |
void | edit_font (...) |
void | edit_align (...) |
void | edit_passmode (...) |
void | edit_editable (...) |
void | edit_autoselect (...) |
void | edit_tooltip (...) |
void | edit_color (...) |
void | edit_color_focus (...) |
void | edit_bgcolor (...) |
void | edit_bgcolor_focus (...) |
void | edit_phtext (...) |
void | edit_phcolor (...) |
void | edit_phstyle (...) |
const char_t* | edit_get_text (...) |
EditBox are small text boxes with editing capabilities. Like the Label they are of uniform format: The typeface and colors will affect the entire text (Figure 1). They are usually used to edit fields in forms, normally restricted to a single line, although they can also be extended to several of them. To edit texts with multiple attributes use TextView. In Hello Edit and UpDown! you have an example of use.
- Use edit_createto create an edit box.
- Use edit_multiline to create a multi-line editing box.
- Use edit_passmode to hide the text of the control.
- Use edit_phtext to set a placeholder.
- Use edit_autoselect to automatically select all text.
1. Filter texts
Depending on the value we are editing, it may be necessary to validate the text entered. We can do this at the end of editing or while we are writing. For the first case we will use the event edit_OnChange which will call the handler when the control has lost focus on the keyboard (Figure 2). If we want to implement more elaborate filters, that correct the text while writing we will use the event edit_OnFilter. For example in (Listing 1) we have a simple filter that only allows numeric characters (Figure 3).
- Use edit_OnChange to validate the final text.
- Use edit_OnFilter to detect and correct every user click.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
static void OnFilter(void *noused, Event *e) { const EvText *params = event_params(e, EvText); EvTextFilter *result = event_result(e, EvTextFilter); uint32_t i = 0, j = 0; while (params->text[i] != '\0') { if (params->text[i] >= '0' && params->text[i] <= '9') { result->text[j] = params->text[i]; j += 1; } i += 1; } result->text[j] = '\0'; result->apply = TRUE; } ... edit_OnFilter(edit1, listener(NULL, i_OnFilter, void)); |
edit_create ()
Create a text edit control.
Edit* edit_create(void);
Return
The edit.
edit_multiline ()
Create a text editing control that allows multiple lines.
Edit* edit_multiline(void);
Return
The edit.
edit_OnFilter ()
Set a function to filter the text while editing.
void edit_OnFilter(Edit *edit, Listener *listener);
edit | The edit. |
listener | Callback function to be called after each key press. In EvTextFilter from event_result filtered text will be returned. |
Remarks
See Filter texts and GUI Events.
edit_OnChange ()
Set a function to detect when the text has changed.
void edit_OnChange(Edit *edit, Listener *listener);
edit | The edit. |
listener | Callback function to be called when the control loses focus on the keyboard, indicating the end of the edition. |
Remarks
See GUI Events.
edit_text ()
Set the edit control text.
void edit_text(Edit *edit, const char_t *text);
edit | The edit. |
text | UTF8 C-string terminated in null character |
edit_font ()
Set the font of the edit control.
void edit_font(Edit *edit, const Font *font);
edit | The edit. |
font | Font. |
edit_align ()
Set text alignment.
void edit_align(Edit *edit, const align_t align);
edit | The edit. |
align | Alignment. |
edit_passmode ()
Activate the password mode, which will hide the typed characters.
void edit_passmode(Edit *edit, const bool_t passmode);
edit | The edit. |
passmode | Enable or disable password mode. |
edit_editable ()
Enable or disable editing in the control.
void edit_editable(Edit *edit, const bool_t is_editable);
edit | The edit. |
is_editable |
|
edit_autoselect ()
Activate or deactivate auto-selection of text.
void edit_autoselect(Edit *edit, const bool_t autoselect);
edit | The edit. |
autoselect |
|
Remarks
Default FALSE
.
edit_tooltip ()
Assigns a tooltip to the edit control.
void edit_tooltip(Edit *edit, const char_t *text);
edit | The edit. |
text | UTF8 C-string terminated in null character |
edit_color ()
Set the text color.
void edit_color(Edit *edit, const color_t color);
edit | The edit. |
color | Text color. |
Remarks
RGB values may not be fully portable. See Colors.
edit_color_focus ()
Sets the color of the text, when the control has the keyboard focus.
void edit_color_focus(Edit *edit, const color_t color);
edit | The edit. |
color | Text color. |
Remarks
RGB values may not be fully portable. See Colors.
edit_bgcolor ()
Set the background color.
void edit_bgcolor(Edit *edit, const color_t color);
edit | The edit. |
color | Background color. |
Remarks
RGB values may not be fully portable. See Colors.
edit_bgcolor_focus ()
Sets the background color, when the control has keyboard focus.
void edit_bgcolor_focus(Edit *edit, const color_t color);
edit | The edit. |
color | Background color. |
Remarks
RGB values may not be fully portable. See Colors.
edit_phtext ()
Set an explanatory text for when the control is blank (placeholder).
void edit_phtext(Edit *edit, const char_t *text);
edit | The edit. |
text | UTF8 C-string terminated in null character |
edit_phcolor ()
Set the color of the placeholder text.
void edit_phcolor(Edit *edit, const color_t color);
edit | The edit. |
color | Text color. |
Remarks
RGB values may not be fully portable. See Colors.
edit_phstyle ()
Set the font style for the placeholder.
void edit_phstyle(Edit *edit, const uint32_t fstyle);
edit | The edit. |
fstyle | Combination of values of fstyle_t. |
edit_get_text ()
Get control text.
const char_t* edit_get_text(const Edit *edit);
edit | The edit. |
Return
UTF8 C-string terminated in null character '\0'
.