From 1f9e1eba27e9a007e7427802454b6853eecd7e53 Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Mon, 19 May 2014 14:33:38 +0400 Subject: [PATCH] support loading of theme from .xml file --- examples/example1/src/main.d | 6 + res/theme_default.xml | 162 ++++++++++++++++++ src/dlangui/graphics/resources.d | 11 +- src/dlangui/widgets/styles.d | 273 ++++++++++++++++++++++++++++++- 4 files changed, 446 insertions(+), 6 deletions(-) create mode 100644 res/theme_default.xml diff --git a/examples/example1/src/main.d b/examples/example1/src/main.d index bddde90d..5a56c755 100644 --- a/examples/example1/src/main.d +++ b/examples/example1/src/main.d @@ -96,6 +96,12 @@ extern (C) int UIAppMain(string[] args) { // select translation file - for english language i18n.load("en.ini"); //"ru.ini", "en.ini" + Theme theme = loadTheme("theme_default"); + if (theme) { + Log.d("Applying loaded theme ", theme.id); + currentTheme = theme; + } + // create window Window window = Platform.instance.createWindow("My Window", null); diff --git a/res/theme_default.xml b/res/theme_default.xml new file mode 100644 index 00000000..b68e4a36 --- /dev/null +++ b/res/theme_default.xml @@ -0,0 +1,162 @@ + + + + + + + + + + + + * + * --- + * + */ +bool loadTheme(Theme theme, Element doc, int level = 0) { + if (doc.tag.name.equal("theme")) { + Log.e(" element should be main in theme file!"); + return false; + } + // + string id = attrValue(doc, "id"); + string parent = attrValue(doc, "parent"); + theme.id = id; + if (parent.length > 0) { + // load base theme + if (level < 3) // to prevent infinite recursion + loadTheme(theme, parent, level + 1); + } + loadStyleAttributes(theme, doc, false); + foreach(styleitem; doc.elements) { + if (styleitem.tag.name.equal("style")) { + // load