git.lucas.co / cce-ui
GPU-accelerated UI toolkit (Vulkan)
git clone https://git.lucas.co/cce-ui.git

commit75f713247f7174afc43341a9a278bf4f36c90363
parentbe3a7c0ac1
authorLucas Galante <[email protected]>
date2026-07-30 15:56
refactor: drop toggle button_color/button_opacity — state colors own the slide button

The slide button's fill is simply the disabled→enabled state colors
(rgba) crossfaded by position, used verbatim: their alpha channel is the
button's opacity. With enabled_color/disabled_color configurable (and
winning over the border fallback since be3a7c0), a separate button_color
key was redundant, and button_opacity with it.

Co-Authored-By: Claude Fable 5 <[email protected]>

 src/color.rs                 | 19 -------------------
 src/layout.rs                |  8 --------
 src/widget/input/checkbox.rs | 16 ++++++----------
 3 files changed, 6 insertions(+), 37 deletions(-)

diff --git a/src/color.rs b/src/color.rs
index 0349f57..67e3d64 100644
--- a/src/color.rs
+++ b/src/color.rs
@@ -43,7 +43,6 @@ static BACKPLATE_OPACITY: RwLock<Option<f32>> = RwLock::new(None);
 static TOGGLE_ON_COLOR: RwLock<[f32; 4]> = RwLock::new(TOGGLE_ON);
 static TOGGLE_OFF_COLOR: RwLock<[f32; 4]> = RwLock::new(TOGGLE_OFF);
 static TOGGLE_BG_COLOR: RwLock<[f32; 4]> = RwLock::new([0.18, 0.18, 0.22, 1.0]);
-static TOGGLE_BUTTON_COLOR: RwLock<Option<[f32; 4]>> = RwLock::new(None);
 static LIST_BG_COLOR: RwLock<[f32; 4]> = RwLock::new([0.08, 0.08, 0.12, 0.3]);
 static LIST_ENTRY_BG_COLOR: RwLock<[f32; 4]> = RwLock::new([1.0, 1.0, 1.0, 0.04]);
 static LIST_ENTRY_HIGHLIGHT_COLOR: RwLock<[f32; 4]> = RwLock::new([1.0, 1.0, 1.0, 0.8]);
@@ -382,9 +381,6 @@ fn parse_and_set_colors(content: &str) {
     if let Some(c) = get_color("/style/control/toggle/background_color").or_else(|| get_color("/layout/toggle_bg_color")) {
         if let Ok(mut lock) = TOGGLE_BG_COLOR.write() { *lock = c; }
     }
-    if let Some(c) = get_color("/style/control/toggle/button_color") {
-        if let Ok(mut lock) = TOGGLE_BUTTON_COLOR.write() { *lock = Some(c); }
-    }
     if let Some(c) = get_color("/style/control/ramp/background") {
         if let Ok(mut lock) = RAMP_BACKGROUND_COLOR.write() { *lock = c; }
     }
@@ -1189,21 +1185,6 @@ pub fn set_toggle_bg_color(color: [f32; 4]) {
     }
 }
 
-/// Optional dedicated fill for the slide toggle's gliding button
-/// (`style.control.toggle.button_color`). `None` → the button falls back to
-/// crossfading the on/off state colors. Only the button reads this — the
-/// track, border, and state colors are untouched.
-pub fn toggle_button_color() -> Option<[f32; 4]> {
-    load_colors_once();
-    *TOGGLE_BUTTON_COLOR.read().unwrap()
-}
-
-pub fn set_toggle_button_color(color: Option<[f32; 4]>) {
-    if let Ok(mut lock) = TOGGLE_BUTTON_COLOR.write() {
-        *lock = color;
-    }
-}
-
 pub fn list_bg_color() -> [f32; 4] {
     load_colors_once();
     *LIST_BG_COLOR.read().unwrap()
diff --git a/src/layout.rs b/src/layout.rs
index 720c0b9..f960af0 100644
--- a/src/layout.rs
+++ b/src/layout.rs
@@ -107,7 +107,6 @@ fn flatten_json_to_flat_props(val: &serde_json::Value, prefix: &str, flat_props:
                 "style.control.textbox.multiline.line_wrap" | "style.textbox.multiline.line_wrap" | "style.data.textbox.multiline.line_wrap" => "textbox_line_wrap",
                 "style.control.textbox.multiline.border_width" | "style.textbox.multiline.border_width" | "style.data.textbox.multiline.border_width" => "textbox_multiline_border_width",
                 "style.control.toggle.style" => "toggle_style",
-                "style.control.toggle.button_opacity" => "toggle_button_opacity",
                 "style.control.toggle.height" => "toggle_height",
                 "style.control.toggle.border_width" => "toggle_border_width",
                 "style.control.toggle.disabled_color" => "toggle_disabled_color",
@@ -1789,13 +1788,6 @@ pub fn toggle_slide() -> bool {
         .is_some_and(|s| s == "slide")
 }
 
-/// The slide toggle button's fill opacity (`style.control.toggle.button_opacity`):
-/// a mostly-transparent glass tint over the track — the beveled rim carries the
-/// button's read.
-pub fn toggle_button_opacity() -> f32 {
-    lazy_init_style_registry();
-    get_style_registry().read().unwrap().get_float("toggle_button_opacity").unwrap_or(0.25)
-}
 
 /// The slider's render style: `style.control.slider.style = "band"` swaps the
 /// track/fill/thumb for a thin full-range band that inflates smoothly at the
diff --git a/src/widget/input/checkbox.rs b/src/widget/input/checkbox.rs
index 299b634..fd3efca 100644
--- a/src/widget/input/checkbox.rs
+++ b/src/widget/input/checkbox.rs
@@ -290,16 +290,12 @@ impl Toggle {
         })
     }
 
-    /// The slide button's face color. `style.control.toggle.button_color`
-    /// (rgba) is used verbatim when set — its alpha channel IS the button's
-    /// opacity, and it recolors ONLY the button. Unset, the off/on state
-    /// colors crossfade by the animated position, knocked down to a glass
-    /// tint by `style.control.toggle.button_opacity`: the beveled edges
-    /// carry the button's read, the fill is a whisper over the track.
+    /// The slide button's face color: the disabled/enabled state colors
+    /// (rgba) crossfaded by the animated position, so the fill morphs while
+    /// the button glides. The colors are used verbatim — their alpha channel
+    /// IS the button's opacity, so a glass tint is a low-alpha state color
+    /// (the beveled edges carry the button's read either way).
     pub fn slide_button_color(&self) -> [f32; 4] {
-        if let Some(c) = colors::toggle_button_color() {
-            return c;
-        }
         let off = colors::toggle_off_color();
         let on = colors::toggle_on_color();
         let t = self.slide_t;
@@ -307,7 +303,7 @@ impl Toggle {
             off[0] + (on[0] - off[0]) * t,
             off[1] + (on[1] - off[1]) * t,
             off[2] + (on[2] - off[2]) * t,
-            (off[3] + (on[3] - off[3]) * t) * crate::layout::toggle_button_opacity(),
+            off[3] + (on[3] - off[3]) * t,
         ]
     }