improve pathbar visuals (GTK) newapi

Thu, 03 Oct 2024 18:54:19 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 03 Oct 2024 18:54:19 +0200
branch
newapi
changeset 323
38cb8e3992e8
parent 322
22f6dadd9f46
child 324
ce13a778654a

improve pathbar visuals (GTK)

ui/gtk/text.c file | annotate | diff | comparison | revisions
ui/gtk/text.h file | annotate | diff | comparison | revisions
ui/gtk/toolkit.c file | annotate | diff | comparison | revisions
ui/gtk/toolkit.h file | annotate | diff | comparison | revisions
--- a/ui/gtk/text.c	Thu Oct 03 15:37:55 2024 +0200
+++ b/ui/gtk/text.c	Thu Oct 03 18:54:19 2024 +0200
@@ -705,15 +705,24 @@
     free(pathtf);
 }
 
-void ui_path_button_clicked(GtkWidget *widget, UiEventData *event) {
-    UiPathElm *elm = event->customdata;
+void ui_path_button_clicked(GtkWidget *widget, UiEventDataExt *event) {
+    UiPathTextField *pathtf = event->customdata1;
+    for(int i=0;i<event->value1;i++) {
+        if(i <= event->value0) {
+            gtk_widget_remove_css_class(pathtf->current_path_buttons[i], "pathbar-button-inactive");
+        } else {
+            gtk_widget_add_css_class(pathtf->current_path_buttons[i], "pathbar-button-inactive");
+        }
+    }
+    
+    UiPathElm *elm = event->customdata0;
     cxmutstr path = cx_strdup(cx_strn(elm->path, elm->path_len));
     UiEvent evt;
     evt.obj = event->obj;
     evt.window = evt.obj->window;
     evt.document = evt.obj->ctx->document;
     evt.eventdata = elm->path;
-    evt.intval = event->value;
+    evt.intval = event->value0;
     event->callback(&evt, event->userdata);
     free(path.ptr);
 }
@@ -734,6 +743,8 @@
     pathtf->current_path = strdup(full_path);
     
     ui_pathelm_destroy(pathtf->current_pathelms, pathtf->current_nelm);
+    free(pathtf->current_path_buttons);
+    pathtf->current_path_buttons = calloc(nelm, sizeof(GtkWidget*));
     pathtf->current_pathelms = path_elm;
     pathtf->current_nelm = nelm;
     
@@ -743,15 +754,19 @@
 static GtkWidget* ui_path_elm_button(UiPathTextField *pathtf, UiPathElm *elm, int i) {
     cxmutstr name = cx_strdup(cx_strn(elm->name, elm->name_len));
     GtkWidget *button = gtk_button_new_with_label(name.ptr);
+    pathtf->current_path_buttons[i] = button;
     free(name.ptr);
 
     if(pathtf->onactivate) {
-        UiEventData *eventdata = malloc(sizeof(UiEventData));
+        UiEventDataExt *eventdata = malloc(sizeof(UiEventDataExt));
+        memset(eventdata, 0, sizeof(UiEventDataExt));
         eventdata->callback = pathtf->onactivate;
         eventdata->userdata = pathtf->onactivatedata;
         eventdata->obj = pathtf->obj;
-        eventdata->customdata = elm;
-        eventdata->value = i;
+        eventdata->customdata0 = elm;
+        eventdata->customdata1 = pathtf;
+        eventdata->value0 = i;
+        eventdata->value1 = pathtf->current_nelm;        
 
         g_signal_connect(
                 button,
@@ -920,7 +935,9 @@
         gtk_box_append(GTK_BOX(pathtf->hbox), button);
         
         if(i+1 < pathtf->current_nelm && cx_strcmp(cx_strn(elm->name, elm->name_len), CX_STR("/"))) {
-            gtk_box_append(GTK_BOX(pathtf->hbox), gtk_label_new("/"));
+            GtkWidget *path_separator = gtk_label_new("/");
+            gtk_widget_add_css_class(path_separator, "pathbar-button-inactive");
+            gtk_box_append(GTK_BOX(pathtf->hbox), path_separator);
         }
     }
     gtk_stack_set_visible_child(GTK_STACK(pathtf->stack), pathtf->hbox);
--- a/ui/gtk/text.h	Thu Oct 03 15:37:55 2024 +0200
+++ b/ui/gtk/text.h	Thu Oct 03 18:54:19 2024 +0200
@@ -85,6 +85,7 @@
     
     char *current_path;
     UiPathElm *current_pathelms;
+    GtkWidget **current_path_buttons;
     size_t current_nelm;
     
     ui_pathelm_func getpathelm;
--- a/ui/gtk/toolkit.c	Thu Oct 03 15:37:55 2024 +0200
+++ b/ui/gtk/toolkit.c	Thu Oct 03 18:54:19 2024 +0200
@@ -341,7 +341,10 @@
 "  border-bottom-left-radius: 6px;"
 "  border-top-right-radius: 0px;"
 "  border-bottom-right-radius: 0px;"
-"}"
+"}\n"
+".pathbar-button-inactive {\n"
+"  color: alpha(currentColor, 0.5);"
+"}\n"
 ;
 
 #elif GTK_MAJOR_VERSION == 3
--- a/ui/gtk/toolkit.h	Thu Oct 03 15:37:55 2024 +0200
+++ b/ui/gtk/toolkit.h	Thu Oct 03 18:54:19 2024 +0200
@@ -112,6 +112,22 @@
     void        *customdata;
 } UiEventData;
 
+typedef struct UiEventDataExt {
+    UiObject    *obj;
+    ui_callback callback;
+    void        *userdata;
+    ui_callback callback2;
+    void        *userdata2;
+    int         value0;
+    int         value1;
+    int         value2;
+    int         value3;
+    void        *customdata0;
+    void        *customdata1;
+    void        *customdata2;
+    void        *customdata3;
+} UiEventDataExt;
+
 typedef struct UiVarEventData {
     UiObject    *obj;
     UiVar       *var;

mercurial