settings for text+bg colors, anim speed, rounding

This commit is contained in:
galister
2025-12-22 15:03:17 +09:00
parent b9513c3c36
commit a0bc4001c0
16 changed files with 134 additions and 76 deletions

View File

@@ -1,13 +1,13 @@
use crate::{
assets::AssetPath,
components::{Component, button, tooltip},
components::{button, tooltip, Component},
drawing::Color,
i18n::Translation,
layout::WidgetID,
parser::{
AttribPair, ParserContext, ParserFile, parse_check_f32, parse_check_i32, parse_children, print_invalid_attrib,
process_component,
parse_check_f32, parse_check_i32, parse_children, print_invalid_attrib, process_component,
style::{parse_color_opt, parse_round, parse_style, parse_text_style},
AttribPair, ParserContext, ParserFile,
},
widget::util::WLength,
};
@@ -45,7 +45,7 @@ pub fn parse_component_button<'a>(
translation = Some(Translation::from_translation_key(value));
}
"round" => {
parse_round(value, &mut round);
parse_round(value, &mut round, ctx.doc_params.globals.get().defaults.rounding_mult);
}
"color" => {
parse_color_opt(value, &mut color);

View File

@@ -8,7 +8,7 @@ mod widget_rectangle;
mod widget_sprite;
use crate::{
assets::{AssetPath, AssetPathOwned, normalize_path},
assets::{normalize_path, AssetPath, AssetPathOwned},
components::{Component, ComponentWeak},
drawing::{self},
globals::WguiGlobals,
@@ -400,6 +400,7 @@ impl ParserContext<'_> {
insert_color_vars!(self, "accent", def.accent_color, def.translucent_alpha);
insert_color_vars!(self, "danger", def.danger_color, def.translucent_alpha);
insert_color_vars!(self, "faded", def.faded_color, def.translucent_alpha);
insert_color_vars!(self, "bg", def.bg_color, def.translucent_alpha);
}
}

View File

@@ -6,22 +6,22 @@ use taffy::{
use crate::{
drawing,
parser::{
AttribPair, is_percent, parse_color_hex, parse_f32, parse_percent, parse_size_unit, parse_val,
print_invalid_attrib, print_invalid_value,
is_percent, parse_color_hex, parse_f32, parse_percent, parse_size_unit, parse_val, print_invalid_attrib,
print_invalid_value, AttribPair,
},
renderer_vk::text::{FontWeight, HorizontalAlign, TextStyle},
widget::util::WLength,
};
pub fn parse_round(value: &str, round: &mut WLength) {
pub fn parse_round(value: &str, round: &mut WLength, multiplier: f32) {
if is_percent(value) {
if let Some(val) = parse_percent(value) {
*round = WLength::Percent(val);
*round = WLength::Percent((val * multiplier).clamp(0., 1.));
} else {
print_invalid_value(value);
}
} else if let Some(val) = parse_f32(value) {
*round = WLength::Units(val);
*round = WLength::Units((val * multiplier).max(0.));
} else {
print_invalid_value(value);
}

View File

@@ -2,8 +2,9 @@ use crate::{
drawing::GradientMode,
layout::WidgetID,
parser::{
AttribPair, ParserContext, ParserFile, parse_children, parse_widget_universal, print_invalid_attrib,
parse_children, parse_widget_universal, print_invalid_attrib,
style::{parse_color, parse_round, parse_style},
AttribPair, ParserContext, ParserFile,
},
widget::rectangle::{WidgetRectangle, WidgetRectangleParams},
};
@@ -40,7 +41,11 @@ pub fn parse_widget_rectangle<'a>(
}
}
"round" => {
parse_round(value, &mut params.round);
parse_round(
value,
&mut params.round,
ctx.doc_params.globals.get().defaults.rounding_mult,
);
}
"border" => {
params.border = value.parse().unwrap_or_else(|_| {