From 2ea3b222f3fbf40665f63fb96b16ac99c2085a26 Mon Sep 17 00:00:00 2001
From: galister <22305755+galister@users.noreply.github.com>
Date: Mon, 13 Jul 2026 03:21:20 +0900
Subject: [PATCH] use_bg_color for label
---
dash-frontend/src/frontend.rs | 2 +-
dash-frontend/src/tab/settings/mod.rs | 1 +
dash-frontend/src/util/toast_manager.rs | 1 +
dash-frontend/src/util/wgui_simple.rs | 2 ++
dash-frontend/src/views/game_cover.rs | 1 +
wayvr/src/assets/gui/keyboard.xml | 6 ++---
wayvr/src/assets/gui/watch.xml | 6 ++---
wgui/src/color.rs | 29 +++++++++++++++++---
wgui/src/components/button.rs | 35 +++++++++++++------------
wgui/src/components/checkbox.rs | 1 +
wgui/src/components/editbox.rs | 1 +
wgui/src/components/slider.rs | 1 +
wgui/src/components/tooltip.rs | 1 +
wgui/src/parser/widget_label.rs | 3 +++
wgui/src/widget/label.rs | 9 ++++++-
15 files changed, 71 insertions(+), 28 deletions(-)
diff --git a/dash-frontend/src/frontend.rs b/dash-frontend/src/frontend.rs
index 327b3e64..c61e2456 100644
--- a/dash-frontend/src/frontend.rs
+++ b/dash-frontend/src/frontend.rs
@@ -1,4 +1,4 @@
-use std::{collections::HashMap, path::PathBuf, rc::Rc};
+use std::{path::PathBuf, rc::Rc};
use chrono::Timelike;
use glam::Vec2;
diff --git a/dash-frontend/src/tab/settings/mod.rs b/dash-frontend/src/tab/settings/mod.rs
index 043e976f..cc13efc3 100644
--- a/dash-frontend/src/tab/settings/mod.rs
+++ b/dash-frontend/src/tab/settings/mod.rs
@@ -607,6 +607,7 @@ fn mount_requires_restart(layout: &mut Layout, parent: WidgetID) -> anyhow::Resu
}),
..Default::default()
},
+ ..Default::default()
},
);
diff --git a/dash-frontend/src/util/toast_manager.rs b/dash-frontend/src/util/toast_manager.rs
index 13ed7f49..176bc937 100644
--- a/dash-frontend/src/util/toast_manager.rs
+++ b/dash-frontend/src/util/toast_manager.rs
@@ -110,6 +110,7 @@ impl ToastManager {
wrap: true,
..Default::default()
},
+ ..Default::default()
},
);
let (label, _) = layout.add_child(rect.id, label, taffy::Style { ..Default::default() })?;
diff --git a/dash-frontend/src/util/wgui_simple.rs b/dash-frontend/src/util/wgui_simple.rs
index f06c3f9a..44f2e6c5 100644
--- a/dash-frontend/src/util/wgui_simple.rs
+++ b/dash-frontend/src/util/wgui_simple.rs
@@ -55,6 +55,7 @@ pub fn create_label(layout: &mut Layout, id_parent: WidgetID, content: Translati
wrap: true,
..Default::default()
},
+ ..Default::default()
},
);
@@ -74,6 +75,7 @@ pub fn create_label_error(layout: &mut Layout, parent: WidgetID, content: String
weight: Some(FontWeight::Bold),
..Default::default()
},
+ ..Default::default()
},
);
diff --git a/dash-frontend/src/views/game_cover.rs b/dash-frontend/src/views/game_cover.rs
index 426da981..d33fdb23 100644
--- a/dash-frontend/src/views/game_cover.rs
+++ b/dash-frontend/src/views/game_cover.rs
@@ -113,6 +113,7 @@ impl View {
shadow: Some(WguiTextShadow::default()),
..Default::default()
},
+ ..Default::default()
},
);
diff --git a/wayvr/src/assets/gui/keyboard.xml b/wayvr/src/assets/gui/keyboard.xml
index 148df951..79665817 100644
--- a/wayvr/src/assets/gui/keyboard.xml
+++ b/wayvr/src/assets/gui/keyboard.xml
@@ -130,7 +130,7 @@
@@ -163,7 +163,7 @@
@@ -192,7 +192,7 @@
diff --git a/wayvr/src/assets/gui/watch.xml b/wayvr/src/assets/gui/watch.xml
index bdb11769..72e531cb 100644
--- a/wayvr/src/assets/gui/watch.xml
+++ b/wayvr/src/assets/gui/watch.xml
@@ -38,7 +38,7 @@
@@ -51,7 +51,7 @@
@@ -65,7 +65,7 @@
diff --git a/wgui/src/color.rs b/wgui/src/color.rs
index eb5d31b8..b2c229b8 100644
--- a/wgui/src/color.rs
+++ b/wgui/src/color.rs
@@ -119,9 +119,19 @@ impl WguiColor {
}
}
- pub fn on_color(&self) -> Option {
+ /// Gets a matching foreground color from a background color
+ pub fn fg_color(&self) -> Option {
if let Self::Named(name) = self {
- name.name.on_color().map(|x| x.into())
+ name.name.fg_color().map(|x| x.into())
+ } else {
+ None
+ }
+ }
+
+ /// Gets a matching background color from a foreground color
+ pub fn bg_color(&self) -> Option {
+ if let Self::Named(name) = self {
+ name.name.bg_color().map(|x| x.into())
} else {
None
}
@@ -129,7 +139,7 @@ impl WguiColor {
}
impl WguiColorName {
- pub fn on_color(&self) -> Option {
+ pub fn fg_color(&self) -> Option {
match self {
Self::Primary => Some(Self::OnPrimary),
Self::Secondary => Some(Self::OnSecondary),
@@ -142,6 +152,19 @@ impl WguiColorName {
}
}
+ pub fn bg_color(&self) -> Option {
+ match self {
+ Self::OnPrimary => Some(Self::Primary),
+ Self::OnSecondary => Some(Self::Secondary),
+ Self::OnTertiary => Some(Self::Tertiary),
+ Self::OnDanger => Some(Self::Danger),
+ Self::OnBackground => Some(Self::Background),
+ Self::OnBackgroundVariant => Some(Self::BackgroundVariant),
+ Self::OnBackgroundContrast => Some(Self::BackgroundContrast),
+ _ => None,
+ }
+ }
+
pub const fn to_wgui_color(&self) -> WguiColor {
WguiColor::Named(WguiNamedColor {
name: *self,
diff --git a/wgui/src/components/button.rs b/wgui/src/components/button.rs
index 4f1b9718..d3058b54 100644
--- a/wgui/src/components/button.rs
+++ b/wgui/src/components/button.rs
@@ -149,24 +149,24 @@ impl ComponentTrait for ComponentButton {
log::error!("Button with more than one sprite!");
}
// apply initial color from button
- if let Some(on_color) = state.colors.color.on_color() {
+ if let Some(fg_color) = state.colors.color.fg_color() {
let common = &mut CallbackDataCommon {
state: &data.layout.state,
alterables: &mut data.layout.alterables,
};
- widget.set_color(common, on_color);
+ widget.set_color(common, fg_color);
}
state.id_sprite = child;
} else if let Some(mut widget) = data.layout.state.widgets.get_as::(child) {
if !state.id_label.is_null() && state.id_label != child {
log::error!("Button with more than one label!");
}
- if let Some(on_color) = state.colors.color.on_color() {
+ if let Some(fg_color) = state.colors.color.fg_color() {
let common = &mut CallbackDataCommon {
state: &data.layout.state,
alterables: &mut data.layout.alterables,
};
- widget.set_color(common, on_color, true);
+ widget.set_color(common, fg_color, true);
}
state.id_label = child;
}
@@ -216,12 +216,12 @@ impl ComponentButton {
let mut state = self.state.borrow_mut();
state.colors.color = color;
- if let Some(on_color) = color.on_color() {
+ if let Some(fg_color) = color.fg_color() {
if let Some(mut label) = common.state.widgets.get_as::(state.id_label) {
- label.set_color(common, on_color, true);
+ label.set_color(common, fg_color, true);
}
if let Some(mut sprite) = common.state.widgets.get_as::(state.id_sprite) {
- sprite.set_color(common, on_color);
+ sprite.set_color(common, fg_color);
}
}
}
@@ -287,15 +287,15 @@ impl ComponentButton {
.border_color
.lerp(&common.globals().palette, alt_border_color, mult);
- if let Some(on_color0) = colors.color.on_color()
- && let Some(on_color1) = alt_color.on_color()
+ if let Some(fg_color0) = colors.color.fg_color()
+ && let Some(fg_color1) = alt_color.fg_color()
{
- let on_color = on_color0.lerp(&common.globals().palette, &on_color1, mult);
+ let fg_color = fg_color0.lerp(&common.globals().palette, &fg_color1, mult);
if let Some(mut label) = common.state.widgets.get_as::(state.id_label) {
- label.set_color(common, on_color, true);
+ label.set_color(common, fg_color, true);
}
if let Some(mut sprite) = common.state.widgets.get_as::(state.id_sprite) {
- sprite.set_color(common, on_color);
+ sprite.set_color(common, fg_color);
}
}
}
@@ -328,15 +328,15 @@ fn anim_hover(
(colors.border_color, colors.color)
};
- if let Some(on_color0) = init_color.on_color()
- && let Some(on_color1) = colors.hover_color.on_color()
+ if let Some(fg_color0) = init_color.fg_color()
+ && let Some(fg_color1) = colors.hover_color.fg_color()
{
- let on_color = on_color0.lerp(&common.globals().palette, &on_color1, mult);
+ let fg_color = fg_color0.lerp(&common.globals().palette, &fg_color1, mult);
if let Some(mut label) = common.state.widgets.get_as::(label) {
- label.set_color(common, on_color, true);
+ label.set_color(common, fg_color, true);
}
if let Some(mut sprite) = common.state.widgets.get_as::(sprite) {
- sprite.set_color(common, on_color);
+ sprite.set_color(common, fg_color);
}
}
@@ -628,6 +628,7 @@ pub fn construct(ess: &mut ConstructEssentials, params: Params) -> anyhow::Resul
color: Some(WguiColorName::OnBackground.into()),
..params.text_style
},
+ ..Default::default()
},
);
diff --git a/wgui/src/components/checkbox.rs b/wgui/src/components/checkbox.rs
index 7bbbb4ea..f85d3496 100644
--- a/wgui/src/components/checkbox.rs
+++ b/wgui/src/components/checkbox.rs
@@ -486,6 +486,7 @@ pub fn construct(ess: &mut ConstructEssentials, params: Params) -> anyhow::Resul
color: Some(WguiColorName::OnBackground.into()),
..Default::default()
},
+ ..Default::default()
},
);
let (label, _node_label) = ess.layout.add_child(id_container, widget_label, Default::default())?;
diff --git a/wgui/src/components/editbox.rs b/wgui/src/components/editbox.rs
index 98e1d6d9..214cc632 100644
--- a/wgui/src/components/editbox.rs
+++ b/wgui/src/components/editbox.rs
@@ -348,6 +348,7 @@ pub fn construct(
}),
..Default::default()
},
+ ..Default::default()
},
);
let (label, _node_label) = ess.layout.add_child(
diff --git a/wgui/src/components/slider.rs b/wgui/src/components/slider.rs
index aecb0559..ae322a84 100644
--- a/wgui/src/components/slider.rs
+++ b/wgui/src/components/slider.rs
@@ -686,6 +686,7 @@ fn mount_slider_handle(
align: Some(HorizontalAlign::Center),
..Default::default()
},
+ ..Default::default()
},
);
Some(ess.layout.add_child(slider_handle.id, label, Default::default())?)
diff --git a/wgui/src/components/tooltip.rs b/wgui/src/components/tooltip.rs
index 47ac5b56..d15ec048 100644
--- a/wgui/src/components/tooltip.rs
+++ b/wgui/src/components/tooltip.rs
@@ -260,6 +260,7 @@ pub fn construct(ess: &mut ConstructEssentials, params: Params) -> anyhow::Resul
weight: Some(FontWeight::Bold),
..Default::default()
},
+ ..Default::default()
},
);
diff --git a/wgui/src/parser/widget_label.rs b/wgui/src/parser/widget_label.rs
index e7e26881..0fed8c82 100644
--- a/wgui/src/parser/widget_label.rs
+++ b/wgui/src/parser/widget_label.rs
@@ -39,6 +39,9 @@ pub fn parse_widget_label<'a>(
"translation" if !value.is_empty() => {
params.content = Translation::from_translation_key(value);
}
+ "use_bg_color" if !value.is_empty() => {
+ params.use_bg_color = true;
+ }
_ => {}
}
}
diff --git a/wgui/src/widget/label.rs b/wgui/src/widget/label.rs
index 86a2b640..c54ba402 100644
--- a/wgui/src/widget/label.rs
+++ b/wgui/src/widget/label.rs
@@ -22,6 +22,7 @@ use super::{WidgetObj, WidgetState};
pub struct WidgetLabelParams {
pub content: Translation,
pub style: TextStyle,
+ pub use_bg_color: bool,
}
pub struct WidgetLabel {
@@ -119,7 +120,13 @@ impl WidgetLabel {
}
pub fn set_color(&mut self, common: &mut CallbackDataCommon, color: WguiColor, apply_to_existing_text: bool) {
- self.params.style.color = Some(color);
+ if self.params.use_bg_color {
+ if let Some(bg_color) = color.bg_color() {
+ self.params.style.color = Some(bg_color);
+ }
+ } else {
+ self.params.style.color = Some(color);
+ }
if apply_to_existing_text {
self.update_attrs(&common.globals().palette);
common.mark_widget_dirty(self.id);