Skip to repository content

tenant.openagents/omega

No repository description is available.

OpenAgents Git authority 2026-07-28T06:31:58.813Z Public web read
NIP-34 coordinate30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omega
MaintainersHidden in public view
References2 branches · 1 tag
Read-only clonegit clone https://openagents.com/git/tenant.openagents/omega.git
Browse files

gradient_fade.rs

101 lines · 3.0 KB · rust
1use gpui::{Hsla, Pixels, SharedString, linear_color_stop, linear_gradient, px};
2
3use crate::prelude::*;
4
5/// A gradient overlay that fades from a solid color to transparent.
6#[derive(IntoElement)]
7pub struct GradientFade {
8    base_bg: Hsla,
9    hover_bg: Hsla,
10    active_bg: Hsla,
11    width: Pixels,
12    width_hovered: Option<Pixels>,
13    right: Pixels,
14    gradient_stop: f32,
15    group_name: Option<SharedString>,
16}
17
18impl GradientFade {
19    pub fn new(base_bg: Hsla, hover_bg: Hsla, active_bg: Hsla) -> Self {
20        Self {
21            base_bg,
22            hover_bg,
23            active_bg,
24            width: px(48.0),
25            right: px(0.0),
26            gradient_stop: 0.6,
27            group_name: None,
28            width_hovered: None,
29        }
30    }
31
32    pub fn width(mut self, width: Pixels) -> Self {
33        self.width = width;
34        self
35    }
36
37    pub fn width_hovered(mut self, width: Pixels) -> Self {
38        self.width_hovered = Some(width);
39        self
40    }
41
42    pub fn right(mut self, right: Pixels) -> Self {
43        self.right = right;
44        self
45    }
46
47    pub fn gradient_stop(mut self, stop: f32) -> Self {
48        self.gradient_stop = stop;
49        self
50    }
51
52    pub fn group_name(mut self, name: impl Into<SharedString>) -> Self {
53        self.group_name = Some(name.into());
54        self
55    }
56}
57
58impl RenderOnce for GradientFade {
59    fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
60        let stop = self.gradient_stop;
61
62        // Best-effort to flatten potentially-transparent colors to opaque ones.
63        let app_bg = cx.theme().colors().background;
64        let base_bg = app_bg.blend(self.base_bg);
65        let hover_bg = app_bg.blend(self.hover_bg);
66        let active_bg = app_bg.blend(self.active_bg);
67
68        div()
69            .id("gradient_fade")
70            .absolute()
71            .top_0()
72            .right(self.right)
73            .w(self.width)
74            .h_full()
75            .bg(linear_gradient(
76                90.,
77                linear_color_stop(base_bg, stop),
78                linear_color_stop(base_bg.opacity(0.0), 0.),
79            ))
80            .when_some(self.group_name.clone(), |element, group_name| {
81                element.group_hover(group_name, move |s| {
82                    s.bg(linear_gradient(
83                        90.,
84                        linear_color_stop(hover_bg, stop),
85                        linear_color_stop(hover_bg.opacity(0.0), 0.),
86                    ))
87                    .w(self.width_hovered.unwrap_or(self.width))
88                })
89            })
90            .when_some(self.group_name, |element, group_name| {
91                element.group_active(group_name, move |s| {
92                    s.bg(linear_gradient(
93                        90.,
94                        linear_color_stop(active_bg, stop),
95                        linear_color_stop(active_bg.opacity(0.0), 0.),
96                    ))
97                })
98            })
99    }
100}
101
Served at tenant.openagents/omega Member data and write actions are omitted.