Newer
Older
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
use crate::egui::style::WidgetVisuals;
use eframe::egui::{Color32, InnerResponse, Style, Ui};
/// Reduces the alpha of a color (how opaque it is) by a factor.
pub fn set_alpha(color: Color32, factor: f32) -> Color32 {
if factor == 1.0 {
// Fast/common path.
color
} else {
color.linear_multiply(factor)
}
}
/// Same as [`multiply_alpha`], but operates in place.
pub fn set_alpha_in_place(color: &mut Color32, factor: f32) {
assert!(factor >= 0.0 && factor <= 1.0);
*color = set_alpha(*color, factor);
}
/// Changes alpha of entire widget style.
fn set_widget_alpha_in_place(widget: &mut WidgetVisuals, factor: f32) {
set_alpha_in_place(&mut widget.bg_fill, factor);
set_alpha_in_place(&mut widget.bg_stroke.color, factor);
set_alpha_in_place(&mut widget.fg_stroke.color, factor);
}
/// Changes alpha of entire style.
pub fn set_style_alpha(style: &Style, factor: f32) -> Style {
let mut clone = style.clone();
set_style_alpha_in_place(&mut clone, factor);
clone
}
/// Changes alpha of entire style, in place.
pub fn set_style_alpha_in_place(style: &mut Style, factor: f32) {
if factor == 1.0 {
// Common/fast path.
return;
}
let widgets = &mut style.visuals.widgets;
for widget in [
&mut widgets.noninteractive,
&mut widgets.inactive,
&mut widgets.hovered,
&mut widgets.active,
&mut widgets.open,
] {
set_widget_alpha_in_place(widget, factor);
}
set_alpha_in_place(&mut style.visuals.hyperlink_color, factor);
set_alpha_in_place(&mut style.visuals.faint_bg_color, factor);
set_alpha_in_place(&mut style.visuals.extreme_bg_color, factor);
set_alpha_in_place(&mut style.visuals.code_bg_color, factor);
set_alpha_in_place(&mut style.visuals.window_shadow.color, factor);
//style.visuals.widgets.noninteractive.bg_fill = Color32::TRANSPARENT;
}
/// Render some children with the specified alpha from 0 to 1.