add UI_STRING_EDITABLE model type (GTK)

Sun, 28 Sep 2025 20:09:08 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 28 Sep 2025 20:09:08 +0200
changeset 777
622efebfab37
parent 776
867ff911492d
child 778
85b6cef7fcba

add UI_STRING_EDITABLE model type (GTK)

application/main.c file | annotate | diff | comparison | revisions
ui/gtk/list.c file | annotate | diff | comparison | revisions
ui/gtk/toolkit.c file | annotate | diff | comparison | revisions
ui/ui/tree.h file | annotate | diff | comparison | revisions
--- a/application/main.c	Wed Sep 24 21:33:33 2025 +0200
+++ b/application/main.c	Sun Sep 28 20:09:08 2025 +0200
@@ -459,11 +459,17 @@
         case 3: return ui_foldericon(16);
         case 4: return ui_fileicon(16);
         case 5: return "file";
+        case 6: return (void*)(intptr_t)123;
+        case 7: return "edit me";
+        case 8: return "edit me too";
     }
     return NULL;
 }
 
 UiBool table_getstyle(UiList *list, void *elm, int row, int col, void *userdata, UiTextStyle *style) {
+    if(col > 6) {
+        return FALSE;
+    }
     if(row < 2 && col != -1) {
         style->text_style = UI_TEXT_STYLE_BOLD;
         if(col == 2) {
@@ -649,7 +655,7 @@
             }
         }
         ui_tab(obj, "Tab 1") {
-            UiModel *model = ui_model(obj->ctx, UI_ICON_TEXT, "col1", UI_INTEGER, "col2", UI_ICON, "col3", UI_ICON_TEXT, "col4", UI_INTEGER, "col5", -1);
+            UiModel *model = ui_model(obj->ctx, UI_ICON_TEXT, "col1", UI_INTEGER, "col2", UI_ICON, "col3", UI_ICON_TEXT, "col4", UI_INTEGER, "col5", UI_STRING_EDITABLE, "edit6", UI_STRING_EDITABLE, "edit7", -1);
             model->columnsize[0] = -1;
             ui_table(obj, .model = model, .list = doc->list2, .colspan = 2, .fill = TRUE, .contextmenu = menubuilder, .multiselection = TRUE, .fill = TRUE,
                     .getvalue = table_getvalue, .getstyle = table_getstyle,
--- a/ui/gtk/list.c	Wed Sep 24 21:33:33 2025 +0200
+++ b/ui/gtk/list.c	Sun Sep 28 20:09:08 2025 +0200
@@ -159,6 +159,10 @@
     } else if(type == UI_ICON) {
         GtkWidget *image = gtk_image_new();
         gtk_list_item_set_child(item, image);
+    } else if(type == UI_STRING_EDITABLE) {
+        GtkWidget *textfield = gtk_entry_new();
+        gtk_widget_add_css_class(textfield, "ui-table-entry");
+        gtk_list_item_set_child(item, textfield);
     } else {
         GtkWidget *label = gtk_label_new(NULL);
         gtk_label_set_xalign(GTK_LABEL(label), 0);
@@ -293,6 +297,10 @@
             }
             break;
         }
+        case UI_STRING_EDITABLE: {
+            ENTRY_SET_TEXT(child, data);
+            break;
+        }
     }
     
     if(attributes != listview->current_row_attributes) {
--- a/ui/gtk/toolkit.c	Wed Sep 24 21:33:33 2025 +0200
+++ b/ui/gtk/toolkit.c	Sun Sep 28 20:09:08 2025 +0200
@@ -407,6 +407,11 @@
 ".ui-nopadding {"
 "  padding: 0;"
 "}\n"
+".ui-table-entry {"
+"  border: none;"
+"  box-shadow: none;"
+"  background: transparent;"
+"}\n"
 ;
 
 #elif GTK_MAJOR_VERSION == 3
--- a/ui/ui/tree.h	Wed Sep 24 21:33:33 2025 +0200
+++ b/ui/ui/tree.h	Sun Sep 28 20:09:08 2025 +0200
@@ -51,7 +51,8 @@
     UI_INTEGER,
     UI_ICON,
     UI_ICON_TEXT,
-    UI_ICON_TEXT_FREE
+    UI_ICON_TEXT_FREE,
+    UI_STRING_EDITABLE
 } UiModelType;
 
 struct UiModel {

mercurial