Added gradient and file() functions to stylesheet

This commit is contained in:
OmniaX-Dev 2026-04-17 08:11:52 +02:00
parent 7e37210e82
commit 91fc3e75b9
6 changed files with 75 additions and 29 deletions

View file

@ -1,5 +1,4 @@
CompileFlags:
CompilationDatabase: bin
Add: ["--target=x86_64-w64-mingw32"]
Diagnostics:
MissingIncludes: None

View file

@ -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))
}
% ===================

View file

@ -1 +1 @@
2065
2066

View file

@ -52,6 +52,7 @@ namespace ogfx
setPadding(getThemeValue<Rectangle>(theme, "button.padding", { 5, 5, 5, 5 }));
setMargin(getThemeValue<Rectangle>(theme, "button.margin", { 0, 0, 0, 0 }));
m_useBackgroundGradient = getThemeValue<bool>(theme, "button.useBackgroundGradient", false);
m_backgroundGradient = getThemeValue<ColorGradient>(theme, "button.backgroundGradient", m_backgroundGradient);
if (m_useBackgroundGradient && isBackgoundEnabled())
enableBackground(false);
}

View file

@ -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:

View file

@ -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;