1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
//! [`UiEffectHelpers`] — UI-effect convenience helpers (hover, active, glass).
//!
//! Composite methods for hover/active/glass patterns.
//! Default impls use solid colour only. Backends that support blur override
//! the blur-specific methods (`draw_blur_background`, `has_blur_background`,
//! `use_convex_glass_buttons`, `draw_glass_button_3d`) with real implementations.
//!
//! This trait lives in the `RenderContext` supertrait chain so all methods are
//! reachable via `&mut dyn RenderContext` — no downcasting required.
use super::shape_helpers::ShapeHelpers;
/// UI-effect convenience helpers — composite methods for hover/active/glass patterns.
///
/// All methods have default impls. Backends that support backdrop blur
/// override the blur-query and blur-draw methods.
///
/// Tessera widgets call these instead of branching on `has_blur_background()`.
pub trait UiEffectHelpers: ShapeHelpers {
// =========================================================================
// Blur queries + draw (no-op defaults; backends with real blur override)
// =========================================================================
/// Draw blurred background for UI elements (FrostedGlass/LiquidGlass effects).
///
/// Default: no-op. Override in GPU backends that load a blur image.
fn draw_blur_background(&mut self, x: f64, y: f64, width: f64, height: f64) {
let _ = (x, y, width, height);
}
/// Snapshot-blur the pixels already under this rect, then the caller
/// paints a translucent fill on top. Overlay chrome only — not the
/// chart pane / scales / toolbars (those keep using `draw_blur_background`).
///
/// Default: no-op.
fn blur_overlay_backdrop(&mut self, x: f64, y: f64, width: f64, height: f64) {
let _ = (x, y, width, height);
}
/// Blur the pixels already painted under the rect `(x, y, width, height)` (in the
/// current user space) with a `blur`-px radius, inside rounded corners of radius
/// `corner`: the backdrop of a CSS `backdrop-filter: blur()` box. The caller paints
/// a translucent fill over it.
///
/// Default: no-op (the translucent fill alone). CPU and canvas backends override.
fn blur_backdrop(&mut self, x: f64, y: f64, width: f64, height: f64, blur: f64, corner: f64) {
let _ = (x, y, width, height, blur, corner);
}
/// Returns `true` when a blur image is loaded and ready for drawing.
///
/// Default: `false`. Override in backends that support blur.
fn has_blur_background(&self) -> bool {
false
}
/// Returns `true` when blur is active AND convex glass button style is enabled.
///
/// Default: `false`.
fn use_convex_glass_buttons(&self) -> bool {
false
}
/// Draw a 3D convex glass button effect.
///
/// Default: blur background + fill_rounded_rect with `color`.
/// GPU backends override with full specular/gradient/shadow 3D effect.
#[allow(clippy::too_many_arguments)]
fn draw_glass_button_3d(
&mut self,
x: f64,
y: f64,
width: f64,
height: f64,
radius: f64,
_is_active: bool,
color: &str,
) {
self.draw_blur_background(x, y, width, height);
self.set_fill_color(color);
self.fill_rounded_rect(x, y, width, height, radius);
}
// =========================================================================
// Hover / active states
// =========================================================================
/// Draw a hover state rectangle.
///
/// Branches on blur/glass state: 3D glass → flat glass → solid.
fn draw_hover_rect(&mut self, x: f64, y: f64, width: f64, height: f64, color: &str) {
if self.use_convex_glass_buttons() {
self.draw_glass_button_3d(x, y, width, height, 2.0, false, color);
} else if self.has_blur_background() {
self.draw_blur_background(x, y, width, height);
self.set_fill_color(color);
self.fill_rect(x, y, width, height);
} else {
self.set_fill_color(color);
self.fill_rect(x, y, width, height);
}
}
/// Draw an active/pressed state rectangle.
fn draw_active_rect(&mut self, x: f64, y: f64, width: f64, height: f64, color: &str) {
if self.use_convex_glass_buttons() {
self.draw_glass_button_3d(x, y, width, height, 2.0, true, color);
} else if self.has_blur_background() {
self.draw_blur_background(x, y, width, height);
self.set_fill_color(color);
self.fill_rect(x, y, width, height);
} else {
self.set_fill_color(color);
self.fill_rect(x, y, width, height);
}
}
/// Draw a hover state rounded rectangle.
fn draw_hover_rounded_rect(
&mut self,
x: f64,
y: f64,
width: f64,
height: f64,
radius: f64,
color: &str,
) {
if self.use_convex_glass_buttons() {
self.draw_glass_button_3d(x, y, width, height, radius, false, color);
} else if self.has_blur_background() {
self.draw_blur_background(x, y, width, height);
self.set_fill_color(color);
self.fill_rounded_rect(x, y, width, height, radius);
} else {
self.set_fill_color(color);
self.fill_rounded_rect(x, y, width, height, radius);
}
}
/// Draw an active/pressed state rounded rectangle.
fn draw_active_rounded_rect(
&mut self,
x: f64,
y: f64,
width: f64,
height: f64,
radius: f64,
color: &str,
) {
if self.use_convex_glass_buttons() {
self.draw_glass_button_3d(x, y, width, height, radius, true, color);
} else if self.has_blur_background() {
self.draw_blur_background(x, y, width, height);
self.set_fill_color(color);
self.fill_rounded_rect(x, y, width, height, radius);
} else {
self.set_fill_color(color);
self.fill_rounded_rect(x, y, width, height, radius);
}
}
/// Draw a sidebar hover item with a vertical accent indicator on the left.
#[allow(clippy::too_many_arguments)]
fn draw_sidebar_hover_item(
&mut self,
x: f64,
y: f64,
width: f64,
height: f64,
accent_color: &str,
bg_color: &str,
indicator_width: f64,
) {
self.set_fill_color(accent_color);
self.fill_rect(x, y, indicator_width, height);
self.draw_hover_rect(x + indicator_width, y, width - indicator_width, height, bg_color);
}
/// Draw a sidebar active item with a vertical accent indicator on the left.
#[allow(clippy::too_many_arguments)]
fn draw_sidebar_active_item(
&mut self,
x: f64,
y: f64,
width: f64,
height: f64,
accent_color: &str,
bg_color: &str,
indicator_width: f64,
) {
self.set_fill_color(accent_color);
self.fill_rect(x, y, indicator_width, height);
self.draw_active_rect(x + indicator_width, y, width - indicator_width, height, bg_color);
}
}