From ff466e7bf41b10f92cf4ca0089cf2e57ba13b024 Mon Sep 17 00:00:00 2001 From: luboslenco Date: Thu, 26 Mar 2020 17:03:57 +0100 Subject: [PATCH] Add theme to config --- Assets/themes/{theme_light.arm => light.json} | 0 Sources/arm/App.hx | 5 +++ Sources/arm/Config.hx | 2 + Sources/arm/ConfigFormat.hx | 1 + Sources/arm/ui/BoxPreferences.hx | 42 ++++++++++++------- 5 files changed, 34 insertions(+), 16 deletions(-) rename Assets/themes/{theme_light.arm => light.json} (100%) diff --git a/Assets/themes/theme_light.arm b/Assets/themes/light.json similarity index 100% rename from Assets/themes/theme_light.arm rename to Assets/themes/light.json diff --git a/Sources/arm/App.hx b/Sources/arm/App.hx index 19264390..5521bf85 100644 --- a/Sources/arm/App.hx +++ b/Sources/arm/App.hx @@ -183,6 +183,11 @@ class App { } }); } + + // Non-default theme selected + if (Config.raw.theme != "dark.json") { + arm.ui.BoxPreferences.loadTheme(Config.raw.theme); + } }); }); } diff --git a/Sources/arm/Config.hx b/Sources/arm/Config.hx index 8f6f5136..134bf3be 100644 --- a/Sources/arm/Config.hx +++ b/Sources/arm/Config.hx @@ -73,6 +73,7 @@ class Config { raw.bookmarks = []; raw.plugins = []; raw.keymap = "default.json"; + raw.theme = "dark.json"; raw.undo_steps = 4; raw.pressure_radius = true; raw.pressure_hardness = true; @@ -105,6 +106,7 @@ class Config { Translator.loadTranslations(raw.locale); #if arm_painter applyConfig(); + arm.ui.BoxPreferences.loadTheme(raw.theme); #end } diff --git a/Sources/arm/ConfigFormat.hx b/Sources/arm/ConfigFormat.hx index c426f51f..e85eb551 100644 --- a/Sources/arm/ConfigFormat.hx +++ b/Sources/arm/ConfigFormat.hx @@ -27,6 +27,7 @@ typedef TConfig = { @:optional var bookmarks: Array; // Bookmarked folders in browser @:optional var plugins: Array; // List of enabled plugins @:optional var keymap: String; // Link to keymap file + @:optional var theme: String; // Link to theme file @:optional var undo_steps: Null; // Number of undo steps to preserve @:optional var pressure_radius: Null; // Pen pressure controls @:optional var pressure_hardness: Null; diff --git a/Sources/arm/ui/BoxPreferences.hx b/Sources/arm/ui/BoxPreferences.hx index 39a18150..8348deb4 100644 --- a/Sources/arm/ui/BoxPreferences.hx +++ b/Sources/arm/ui/BoxPreferences.hx @@ -19,6 +19,7 @@ class BoxPreferences { public static var filesKeymap: Array = null; public static var presetHandle: Handle; static var locales: Array = null; + static var themes: Array = null; @:access(zui.Zui) public static function show() { @@ -48,24 +49,17 @@ class BoxPreferences { setScale(); } Context.hscaleWasChanged = hscale.changed; - var themeHandle = Id.handle(); - var themes = ["Dark", "Light"]; + + if (themes == null) { + themes = File.readDirectory(Path.data() + Path.sep + "themes"); + for (i in 0...themes.length) themes[i] = themes[i].substr(0, themes[i].length - 5); // Trim .json + themes.unshift("dark"); + } + var themeHandle = Id.handle({position: themes.indexOf(Config.raw.theme.substr(0, Config.raw.theme.length - 5))}); ui.combo(themeHandle, themes, tr("Theme"), true); if (themeHandle.changed) { - var theme = themes[themeHandle.position].toLowerCase(); - if (theme == "dark") { // Built-in default - App.theme = zui.Themes.dark; - } - else { - Data.getBlob("themes/theme_" + theme + ".arm", function(b: kha.Blob) { - App.theme = Json.parse(b.toString()); - }); - } - ui.t = App.theme; - UISidebar.inst.ui.t = App.theme; - UINodes.inst.ui.t = App.theme; - UIView2D.inst.ui.t = App.theme; - UISidebar.inst.tagUIRedraw(); + Config.raw.theme = themes[themeHandle.position] + ".json"; + loadTheme(Config.raw.theme); } #if (!krom_android && !krom_ios) @@ -390,4 +384,20 @@ plugin.drawUI = function(ui) { App.uiMenu.setScale(scale); App.resize(); } + + public static function loadTheme(theme: String) { + if (theme == "dark.json") { // Built-in default + App.theme = zui.Themes.dark; + } + else { + Data.getBlob("themes/" + theme, function(b: kha.Blob) { + App.theme = Json.parse(b.toString()); + }); + } + App.uiBox.t = App.theme; + UISidebar.inst.ui.t = App.theme; + UINodes.inst.ui.t = App.theme; + UIView2D.inst.ui.t = App.theme; + UISidebar.inst.tagUIRedraw(); + } }