# HG changeset patch # User Olaf Wintermann # Date 1708108671 -3600 # Node ID 79dd183dd4cb7ac8866ca6f1f1edf25b23e59577 # Parent 37d5b49b1c9143df5e5035a0c51b5e2cad108926 port textfield to new API (GTK) diff -r 37d5b49b1c91 -r 79dd183dd4cb application/main.c --- a/application/main.c Fri Feb 16 19:24:52 2024 +0100 +++ b/application/main.c Fri Feb 16 19:37:51 2024 +0100 @@ -76,7 +76,7 @@ ui_togglebutton(obj, .label = "Toggle"); ui_checkbox(obj, .label = "Checkbox"); - ui_grid(obj, .fill = 1, .spacing = 5) { + ui_grid(obj, .fill = 1, .columnspacing = 5, .rowspacing = 5, .margin = 5) { ui_button(obj, .label = "cell1", .hexpand = TRUE); ui_button(obj, .label = "cell2"); ui_newline(obj); @@ -92,6 +92,9 @@ ui_progressbar(obj, .colspan = 2, .varname = "progress"); ui_set(doc->progress, 0.75); + ui_newline(obj); + + ui_textfield(obj, .value = doc->str1); } ui_show(obj); diff -r 37d5b49b1c91 -r 79dd183dd4cb ui/gtk/container.c --- a/ui/gtk/container.c Fri Feb 16 19:24:52 2024 +0100 +++ b/ui/gtk/container.c Fri Feb 16 19:37:51 2024 +0100 @@ -292,8 +292,8 @@ gtk_widget_set_margin_start(grid, args.margin); gtk_widget_set_margin_end(grid, args.margin); #else - gtk_widget_set_margin_left(grid, margin); - gtk_widget_set_margin_right(grid, margin); + gtk_widget_set_margin_left(grid, args.margin); + gtk_widget_set_margin_right(grid, args.margin); #endif gtk_widget_set_margin_top(grid, args.margin); gtk_widget_set_margin_bottom(grid, args.margin); diff -r 37d5b49b1c91 -r 79dd183dd4cb ui/gtk/text.c --- a/ui/gtk/text.c Fri Feb 16 19:24:52 2024 +0100 +++ b/ui/gtk/text.c Fri Feb 16 19:37:51 2024 +0100 @@ -534,9 +534,14 @@ } -static UIWIDGET create_textfield_var(UiObject *obj, int width, UiBool frameless, UiBool password, UiVar *var) { + + +static UIWIDGET create_textfield(UiObject *obj, UiBool frameless, UiBool password, UiTextFieldArgs args) { GtkWidget *textfield = gtk_entry_new(); + UiObject* current = uic_current_obj(obj); + UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_STRING); + UiTextField *uitext = malloc(sizeof(UiTextField)); uitext->ctx = obj->ctx; uitext->var = var; @@ -547,8 +552,8 @@ G_CALLBACK(ui_textfield_destroy), uitext); - if(width > 0) { - gtk_entry_set_width_chars(GTK_ENTRY(textfield), width); + if(args.width > 0) { + gtk_entry_set_width_chars(GTK_ENTRY(textfield), args.width); } if(frameless) { // TODO: gtk2legacy workaroud @@ -586,40 +591,25 @@ return textfield; } -static UIWIDGET create_textfield_nv(UiObject *obj, int width, UiBool frameless, UiBool password, char *varname) { - UiVar *var = uic_create_var(obj->ctx, varname, UI_VAR_STRING); - if(var) { - return create_textfield_var(obj, width, frameless, password, var); - } else { - // TODO: error - } - return NULL; +UIWIDGET ui_textfield_create(UiObject *obj, UiTextFieldArgs args) { + return create_textfield(obj, FALSE, FALSE, args); } -static UIWIDGET create_textfield(UiObject *obj, int width, UiBool frameless, UiBool password, UiString *value) { - UiVar *var = NULL; - if(value) { - var = malloc(sizeof(UiVar)); - var->value = value; - var->type = UI_VAR_SPECIAL; - var->from = NULL; - var->from_ctx = NULL; - } - return create_textfield_var(obj, width, frameless, password, var); +UIWIDGET ui_frameless_textfield_create(UiObject* obj, UiTextFieldArgs args) { + return create_textfield(obj, TRUE, FALSE, args); } +UIWIDGET ui_passwordfield_create(UiObject* obj, UiTextFieldArgs args) { + return create_textfield(obj, FALSE, TRUE, args); +} + + void ui_textfield_destroy(GtkWidget *object, UiTextField *textfield) { - if(textfield->var) { - UiText *text = textfield->var->value; - if(text->undomgr) { - ui_destroy_undomgr(text->undomgr); - } - ui_destroy_boundvar(textfield->ctx, textfield->var); - } free(textfield); } void ui_textfield_changed(GtkEditable *editable, UiTextField *textfield) { + // changed event is only registered, if the textfield->var != NULL UiString *value = textfield->var->value; if(value->observers) { UiEvent e; @@ -632,45 +622,6 @@ } } -UIWIDGET ui_textfield_deprecated(UiObject *obj, UiString *value) { - return create_textfield(obj, 0, FALSE, FALSE, value); -} - -UIWIDGET ui_textfield_nv(UiObject *obj, char *varname) { - return create_textfield_nv(obj, 0, FALSE, FALSE, varname); -} - -UIWIDGET ui_textfield_w(UiObject *obj, int width, UiString *value) { - return create_textfield(obj, width, FALSE, FALSE, value); -} - -UIWIDGET ui_textfield_wnv(UiObject *obj, int width, char *varname) { - return create_textfield_nv(obj, width, FALSE, FALSE, varname); -} - -UIWIDGET ui_frameless_textfield_deprecated(UiObject *obj, UiString *value) { - return create_textfield(obj, 0, TRUE, FALSE, value); -} - -UIWIDGET ui_frameless_textfield_nv(UiObject *obj, char *varname) { - return create_textfield_nv(obj, 0, TRUE, FALSE, varname); -} - -UIWIDGET ui_passwordfield_deprecated(UiObject *obj, UiString *value) { - return create_textfield(obj, 0, FALSE, TRUE, value); -} - -UIWIDGET ui_passwordfield_nv(UiObject *obj, char *varname) { - return create_textfield_nv(obj, 0, FALSE, TRUE, varname); -} - -UIWIDGET ui_passwordfield_w(UiObject *obj, int width, UiString *value) { - return create_textfield(obj, width, FALSE, TRUE, value); -} - -UIWIDGET ui_passwordfield_wnv(UiObject *obj, int width, char *varname) { - return create_textfield_nv(obj, width, FALSE, TRUE, varname); -} char* ui_textfield_get(UiString *str) { if(str->value.ptr) { diff -r 37d5b49b1c91 -r 79dd183dd4cb ui/ui/text.h --- a/ui/ui/text.h Fri Feb 16 19:24:52 2024 +0100 +++ b/ui/ui/text.h Fri Feb 16 19:37:51 2024 +0100 @@ -84,8 +84,8 @@ void* ondropsdata; } UiPathTextFieldArgs; -UIWIDGET ui_textarea(UiObject *obj, UiText *value); -UIWIDGET ui_textarea_nv(UiObject *obj, char *varname); +UIWIDGET ui_textarea_deprecated(UiObject *obj, UiText *value); +UIWIDGET ui_textarea_nv_deprecated(UiObject *obj, char *varname); UIWIDGET ui_textarea_gettextwidget(UIWIDGET textarea);