Sun, 13 Sep 2026 11:22:09 +0200
implement UI_INTEGER_EDITABLE type for editable tables (GTK)
| ui/gtk/list.c | file | annotate | diff | comparison | revisions |
--- a/ui/gtk/list.c Sun Sep 13 10:53:14 2026 +0200 +++ b/ui/gtk/list.c Sun Sep 13 11:22:09 2026 +0200 @@ -30,6 +30,7 @@ #include <stdlib.h> #include <string.h> #include <stdarg.h> +#include <limits.h> #include "../common/context.h" #include "../common/object.h" @@ -164,6 +165,7 @@ GtkEntry *entry; UiListView *listview; char *previous_value; + UiModelType type; int row; int col; } UiCellEntry; @@ -173,10 +175,21 @@ UiVar *var = data->listview->var; UiList *list = var ? var->value : NULL; const char *str = ENTRY_GET_TEXT(data->entry); - UiCellValue value; - value.string = str; - value.type = UI_STRING_EDITABLE; - if(data->listview->onsave(list, data->row, data->col, &value, data->listview->onsavedata)) { + + UiCellValue value = { .type = 0 }; + if(data->type == UI_INTEGER_EDITABLE) { + cxstring s = cx_str(str); + long long ivalue; + if(!cx_strtoll(s, &ivalue, 10)) { + value.i = ivalue; + value.type = UI_INTEGER_EDITABLE; + } + } else { + value.string = str; + value.type = UI_STRING_EDITABLE; + } + + if(value.type != 0 && data->listview->onsave(list, data->row, data->col, &value, data->listview->onsavedata)) { free(data->previous_value); data->previous_value = strdup(str); } else if(restore) { @@ -228,14 +241,20 @@ } else if(type == UI_ICON) { GtkWidget *image = gtk_image_new(); gtk_list_item_set_child(item, image); - } else if(type == UI_STRING_EDITABLE) { + } else if(type == UI_STRING_EDITABLE || type == UI_INTEGER_EDITABLE) { GtkWidget *textfield = gtk_entry_new(); gtk_widget_add_css_class(textfield, "ui-table-entry"); gtk_list_item_set_child(item, textfield); + if(type == UI_INTEGER_EDITABLE) { + gtk_entry_set_input_purpose(GTK_ENTRY(textfield), GTK_INPUT_PURPOSE_NUMBER); + + } + UiCellEntry *entry_data = malloc(sizeof(UiCellEntry)); entry_data->entry = GTK_ENTRY(textfield); entry_data->listview = NULL; + entry_data->type = type; entry_data->previous_value = NULL; entry_data->col = 0; entry_data->row = 0; @@ -402,6 +421,9 @@ break; } case UI_STRING_EDITABLE: { + // fallthrough + } + case UI_INTEGER_EDITABLE: { UiCellEntry *entry = g_object_get_data(G_OBJECT(child), "ui_entry_data"); if(entry) { entry->listview = col->listview; @@ -409,7 +431,6 @@ entry->col = datacolumn; entry->previous_value = strdup(data); } - ENTRY_SET_TEXT(child, data); break; } case UI_BOOL_EDITABLE: {