Added gradient and file() functions to stylesheet
This commit is contained in:
parent
7e37210e82
commit
91fc3e75b9
6 changed files with 75 additions and 29 deletions
1
.clangd
1
.clangd
|
|
@ -1,5 +1,4 @@
|
||||||
CompileFlags:
|
CompileFlags:
|
||||||
CompilationDatabase: bin
|
CompilationDatabase: bin
|
||||||
Add: ["--target=x86_64-w64-mingw32"]
|
|
||||||
Diagnostics:
|
Diagnostics:
|
||||||
MissingIncludes: None
|
MissingIncludes: None
|
||||||
|
|
@ -30,9 +30,9 @@ window.backgroundColor = rgba(160, 160, 160, 255)
|
||||||
titlebarHeight = 18
|
titlebarHeight = 18
|
||||||
titlebarFontSize = 18
|
titlebarFontSize = 18
|
||||||
titlebarTextAlign = text_left
|
titlebarTextAlign = text_left
|
||||||
scrollSpeed = Vec2(0.8, 0.8)
|
scrollSpeed = vec2(0.8, 0.8)
|
||||||
padding = Rect(15, 15, 15, 15)
|
padding = rect(15, 15, 15, 15)
|
||||||
margin = Rect(0, 0, 0, 0)
|
margin = rect(0, 0, 0, 0)
|
||||||
}
|
}
|
||||||
% ===================
|
% ===================
|
||||||
|
|
||||||
|
|
@ -48,7 +48,7 @@ window.backgroundColor = rgba(160, 160, 160, 255)
|
||||||
}
|
}
|
||||||
(track) {
|
(track) {
|
||||||
color = rgb(90, 90, 90)
|
color = rgb(90, 90, 90)
|
||||||
borderRadii = Rect(0, 0, 10, 0)
|
borderRadii = rect(0, 0, 10, 0)
|
||||||
}
|
}
|
||||||
width = 18.0
|
width = 18.0
|
||||||
}
|
}
|
||||||
|
|
@ -83,8 +83,8 @@ window.backgroundColor = rgba(160, 160, 160, 255)
|
||||||
checkBorderWidth = 2
|
checkBorderWidth = 2
|
||||||
showBackground = false
|
showBackground = false
|
||||||
showBorder = false
|
showBorder = false
|
||||||
padding = Rect(15, 15, 15, 15)
|
padding = rect(15, 15, 15, 15)
|
||||||
margin = Rect(0, 0, 0, 0)
|
margin = rect(0, 0, 0, 0)
|
||||||
}
|
}
|
||||||
(checkbox:hover) {
|
(checkbox:hover) {
|
||||||
checkBorderColor = $accentColorLight
|
checkBorderColor = $accentColorLight
|
||||||
|
|
@ -113,8 +113,8 @@ window.backgroundColor = rgba(160, 160, 160, 255)
|
||||||
borderWidth = 0
|
borderWidth = 0
|
||||||
showBackground = false
|
showBackground = false
|
||||||
showBorder = false
|
showBorder = false
|
||||||
padding = Rect(15, 15, 15, 15)
|
padding = rect(15, 15, 15, 15)
|
||||||
margin = Rect(0, 0, 0, 0)
|
margin = rect(0, 0, 0, 0)
|
||||||
}
|
}
|
||||||
% ===================
|
% ===================
|
||||||
|
|
||||||
|
|
@ -124,8 +124,7 @@ window.backgroundColor = rgba(160, 160, 160, 255)
|
||||||
(button) {
|
(button) {
|
||||||
textColor = $textColor
|
textColor = $textColor
|
||||||
backgroundColor = #999999FF
|
backgroundColor = #999999FF
|
||||||
backgroundGradient = gradientH(#000000FF, #555555FF, #999999FF)
|
backgroundGradient = gradientV(rgb(160, 160, 160) - rgb(120, 120, 120))
|
||||||
backgroundGradient = w_vgradientV(#000000FF, 0.2, #555555FF, 0.8, #999999FF)
|
|
||||||
borderColor = $accentColorDark
|
borderColor = $accentColorDark
|
||||||
fontSize = 20
|
fontSize = 20
|
||||||
borderRadius = 0
|
borderRadius = 0
|
||||||
|
|
@ -133,17 +132,17 @@ window.backgroundColor = rgba(160, 160, 160, 255)
|
||||||
showBackground = true
|
showBackground = true
|
||||||
showBorder = true
|
showBorder = true
|
||||||
useBackgroundGradient = true
|
useBackgroundGradient = true
|
||||||
padding = Rect(15, 5, 15, 5)
|
padding = rect(15, 8, 15, 8)
|
||||||
margin = Rect(0, 0, 0, 0)
|
margin = rect(0, 0, 0, 0)
|
||||||
icon = file("testIcon.png")
|
icon = file("img.png")
|
||||||
}
|
}
|
||||||
(button:hover) {
|
(button:hover) {
|
||||||
borderColor = $accentColor
|
borderColor = $accentColor
|
||||||
backgroundColor = #BBBBBBFF
|
backgroundColor = #BBBBBBFF
|
||||||
}
|
}
|
||||||
(button:pressed) {
|
(button:pressed) {
|
||||||
borderColor = #BBBBBBFF
|
borderColor = $accentColorDark
|
||||||
textColor = #DDDDDDFF
|
textColor = #DDDDDDFF
|
||||||
backgroundColor = #555555FF
|
backgroundGradient = gradientV(rgb(120, 120, 120) - rgb(160, 160, 160))
|
||||||
}
|
}
|
||||||
% ===================
|
% ===================
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
2065
|
2066
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,7 @@ namespace ogfx
|
||||||
setPadding(getThemeValue<Rectangle>(theme, "button.padding", { 5, 5, 5, 5 }));
|
setPadding(getThemeValue<Rectangle>(theme, "button.padding", { 5, 5, 5, 5 }));
|
||||||
setMargin(getThemeValue<Rectangle>(theme, "button.margin", { 0, 0, 0, 0 }));
|
setMargin(getThemeValue<Rectangle>(theme, "button.margin", { 0, 0, 0, 0 }));
|
||||||
m_useBackgroundGradient = getThemeValue<bool>(theme, "button.useBackgroundGradient", false);
|
m_useBackgroundGradient = getThemeValue<bool>(theme, "button.useBackgroundGradient", false);
|
||||||
|
m_backgroundGradient = getThemeValue<ColorGradient>(theme, "button.backgroundGradient", m_backgroundGradient);
|
||||||
if (m_useBackgroundGradient && isBackgoundEnabled())
|
if (m_useBackgroundGradient && isBackgoundEnabled())
|
||||||
enableBackground(false);
|
enableBackground(false);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -125,7 +125,7 @@ namespace ostd
|
||||||
str.add(m_weights[i - 1], 2).add(", ");
|
str.add(m_weights[i - 1], 2).add(", ");
|
||||||
str.add(m_colors[i].hexString(true, "#")).add(" ");
|
str.add(m_colors[i].hexString(true, "#")).add(" ");
|
||||||
}
|
}
|
||||||
return str.trim();
|
return str.trim().add("@").add(m_angleDeg, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -269,6 +269,19 @@ namespace ostd
|
||||||
return true;
|
return true;
|
||||||
return false;
|
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("@"))
|
if (key.startsWith("@"))
|
||||||
{
|
{
|
||||||
|
|
@ -299,6 +312,15 @@ namespace ostd
|
||||||
return false;
|
return false;
|
||||||
set(key, grad, themeID);
|
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(")"))
|
else if (value.startsWith("vec2(") && value.endsWith(")"))
|
||||||
{
|
{
|
||||||
value.substr(5, value.len() - 1).trim();
|
value.substr(5, value.len() - 1).trim();
|
||||||
|
|
@ -419,16 +441,16 @@ namespace ostd
|
||||||
return newLines;
|
return newLines;
|
||||||
}
|
}
|
||||||
|
|
||||||
ColorGradient parseColorGradient(const String& _value)
|
ColorGradient Stylesheet::parseColorGradient(const String& _value)
|
||||||
{
|
{
|
||||||
String value = _value.new_toLower().trim();
|
String value = _value.new_toLower().trim();
|
||||||
ColorGradient grad;
|
ColorGradient grad;
|
||||||
f32 angle = 0.0f;
|
f32 angle = 0.0f;
|
||||||
bool weighted = false;
|
bool weighted = false;
|
||||||
String gradientFunc = value.new_substr(0, value.indexOf("(")).trim();
|
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;
|
return grad;
|
||||||
|
|
||||||
weighted = gradientFunc.startsWith("w_");
|
weighted = gradientFunc.startsWith("w_");
|
||||||
|
|
@ -439,21 +461,46 @@ namespace ostd
|
||||||
else
|
else
|
||||||
return grad;
|
return grad;
|
||||||
|
|
||||||
auto tokens = gradientVal.tokenize(",");
|
auto tokens = gradientVal.tokenize("-");
|
||||||
|
|
||||||
|
if (weighted && tokens.count() < 3)
|
||||||
|
return grad;
|
||||||
|
|
||||||
|
if (tokens.count() < 2)
|
||||||
|
return grad;
|
||||||
|
|
||||||
|
grad.setAngleDeg(angle);
|
||||||
|
if (!weighted)
|
||||||
|
{
|
||||||
|
i32 index = 0;
|
||||||
|
for (auto& token : tokens)
|
||||||
|
{
|
||||||
|
grad.addColor(Color(token));
|
||||||
|
if (index > 0)
|
||||||
|
grad.addWeight(1.0f);
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
return grad;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
bool is_color = true;
|
bool is_color = true;
|
||||||
for (auto& token : tokens)
|
for (auto& token : tokens)
|
||||||
{
|
{
|
||||||
if (is_color)
|
if (is_color)
|
||||||
{
|
{
|
||||||
|
grad.addColor(Color(token));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (!token.isNumeric(true))
|
||||||
|
return ColorGradient();
|
||||||
|
grad.addWeight(token.toFloat());
|
||||||
}
|
}
|
||||||
is_color = !is_color;
|
is_color = !is_color;
|
||||||
}
|
}
|
||||||
|
return grad;
|
||||||
|
}
|
||||||
|
|
||||||
return grad;
|
return grad;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue