From 91fc3e75b983717dc48e7445783e6931c5b335f0 Mon Sep 17 00:00:00 2001 From: OmniaX-Dev Date: Fri, 17 Apr 2026 08:11:52 +0200 Subject: [PATCH] Added gradient and file() functions to stylesheet --- .clangd | 1 - extra/DefaultTheme.oss | 29 +++++++------- other/build.nr | 2 +- src/ogfx/gui/widgets/Button.cpp | 1 + src/ostd/data/Color.hpp | 2 +- src/ostd/io/Stylesheet.cpp | 69 +++++++++++++++++++++++++++------ 6 files changed, 75 insertions(+), 29 deletions(-) diff --git a/.clangd b/.clangd index c60968a..e6defe1 100644 --- a/.clangd +++ b/.clangd @@ -1,5 +1,4 @@ CompileFlags: CompilationDatabase: bin - Add: ["--target=x86_64-w64-mingw32"] Diagnostics: MissingIncludes: None \ No newline at end of file diff --git a/extra/DefaultTheme.oss b/extra/DefaultTheme.oss index e699415..8982bb0 100644 --- a/extra/DefaultTheme.oss +++ b/extra/DefaultTheme.oss @@ -30,9 +30,9 @@ window.backgroundColor = rgba(160, 160, 160, 255) titlebarHeight = 18 titlebarFontSize = 18 titlebarTextAlign = text_left - scrollSpeed = Vec2(0.8, 0.8) - padding = Rect(15, 15, 15, 15) - margin = Rect(0, 0, 0, 0) + scrollSpeed = vec2(0.8, 0.8) + padding = rect(15, 15, 15, 15) + margin = rect(0, 0, 0, 0) } % =================== @@ -48,7 +48,7 @@ window.backgroundColor = rgba(160, 160, 160, 255) } (track) { color = rgb(90, 90, 90) - borderRadii = Rect(0, 0, 10, 0) + borderRadii = rect(0, 0, 10, 0) } width = 18.0 } @@ -83,8 +83,8 @@ window.backgroundColor = rgba(160, 160, 160, 255) checkBorderWidth = 2 showBackground = false showBorder = false - padding = Rect(15, 15, 15, 15) - margin = Rect(0, 0, 0, 0) + padding = rect(15, 15, 15, 15) + margin = rect(0, 0, 0, 0) } (checkbox:hover) { checkBorderColor = $accentColorLight @@ -113,8 +113,8 @@ window.backgroundColor = rgba(160, 160, 160, 255) borderWidth = 0 showBackground = false showBorder = false - padding = Rect(15, 15, 15, 15) - margin = Rect(0, 0, 0, 0) + padding = rect(15, 15, 15, 15) + margin = rect(0, 0, 0, 0) } % =================== @@ -124,8 +124,7 @@ window.backgroundColor = rgba(160, 160, 160, 255) (button) { textColor = $textColor backgroundColor = #999999FF - backgroundGradient = gradientH(#000000FF, #555555FF, #999999FF) - backgroundGradient = w_vgradientV(#000000FF, 0.2, #555555FF, 0.8, #999999FF) + backgroundGradient = gradientV(rgb(160, 160, 160) - rgb(120, 120, 120)) borderColor = $accentColorDark fontSize = 20 borderRadius = 0 @@ -133,17 +132,17 @@ window.backgroundColor = rgba(160, 160, 160, 255) showBackground = true showBorder = true useBackgroundGradient = true - padding = Rect(15, 5, 15, 5) - margin = Rect(0, 0, 0, 0) - icon = file("testIcon.png") + padding = rect(15, 8, 15, 8) + margin = rect(0, 0, 0, 0) + icon = file("img.png") } (button:hover) { borderColor = $accentColor backgroundColor = #BBBBBBFF } (button:pressed) { - borderColor = #BBBBBBFF + borderColor = $accentColorDark textColor = #DDDDDDFF - backgroundColor = #555555FF + backgroundGradient = gradientV(rgb(120, 120, 120) - rgb(160, 160, 160)) } % =================== diff --git a/other/build.nr b/other/build.nr index d90a27d..0e21d5e 100644 --- a/other/build.nr +++ b/other/build.nr @@ -1 +1 @@ -2065 +2066 diff --git a/src/ogfx/gui/widgets/Button.cpp b/src/ogfx/gui/widgets/Button.cpp index 2557cfc..5c25c7c 100644 --- a/src/ogfx/gui/widgets/Button.cpp +++ b/src/ogfx/gui/widgets/Button.cpp @@ -52,6 +52,7 @@ namespace ogfx setPadding(getThemeValue(theme, "button.padding", { 5, 5, 5, 5 })); setMargin(getThemeValue(theme, "button.margin", { 0, 0, 0, 0 })); m_useBackgroundGradient = getThemeValue(theme, "button.useBackgroundGradient", false); + m_backgroundGradient = getThemeValue(theme, "button.backgroundGradient", m_backgroundGradient); if (m_useBackgroundGradient && isBackgoundEnabled()) enableBackground(false); } diff --git a/src/ostd/data/Color.hpp b/src/ostd/data/Color.hpp index b044179..6c10cc1 100755 --- a/src/ostd/data/Color.hpp +++ b/src/ostd/data/Color.hpp @@ -125,7 +125,7 @@ namespace ostd str.add(m_weights[i - 1], 2).add(", "); str.add(m_colors[i].hexString(true, "#")).add(" "); } - return str.trim(); + return str.trim().add("@").add(m_angleDeg, 2); } private: diff --git a/src/ostd/io/Stylesheet.cpp b/src/ostd/io/Stylesheet.cpp index 958632b..452c656 100644 --- a/src/ostd/io/Stylesheet.cpp +++ b/src/ostd/io/Stylesheet.cpp @@ -269,6 +269,19 @@ namespace ostd return true; return false; }; + auto l_isFile = [this](String& value) -> bool { + value.trim(); + if (value.startsWith("file(") && value.endsWith(")")) + { + value.substr(5, value.len() - 1).trim(); + if (value.startsWith("\"") && value.endsWith("\"")) + { + value.substr(1, value.len() - 1); + return true; + } + } + return false; + }; if (key.startsWith("@")) { @@ -299,6 +312,15 @@ namespace ostd return false; set(key, grad, themeID); } + else if (l_isFile(value)) + { + bool exists = ostd::FileSystem::fileExists(value) || + ostd::FileSystem::fileExists("./" + value); + if (exists) + set(key, value, themeID); + else + return false; + } else if (value.startsWith("vec2(") && value.endsWith(")")) { value.substr(5, value.len() - 1).trim(); @@ -419,16 +441,16 @@ namespace ostd return newLines; } - ColorGradient parseColorGradient(const String& _value) + ColorGradient Stylesheet::parseColorGradient(const String& _value) { String value = _value.new_toLower().trim(); ColorGradient grad; f32 angle = 0.0f; bool weighted = false; String gradientFunc = value.new_substr(0, value.indexOf("(")).trim(); - String gradientVal = value.substr(value.indexOf("(") + 1, value.indexOf(")")).trim(); + String gradientVal = value.substr(value.indexOf("(") + 1, value.lastIndexOf(")")).trim(); - if (gradientVal == "" || !gradientVal.contains(",")) + if (gradientVal == "" || !gradientVal.contains("-")) return grad; weighted = gradientFunc.startsWith("w_"); @@ -439,20 +461,45 @@ namespace ostd else return grad; - auto tokens = gradientVal.tokenize(","); + auto tokens = gradientVal.tokenize("-"); - bool is_color = true; - for (auto& token : tokens) + if (weighted && tokens.count() < 3) + return grad; + + if (tokens.count() < 2) + return grad; + + grad.setAngleDeg(angle); + if (!weighted) { - if (is_color) + i32 index = 0; + for (auto& token : tokens) { - + grad.addColor(Color(token)); + if (index > 0) + grad.addWeight(1.0f); + index++; } - else + return grad; + } + else + { + bool is_color = true; + for (auto& token : tokens) { - + if (is_color) + { + grad.addColor(Color(token)); + } + else + { + if (!token.isNumeric(true)) + return ColorGradient(); + grad.addWeight(token.toFloat()); + } + is_color = !is_color; } - is_color = !is_color; + return grad; } return grad;