add more label styles (GTK) newapi

Sun, 27 Oct 2024 10:33:24 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 27 Oct 2024 10:33:24 +0100
branch
newapi
changeset 358
98b26a19cbeb
parent 357
3f2a84587e4e
child 359
c51e58359db8

add more label styles (GTK)

application/main.c file | annotate | diff | comparison | revisions
ui/gtk/display.c file | annotate | diff | comparison | revisions
ui/gtk/toolkit.c file | annotate | diff | comparison | revisions
ui/ui/display.h file | annotate | diff | comparison | revisions
--- a/application/main.c	Sun Oct 27 10:23:02 2024 +0100
+++ b/application/main.c	Sun Oct 27 10:33:24 2024 +0100
@@ -250,7 +250,7 @@
                 ui_newline(obj);
 
                 ui_label(obj, .label = "Label Col 1", .align = UI_ALIGN_LEFT);
-                ui_label(obj, .label = "Label Col 2", .type = UI_LABEL_STYLE_HEADING, .align = UI_ALIGN_RIGHT);
+                ui_label(obj, .label = "Label Col 2", .style = UI_LABEL_STYLE_TITLE, .align = UI_ALIGN_RIGHT);
                 ui_newline(obj);
 
                 ui_spinner(obj, .step = 5);
@@ -315,8 +315,10 @@
                 }
                 
                 ui_frame(obj, .label = "Frame", .margin = 10, .spacing = 10) {
-                    ui_label(obj, .label = "Test");
-                    ui_button(obj, .label = "Button");
+                    ui_label(obj, .label = "Title", .style = UI_LABEL_STYLE_TITLE);
+                    ui_label(obj, .label = "Sub-Title", .style = UI_LABEL_STYLE_SUBTITLE);
+                    ui_label(obj, .label = "Dim Label", .style = UI_LABEL_STYLE_DIM);
+                    ui_label(obj, .label = "No Style");
                 }
                 
                 for(int i=0;i<100;i++) {
--- a/ui/gtk/display.c	Sun Oct 27 10:23:02 2024 +0100
+++ b/ui/gtk/display.c	Sun Oct 27 10:33:24 2024 +0100
@@ -51,24 +51,41 @@
     
     const char *css_class = NULL;
     char *markup = NULL;
-#if GTK_MAJOR_VERSION < 3
-    switch(args.type && args.label) {
-        case UI_LABEL_STYLE_DEFAULT: break;
-        case UI_LABEL_STYLE_HEADING: {
-            cxmutstr m = cx_asprintf("<b>%s</b>", args.label);
-            markup = m.ptr;
-            args.label = NULL;
-        }
+    if(args.label) {
+        #if GTK_MAJOR_VERSION < 3
+            switch(args.style) {
+                case UI_LABEL_STYLE_DEFAULT: break;
+                case UI_LABEL_STYLE_TITLE: {
+                    cxmutstr m = cx_asprintf("<b>%s</b>", args.label);
+                    markup = m.ptr;
+                    args.label = NULL;
+                }
+                case UI_LABEL_STYLE_SUBTITLE: {
+                    break;
+                }
+                case UI_LABEL_STYLE_DIM: {
+                    break;
+                }
+            }
+#       else
+            switch(args.style) {
+                case UI_LABEL_STYLE_DEFAULT: break;
+                case UI_LABEL_STYLE_TITLE: {
+                    css_class = "ui_label_title";
+                    break;
+                }
+                case UI_LABEL_STYLE_SUBTITLE: {
+                    css_class = "subtitle";
+                    break;
+                }
+                case UI_LABEL_STYLE_DIM: {
+                    css_class = "dim-label";
+                    break;
+                }
+            }
+#       endif
     }
-#else
-    switch(args.type && args.label) {
-        case UI_LABEL_STYLE_DEFAULT: break;
-        case UI_LABEL_STYLE_HEADING: {
-            css_class = "ui_label_heading";
-            break;
-        }
-    }
-#endif
+
     
     GtkWidget *widget = gtk_label_new(args.label);
     if(markup) {
--- a/ui/gtk/toolkit.c	Sun Oct 27 10:23:02 2024 +0100
+++ b/ui/gtk/toolkit.c	Sun Oct 27 10:33:24 2024 +0100
@@ -351,7 +351,7 @@
 ".ui_test {\n"
 "  background-color: red;\n"
 "}\n"
-".ui_label_heading {\n"
+".ui_label_title {\n"
 "  font-weight: bold;\n"
 "}\n"
 ;
@@ -366,7 +366,7 @@
 ".ui_test {\n"
 "  background-color: red;\n"
 "}\n"
-".ui_label_heading {\n"
+".ui_label_title {\n"
 "  font-weight: bold;\n"
 "}\n"
 ;
--- a/ui/ui/display.h	Sun Oct 27 10:23:02 2024 +0100
+++ b/ui/ui/display.h	Sun Oct 27 10:33:24 2024 +0100
@@ -50,7 +50,9 @@
 
 enum UiLabelStyle {
     UI_LABEL_STYLE_DEFAULT = 0,
-    UI_LABEL_STYLE_HEADING
+    UI_LABEL_STYLE_TITLE,
+    UI_LABEL_STYLE_SUBTITLE,
+    UI_LABEL_STYLE_DIM
 };
 
 typedef enum UiLabelStyle UiLabelStyle;
@@ -64,7 +66,7 @@
 
     const char* label;
     UiAlignment align;
-    UiLabelType type;
+    UiLabelStyle style;
     UiString* value;
     const char* varname;
 } UiLabelArgs;

mercurial