From a2fad4569a5a9e84316a07b13240f9d9c3ebb376 Mon Sep 17 00:00:00 2001 From: faumaray Date: Tue, 27 Oct 2026 07:15:31 +0300 Subject: [PATCH] voelin-gpui: the backdrop's GPUI gradient in one place (Backdrop::to_gpui) GPUI's gradient has two colour stops and the Slint backdrop three, so what GPUI draws is the first and the last; that choice was written inline in the swatch page. It is a method of the token now (theme/mod.rs), with a test that it is the gradient of the first and the last stops and not of the middle one, and the swatch calls it. No change on screen. Checked on Rust 1.95.0: fmt, clippy -D warnings --no-deps (all targets), `cargo test -p voelin-gpui` (31 tests). Co-Authored-By: Claude Sonnet 5.5 --- crates/voelin-gpui/src/swatch.rs | 10 ++----- crates/voelin-gpui/src/theme/mod.rs | 38 +++++++++++++++++++++++++- crates/voelin-gpui/src/theme/tokens.rs | 4 +-- 3 files changed, 41 insertions(+), 11 deletions(-) diff --git a/crates/voelin-gpui/src/swatch.rs b/crates/voelin-gpui/src/swatch.rs index bce5169..fedd8ab 100644 --- a/crates/voelin-gpui/src/swatch.rs +++ b/crates/voelin-gpui/src/swatch.rs @@ -11,7 +11,7 @@ use gpui_kit::component::checkbox::Checkbox; use gpui_kit::component::switch::Switch; use gpui_kit::{ FontWeight, InteractiveElement as _, IntoElement, ParentElement as _, - StatefulInteractiveElement as _, Styled as _, div, linear_color_stop, linear_gradient, px, svg, + StatefulInteractiveElement as _, Styled as _, div, px, svg, }; use crate::theme::{VoelinTheme, hsla, tokens::Rgba}; @@ -268,19 +268,13 @@ fn components(theme: &VoelinTheme) -> impl IntoElement { fn backdrop(theme: &VoelinTheme) -> impl IntoElement { let (c, m, b) = (&theme.colors, &theme.metrics, &theme.backdrop); let [first, _, last] = b.stops; - // GPUI's gradient has two colour stops: the first and the last of three. - let gradient = linear_gradient( - b.angle, - linear_color_stop(hsla(first.0), first.1), - linear_color_stop(hsla(last.0), last.1), - ); div().flex().flex_col().gap(px(m.space_3)).child(heading(theme, "Backdrop")).child( div() .h(px(36.0)) .rounded(px(m.radius_md)) .border_1() .border_color(hsla(c.border)) - .bg(gradient) + .bg(b.to_gpui()) .px(px(m.space_3)) .py(px(m.space_2)) .text_size(px(m.font_xs)) diff --git a/crates/voelin-gpui/src/theme/mod.rs b/crates/voelin-gpui/src/theme/mod.rs index d8866ab..c4a02ea 100644 --- a/crates/voelin-gpui/src/theme/mod.rs +++ b/crates/voelin-gpui/src/theme/mod.rs @@ -18,9 +18,22 @@ pub mod tokens; pub use components::hsla; use gpui_kit::component::{Theme, ThemeMode}; -use gpui_kit::{App, Global, WindowAppearance, px}; +use gpui_kit::{App, Background, Global, WindowAppearance, linear_color_stop, linear_gradient, px}; pub use tokens::{Backdrop, FONT_FAMILY, Metrics, Palette, Rgba}; +impl Backdrop { + /// What GPUI draws: its gradient has two colour stops, so the first and the + /// last of the three; the middle one is not drawn. + pub fn to_gpui(&self) -> Background { + let [first, _, last] = self.stops; + linear_gradient( + self.angle, + linear_color_stop(hsla(first.0), first.1), + linear_color_stop(hsla(last.0), last.1), + ) + } +} + /// The theme mode setting (`ui.theme` of the Slint front end). #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum Choice { @@ -206,6 +219,29 @@ mod tests { assert!(is_dark(WindowAppearance::VibrantDark) && !is_dark(WindowAppearance::VibrantLight)); } + #[test] + fn the_backdrop_draws_the_first_and_the_last_of_its_three_stops() { + let b = Backdrop::DARK; + let [first, middle, last] = b.stops; + assert_eq!( + b.to_gpui(), + linear_gradient( + 160.0, + linear_color_stop(hsla(first.0), 0.0), + linear_color_stop(hsla(last.0), 1.0) + ) + ); + assert_ne!( + b.to_gpui(), + linear_gradient( + 160.0, + linear_color_stop(hsla(first.0), 0.0), + linear_color_stop(hsla(middle.0), 1.0) + ), + "the middle stop is not the end one" + ); + } + #[gpui::test] fn the_tokens_reach_gpui_component(cx: &mut TestAppContext) { start(cx, Choice::Dark, WindowAppearance::Light); diff --git a/crates/voelin-gpui/src/theme/tokens.rs b/crates/voelin-gpui/src/theme/tokens.rs index 39751bf..dc341d6 100644 --- a/crates/voelin-gpui/src/theme/tokens.rs +++ b/crates/voelin-gpui/src/theme/tokens.rs @@ -150,8 +150,8 @@ palette! { /// `@linear-gradient(angle, stop 0%, stop 55%, stop 100%)`: the window's /// backdrop. GPUI's `Background` has two colour stops, so what it draws -/// ([`Backdrop::to_gpui`]) is the first and the last; the middle one stays -/// here for the front end that can use it. +/// (`Backdrop::to_gpui`, in the theme module) is the first and the last; the +/// middle one stays here for a front end that can use it. #[derive(Clone, Copy, Debug, PartialEq)] pub struct Backdrop { /// The direction in degrees, as CSS and Slint take it (0 is to the top).