This commit is contained in:
galister 2026-07-12 22:20:45 +09:00
parent 0a7f8340d7
commit 02f1de59b2
4 changed files with 41 additions and 14 deletions

View File

@ -10,8 +10,8 @@
<!-- Toast title --> <!-- Toast title -->
<div flex_direction="row" align_items="center" gap="8"> <div flex_direction="row" align_items="center" gap="8">
<sprite src="icons/bell.svg" color="on_background_variant" min_width="32" min_height="32" max_width="32" max_height="32" flex_grow="1" /> <sprite src="icons/bell.svg" color="primary" min_width="32" min_height="32" max_width="32" max_height="32" flex_grow="1" />
<label wrap="1" id="toast_title" color="on_background_variant" weight="bold" size="25" padding_left="16" padding_right="16" /> <label wrap="1" id="toast_title" color="primary" weight="bold" size="25" padding_left="16" padding_right="16" />
</div> </div>
<!-- A simple separator --> <!-- A simple separator -->

View File

@ -16,7 +16,7 @@
<template name="Device"> <template name="Device">
<rectangle macro="decorative_rect" padding_top="4" padding_bottom="4" align_items="center" gap="8"> <rectangle macro="decorative_rect" padding_top="4" padding_bottom="4" align_items="center" gap="8">
<sprite width="32" height="32" src_builtin="${src}" color="on_background" /> <sprite width="32" height="32" src_builtin="${src}" color="on_background" />
<label _source="battery" _device="${idx}" size="24" weight="bold" _low_color="danger" _normal_color="primary" _charging_color="secondary" /> <label _source="battery" _device="${idx}" size="24" weight="bold" _low_color="danger" _normal_color="primary" _charging_color="tertiary" />
</rectangle> </rectangle>
</template> </template>

View File

@ -3,24 +3,26 @@ use crate::{
assets::AssetPath, assets::AssetPath,
color::{WguiColor, WguiColorName}, color::{WguiColor, WguiColorName},
components::{ components::{
self, Component, ComponentBase, ComponentTrait, RefreshData, self,
tooltip::{ComponentTooltip, TooltipTrait}, tooltip::{ComponentTooltip, TooltipTrait},
Component, ComponentBase, ComponentTrait, RefreshData,
}, },
drawing::{self, Boundary}, drawing::{self, Boundary},
event::{CallbackDataCommon, EventListenerCollection, EventListenerID, EventListenerKind}, event::{CallbackDataCommon, EventListenerCollection, EventListenerID, EventListenerKind},
i18n::Translation, i18n::Translation,
layout::{WidgetID, WidgetPair}, layout::{WidgetID, WidgetPair},
renderer_vk::{ renderer_vk::{
text::{FontWeight, TextStyle, custom_glyph::CustomGlyphData}, text::{custom_glyph::CustomGlyphData, FontWeight, TextStyle},
util::centered_matrix, util::centered_matrix,
}, },
sound::WguiSoundType, sound::WguiSoundType,
widget::{ widget::{
self, ConstructEssentials, EventResult, WidgetData, self,
label::{WidgetLabel, WidgetLabelParams}, label::{WidgetLabel, WidgetLabelParams},
rectangle::{WidgetRectangle, WidgetRectangleParams}, rectangle::{WidgetRectangle, WidgetRectangleParams},
sprite::{WidgetSprite, WidgetSpriteParams}, sprite::{WidgetSprite, WidgetSpriteParams},
util::WLength, util::WLength,
ConstructEssentials, EventResult, WidgetData,
}, },
}; };
use glam::{Mat4, Vec2, Vec3}; use glam::{Mat4, Vec2, Vec3};
@ -29,7 +31,7 @@ use std::{
rc::Rc, rc::Rc,
time::{Duration, Instant}, time::{Duration, Instant},
}; };
use taffy::{AlignItems, JustifyContent, prelude::length}; use taffy::{prelude::length, AlignItems, JustifyContent};
pub struct Params<'a> { pub struct Params<'a> {
pub text: Option<Translation>, // if unset, label will not be populated pub text: Option<Translation>, // if unset, label will not be populated
@ -38,8 +40,10 @@ pub struct Params<'a> {
pub color: Option<WguiColor>, pub color: Option<WguiColor>,
pub border: f32, pub border: f32,
pub border_color: Option<WguiColor>, pub border_color: Option<WguiColor>,
pub hover_border_color: Option<WguiColor>,
pub hover_color: Option<WguiColor>, pub hover_color: Option<WguiColor>,
pub hover_border_color: Option<WguiColor>,
pub sticky_color: Option<WguiColor>,
pub sticky_border_color: Option<WguiColor>,
pub round: WLength, pub round: WLength,
pub style: taffy::Style, pub style: taffy::Style,
pub text_style: TextStyle, pub text_style: TextStyle,
@ -58,10 +62,12 @@ impl Default for Params<'_> {
text: Some(Translation::from_raw_text("")), text: Some(Translation::from_raw_text("")),
sprite_src: None, sprite_src: None,
color: None, color: None,
hover_color: None,
border_color: None, border_color: None,
border: 2.0, hover_color: None,
hover_border_color: None, hover_border_color: None,
sticky_color: None,
sticky_border_color: None,
border: 2.0,
round: WLength::Units(4.0), round: WLength::Units(4.0),
style: Default::default(), style: Default::default(),
text_style: TextStyle::default(), text_style: TextStyle::default(),
@ -84,6 +90,8 @@ pub struct Colors {
pub border_color: WguiColor, pub border_color: WguiColor,
pub hover_color: WguiColor, pub hover_color: WguiColor,
pub hover_border_color: WguiColor, pub hover_border_color: WguiColor,
pub sticky_color: WguiColor,
pub sticky_border_color: WguiColor,
} }
struct State { struct State {
@ -478,6 +486,12 @@ pub fn construct(ess: &mut ConstructEssentials, params: Params) -> anyhow::Resul
.hover_border_color .hover_border_color
.unwrap_or_else(|| border_color.add_rgb(0.5).add_alpha(0.5)); .unwrap_or_else(|| border_color.add_rgb(0.5).add_alpha(0.5));
let sticky_color = params.hover_color.unwrap_or_else(|| color.add_rgb(0.15).add_alpha(0.1));
let sticky_border_color = params
.hover_border_color
.unwrap_or_else(|| border_color.add_rgb(0.25).add_alpha(0.35));
let gradient_intensity = theme.gradient_intensity; let gradient_intensity = theme.gradient_intensity;
drop(globals); drop(globals);
@ -568,6 +582,8 @@ pub fn construct(ess: &mut ConstructEssentials, params: Params) -> anyhow::Resul
border_color, border_color,
hover_color, hover_color,
hover_border_color, hover_border_color,
sticky_color,
sticky_border_color,
}, },
})); }));

View File

@ -1,14 +1,15 @@
use crate::{ use crate::{
assets::AssetPath, assets::AssetPath,
color::WguiColor, color::WguiColor,
components::{Component, button}, components::{button, Component},
i18n::Translation, i18n::Translation,
layout::WidgetID, layout::WidgetID,
parser::{ parser::{
AttribPair, ParserContext, ParserFile, get_asset_path_from_kv, get_asset_path_from_kv,
helpers::{TooltipAttribs, parse_attrib_tooltip}, helpers::{parse_attrib_tooltip, TooltipAttribs},
parse_children, parse_f32, process_component, parse_children, parse_f32, process_component,
style::{parse_color_opt, parse_round, parse_style, parse_text_style}, style::{parse_color_opt, parse_round, parse_style, parse_text_style},
AttribPair, ParserContext, ParserFile,
}, },
widget::util::WLength, widget::util::WLength,
}; };
@ -27,6 +28,8 @@ pub fn parse_component_button<'a>(
let mut border_color: Option<WguiColor> = None; let mut border_color: Option<WguiColor> = None;
let mut hover_color: Option<WguiColor> = None; let mut hover_color: Option<WguiColor> = None;
let mut hover_border_color: Option<WguiColor> = None; let mut hover_border_color: Option<WguiColor> = None;
let mut sticky_color: Option<WguiColor> = None;
let mut sticky_border_color: Option<WguiColor> = None;
let mut round = WLength::Units(4.0); let mut round = WLength::Units(4.0);
let mut tooltip = TooltipAttribs::default(); let mut tooltip = TooltipAttribs::default();
let mut sticky: bool = false; let mut sticky: bool = false;
@ -79,6 +82,12 @@ pub fn parse_component_button<'a>(
"hover_border_color" => { "hover_border_color" => {
parse_color_opt(ctx, tag_name, key, value, &mut hover_border_color); parse_color_opt(ctx, tag_name, key, value, &mut hover_border_color);
} }
"sticky_color" => {
parse_color_opt(ctx, tag_name, key, value, &mut sticky_color);
}
"sticky_border_color" => {
parse_color_opt(ctx, tag_name, key, value, &mut sticky_border_color);
}
"sprite_src" | "sprite_src_ext" | "sprite_src_builtin" | "sprite_src_internal" => { "sprite_src" | "sprite_src_ext" | "sprite_src_builtin" | "sprite_src_internal" => {
let asset_path = get_asset_path_from_kv("sprite_", key, value); let asset_path = get_asset_path_from_kv("sprite_", key, value);
@ -106,8 +115,10 @@ pub fn parse_component_button<'a>(
color, color,
border, border,
border_color, border_color,
hover_border_color,
hover_color, hover_color,
hover_border_color,
sticky_color,
sticky_border_color,
text: translation, text: translation,
style, style,
text_style, text_style,