replace hard coded icon names with macros

Sun, 09 Jun 2024 16:06:40 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 09 Jun 2024 16:06:40 +0200
changeset 33
cdeb0dc47ef5
parent 32
e5f4d8af567e
child 34
98e041f2f9a2

replace hard coded icon names with macros

application/application.c file | annotate | diff | comparison | revisions
application/window.c file | annotate | diff | comparison | revisions
ui/ui/icons.h file | annotate | diff | comparison | revisions
ui/ui/ui.h file | annotate | diff | comparison | revisions
--- a/application/application.c	Sun Jun 09 15:43:08 2024 +0200
+++ b/application/application.c	Sun Jun 09 16:06:40 2024 +0200
@@ -75,42 +75,41 @@
 }
 
 void application_create_menu(void) {
-	// menu
+    // menu
 
 
-	// toolbar
-	ui_toolbar_item("Home", .icon = "Home");
-	ui_toolbar_item("NewWindow", .icon = "NewWindow", .onclick = action_window_new);
-	ui_toolbar_item("Refresh", .icon = "Refresh", .onclick = action_refresh);
+    // toolbar
+    ui_toolbar_item("Home", .icon = UI_ICON_HOME);
+    ui_toolbar_item("NewWindow", .icon = UI_ICON_NEW_WINDOW, .onclick = action_window_new);
+    ui_toolbar_item("Refresh", .icon = UI_ICON_REFRESH, .onclick = action_refresh);
     ui_toolbar_menu("Repo", .label = "Repository") {
         ui_menu_itemlist(.varname = "repolist", .getvalue = davrepo_getname, .onselect = action_repo_selected);
     }
-	ui_toolbar_item("NewFolder", .icon = "NewFolder", .onclick = action_mkcol);
-	ui_toolbar_item("NewFile", .icon = "Add", .onclick = action_newfile);
-	ui_toolbar_item("Upload", .label = "Upload", .icon = "Upload", .onclick = action_upload_file);
-	ui_toolbar_item("Download", .icon = "SaveLocal", .onclick = action_download);
-	ui_toolbar_item("Remove", .icon = "Delete", .onclick = action_delete );
-	ui_toolbar_toggleitem("LocalBrowser", .icon = "DockLeft", .label = "Local Browser");
-	ui_toolbar_toggleitem("PreviewPane", .icon = "DockRight");
+    ui_toolbar_item("NewFolder", .icon = UI_ICON_NEW_FOLDER, .onclick = action_mkcol);
+    ui_toolbar_item("NewFile", .icon = UI_ICON_ADD, .onclick = action_newfile);
+    ui_toolbar_item("Upload", .label = "Upload", .icon = UI_ICON_UPLOAD, .onclick = action_upload_file);
+    ui_toolbar_item("Download", .icon = UI_ICON_SAVE_LOCAL, .onclick = action_download);
+    ui_toolbar_item("Remove", .icon = UI_ICON_DELETE, .onclick = action_delete );
+    ui_toolbar_toggleitem("LocalBrowser", .icon = UI_ICON_DOCK_LEFT, .label = "Local Browser");
+    ui_toolbar_toggleitem("PreviewPane", .icon = UI_ICON_DOCK_RIGHT);
 
-	ui_toolbar_appmenu() {
-		ui_menuitem("TODO", NULL);
-	}
-
+    ui_toolbar_appmenu() {
+        ui_menuitem("TODO", NULL);
+    }
 
-	ui_toolbar_add_default("Home", UI_TOOLBAR_LEFT);
-	ui_toolbar_add_default("NewWindow", UI_TOOLBAR_LEFT);
-	ui_toolbar_add_default("Refresh", UI_TOOLBAR_LEFT);
-	ui_toolbar_add_default("Repo", UI_TOOLBAR_LEFT);
+    ui_toolbar_add_default("Home", UI_TOOLBAR_LEFT);
+    ui_toolbar_add_default("NewWindow", UI_TOOLBAR_LEFT);
+    ui_toolbar_add_default("Refresh", UI_TOOLBAR_LEFT);
+    ui_toolbar_add_default("Repo", UI_TOOLBAR_LEFT);
 
-	ui_toolbar_add_default("NewFolder", UI_TOOLBAR_CENTER);
-	ui_toolbar_add_default("NewFile", UI_TOOLBAR_CENTER);
-	ui_toolbar_add_default("Remove", UI_TOOLBAR_CENTER);
-	ui_toolbar_add_default("Download", UI_TOOLBAR_CENTER);
-	ui_toolbar_add_default("Upload", UI_TOOLBAR_CENTER);
+    ui_toolbar_add_default("NewFolder", UI_TOOLBAR_CENTER);
+    ui_toolbar_add_default("NewFile", UI_TOOLBAR_CENTER);
+    ui_toolbar_add_default("Remove", UI_TOOLBAR_CENTER);
+    ui_toolbar_add_default("Download", UI_TOOLBAR_CENTER);
+    ui_toolbar_add_default("Upload", UI_TOOLBAR_CENTER);
 
-	ui_toolbar_add_default("LocalBrowser", UI_TOOLBAR_RIGHT);
-	ui_toolbar_add_default("PreviewPane", UI_TOOLBAR_RIGHT);
+    ui_toolbar_add_default("LocalBrowser", UI_TOOLBAR_RIGHT);
+    ui_toolbar_add_default("PreviewPane", UI_TOOLBAR_RIGHT);
 }
 
 
--- a/application/window.c	Sun Jun 09 15:43:08 2024 +0200
+++ b/application/window.c	Sun Jun 09 16:06:40 2024 +0200
@@ -57,8 +57,8 @@
 
 	// navigation bar
 	ui_hbox(obj, .fill = UI_OFF, .margin = 8) {
-		ui_button(obj, .icon = "Back", .onclick = action_go_back);
-		ui_button(obj, .icon = "Forward", .onclick = action_go_forward);
+		ui_button(obj, .icon = UI_ICON_GO_BACK, .onclick = action_go_back);
+		ui_button(obj, .icon = UI_ICON_GO_FORWARD, .onclick = action_go_forward);
 
 		ui_path_textfield(obj, .fill = UI_ON, .getpathelm = dav_get_pathelm, .onactivate = action_path_selected ,.varname = "path");
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/ui/icons.h	Sun Jun 09 16:06:40 2024 +0200
@@ -0,0 +1,80 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2024 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef UI_ICONS_H
+#define UI_ICONS_H
+
+#include "toolkit.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef UI_GTK3
+    
+#define UI_ICON_HOME "user-home"
+#define UI_ICON_NEW_WINDOW ""
+#define UI_ICON_REFRESH ""
+#define UI_ICON_NEW_FOLDER "folder-new"
+#define UI_ICON_ADD ""
+#define UI_ICON_UPLOAD ""
+#define UI_ICON_SAVE_LOCAL ""
+#define UI_ICON_DELETE ""
+#define UI_ICON_DOCK_LEFT ""
+#define UI_ICON_DOCK_RIGHT ""
+#define UI_ICON_GO_BACK "go-previous"
+#define UI_ICON_GO_FORWARD "go-next"
+    
+#endif /* UI_GTK3 */
+    
+    
+
+#ifdef UI_WINUI
+    
+#define UI_ICON_HOME "Home"
+#define UI_ICON_NEW_WINDOW "NewWindow"
+#define UI_ICON_REFRESH "Refresh"
+#define UI_ICON_NEW_FOLDER "NewFolder"
+#define UI_ICON_ADD "Add"
+#define UI_ICON_UPLOAD "Upload"
+#define UI_ICON_SAVE_LOCAL "SaveLocal"
+#define UI_ICON_DELETE "Delete"
+#define UI_ICON_DOCK_LEFT "DockLeft"
+#define UI_ICON_DOCK_RIGHT "DockRight"
+#define UI_ICON_GO_BACK "Back"
+#define UI_ICON_GO_FORWARD "Forward"
+    
+#endif /* UI_WINUI */
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* UI_ICONS_H */
+
--- a/ui/ui/ui.h	Sun Jun 09 15:43:08 2024 +0200
+++ b/ui/ui/ui.h	Sun Jun 09 16:06:40 2024 +0200
@@ -45,6 +45,7 @@
 #include "image.h"
 #include "display.h"
 #include "dnd.h"
+#include "icons.h"
 
 #endif	/* UI_H */
 

mercurial