Sun, 11 Jan 2026 14:59:15 +0100
extend textfield API (GTK)
| ui/gtk/text.c | file | annotate | diff | comparison | revisions | |
| ui/gtk/toolkit.h | file | annotate | diff | comparison | revisions | |
| ui/ui/text.h | file | annotate | diff | comparison | revisions |
--- a/ui/gtk/text.c Sun Jan 11 10:42:29 2026 +0100 +++ b/ui/gtk/text.c Sun Jan 11 14:59:15 2026 +0100 @@ -687,6 +687,41 @@ return create_textfield(obj, FALSE, TRUE, args); } +void ui_textfield_focus(UIWIDGET textfield) { + gtk_widget_grab_focus(textfield); +} + +void ui_textfield_focus_without_selecting(UIWIDGET textfield) { +#if GTK_CHECK_VERSION(3, 16, 0) + gtk_entry_grab_focus_without_selecting(GTK_ENTRY(textfield)); +#else + gtk_widget_grab_focus(textfield); +#endif +} + +void ui_textfield_set_selection(UIWIDGET textfield, int begin, int length) { + ENTRY_SET_SELECTION(textfield, begin, begin+length); +} + +void ui_textfield_select_all(UIWIDGET textfield) { + ENTRY_SET_SELECTION(textfield, 0, -1); +} + +void ui_textfield_set_editable(UIWIDGET textfield, UiBool editable) { + ENTRY_SET_EDITABLE(textfield, editable); +} + +UiBool ui_textfield_is_editable(UIWIDGET textfield) { + ENTRY_IS_EDITABLE(textfield); +} + +void ui_textfield_set_position(UIWIDGET textfield, int pos) { + ENTRY_SET_POSITION(textfield, pos); +} + +int ui_textfield_get_position(UIWIDGET textfield) { + return ENTRY_GET_POSITION(textfield); +} void ui_textfield_destroy(GtkWidget *object, UiTextField *textfield) { free(textfield);
--- a/ui/gtk/toolkit.h Sun Jan 11 10:42:29 2026 +0100 +++ b/ui/gtk/toolkit.h Sun Jan 11 14:59:15 2026 +0100 @@ -65,6 +65,11 @@ #define BOX_REMOVE(box, child) gtk_box_remove(GTK_BOX(box), child) #define ENTRY_SET_TEXT(entry, text) gtk_editable_set_text(GTK_EDITABLE(entry), text) #define ENTRY_GET_TEXT(entry) gtk_editable_get_text(GTK_EDITABLE(entry)) +#define ENTRY_SET_SELECTION(entry, begin, end) gtk_editable_select_region(GTK_EDITABLE(entry), begin, end) +#define ENTRY_SET_EDITABLE(entry, editable) gtk_editable_set_editable(GTK_EDITABLE(entry), editable) +#define ENTRY_IS_EDITABLE(entry) gtk_editable_get_editable(GTK_EDITABLE(entry)) +#define ENTRY_SET_POSITION(entry, pos) gtk_editable_set_position(GTK_EDITABLE(entry), pos) +#define ENTRY_GET_POSITION(entry) gtk_editable_get_position(GTK_EDITABLE(entry)) #define SCROLLEDWINDOW_NEW() gtk_scrolled_window_new() #define SCROLLEDWINDOW_SET_CHILD(sw, child) gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(sw), child) #define SCROLLEDWINDOW_GET_CHILD(sw) gtk_scrolled_window_get_child(GTK_SCROLLED_WINDOW(sw)) @@ -90,6 +95,11 @@ #define BOX_REMOVE(box, child) gtk_container_remove(GTK_CONTAINER(box), child) #define ENTRY_SET_TEXT(entry, text) gtk_entry_set_text(GTK_ENTRY(entry), text) #define ENTRY_GET_TEXT(entry) gtk_entry_get_text(GTK_ENTRY(entry)) +#define ENTRY_SET_SELECTION(entry, begin, end) gtk_editable_select_region(GTK_EDITABLE(entry), begin, end) +#define ENTRY_SET_EDITABLE(entry, editable) gtk_editable_set_editable(GTK_EDITABLE(entry), editable) +#define ENTRY_IS_EDITABLE(entry) gtk_editable_get_editable(GTK_EDITABLE(entry)) +#define ENTRY_SET_POSITION(entry, pos) gtk_editable_set_position(GTK_EDITABLE(entry), pos) +#define ENTRY_GET_POSITION(entry) gtk_editable_get_position(GTK_EDITABLE(entry)) #define SCROLLEDWINDOW_NEW() gtk_scrolled_window_new(NULL, NULL) #define SCROLLEDWINDOW_SET_CHILD(sw, child) gtk_container_add(GTK_CONTAINER(sw), child) #define SCROLLEDWINDOW_GET_CHILD(sw) gtk_bin_get_child(GTK_BIN(sw))
--- a/ui/ui/text.h Sun Jan 11 10:42:29 2026 +0100 +++ b/ui/ui/text.h Sun Jan 11 14:59:15 2026 +0100 @@ -155,6 +155,15 @@ UIEXPORT UIWIDGET ui_passwordfield_create(UiObject* obj, UiTextFieldArgs *args); UIEXPORT UIWIDGET ui_path_textfield_create(UiObject* obj, UiPathTextFieldArgs *args); + +UIEXPORT void ui_textfield_focus(UIWIDGET textfield); +UIEXPORT void ui_textfield_focus_without_selecting(UIWIDGET textfield); +UIEXPORT void ui_textfield_set_selection(UIWIDGET textfield, int begin, int length); +UIEXPORT void ui_textfield_select_all(UIWIDGET textfield); +UIEXPORT void ui_textfield_set_editable(UIWIDGET textfield, UiBool editable); +UIEXPORT UiBool ui_textfield_is_editable(UIWIDGET textfield); +UIEXPORT void ui_textfield_set_position(UIWIDGET textfield, int pos); +UIEXPORT int ui_textfield_get_position(UIWIDGET textfield); #ifdef __cplusplus }