Skip to content

Commit 0de4a1a

Browse files
authored
Merge pull request #168 from unsecretised/liquid-glass
Make rustcast into a frosted glass window
2 parents 3c15077 + 6f216bd commit 0de4a1a

File tree

5 files changed

+85
-76
lines changed

5 files changed

+85
-76
lines changed

src/app.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub fn default_settings() -> Settings {
7474
minimizable: false,
7575
level: window::Level::AlwaysOnTop,
7676
transparent: true,
77-
blur: false,
77+
blur: true,
7878
size: iced::Size {
7979
width: WINDOW_WIDTH,
8080
height: DEFAULT_WINDOW_HEIGHT,

src/app/pages/emoji.rs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
use iced::{Border, Length::Fill, border::Radius, widget::tooltip};
22

3-
use crate::{app::pages::prelude::*, clipboard::ClipBoardContentType, commands::Function};
3+
use crate::{
4+
app::pages::prelude::*,
5+
clipboard::ClipBoardContentType,
6+
commands::Function,
7+
styles::{glass_border, glass_surface, with_alpha},
8+
};
49

510
pub fn emoji_page(
611
tile_theme: Theme,
@@ -65,21 +70,25 @@ pub fn emoji_page(
6570
}
6671

6772
let tile_theme_clone = tile_theme.clone();
68-
6973
container(Column::from_vec(column).spacing(10))
70-
.padding(5)
71-
.style(move |_| {
72-
result_row_container_style(&tile_theme_clone, false)
73-
.background({
74-
let mut clr = tile_theme_clone.bg_color();
75-
clr.a = 1.;
76-
Background::Color(tint(clr, 0.02))
77-
})
78-
.border(Border {
79-
color: tile_theme.bg_color(),
80-
width: 1.,
81-
radius: Radius::new(0),
82-
})
74+
.padding(10)
75+
.style(move |_| container::Style {
76+
background: Some(Background::Color(glass_surface(
77+
tile_theme_clone.bg_color(),
78+
false,
79+
))),
80+
text_color: None,
81+
border: Border {
82+
color: glass_border(tile_theme_clone.text_color(1.0), false),
83+
width: 0.5,
84+
radius: Radius::new(14.0).top(0),
85+
},
86+
shadow: iced::Shadow {
87+
color: with_alpha(iced::Color::TRANSPARENT, 0.),
88+
offset: iced::Vector::new(0.0, 10.0),
89+
blur_radius: 28.0,
90+
},
91+
snap: false,
8392
})
8493
.center_x(WINDOW_WIDTH)
8594
.into()

src/app/pages/prelude.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ pub use iced::{
66
pub use crate::{
77
app::{Message, WINDOW_WIDTH, apps::App},
88
config::Theme,
9-
styles::{emoji_button_container_style, emoji_button_style, result_row_container_style, tint},
9+
styles::{emoji_button_container_style, emoji_button_style, result_row_container_style},
1010
};

src/app/tile/elm.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::app::DEFAULT_WINDOW_HEIGHT;
1717
use crate::app::pages::emoji::emoji_page;
1818
use crate::app::tile::{AppIndex, Hotkeys};
1919
use crate::config::Theme;
20-
use crate::styles::{contents_style, rustcast_text_input_style, tint, with_alpha};
20+
use crate::styles::{contents_style, glass_border, glass_surface, rustcast_text_input_style};
2121
use crate::{app::WINDOW_WIDTH, platform};
2222
use crate::{app::pages::clipboard::clipboard_view, platform::get_installed_apps};
2323
use crate::{
@@ -180,18 +180,24 @@ pub fn view(tile: &Tile, wid: window::Id) -> Element<'_, Message> {
180180
}
181181

182182
fn footer(theme: Theme, results_count: usize) -> Element<'static, Message> {
183-
let text = if results_count == 0 {
183+
if results_count == 0 {
184184
return space().into();
185-
} else if results_count == 1 {
186-
"1 result found"
185+
}
186+
187+
let text = if results_count == 1 {
188+
"1 result found".to_string()
187189
} else {
188-
&format!("{} results found", results_count)
190+
format!("{results_count} results found")
189191
};
190192

193+
// “Liquid glass” parameters (match your other styles)
194+
let focused = false;
195+
let radius = 15.0;
196+
191197
container(
192198
Row::new()
193199
.push(
194-
Text::new(text.to_string())
200+
Text::new(text)
195201
.size(12)
196202
.height(30)
197203
.color(theme.text_color(0.7))
@@ -207,15 +213,16 @@ fn footer(theme: Theme, results_count: usize) -> Element<'static, Message> {
207213
.padding(5)
208214
.style(move |_| container::Style {
209215
text_color: None,
210-
background: Some(iced::Background::Color(with_alpha(
211-
tint(theme.bg_color(), 0.04),
212-
1.0,
216+
background: Some(iced::Background::Color(glass_surface(
217+
theme.bg_color(),
218+
focused,
213219
))),
214220
border: iced::Border {
215-
color: Color::WHITE,
216-
width: 0.,
217-
radius: Radius::new(15).top(0),
221+
color: glass_border(theme.text_color(1.0), focused),
222+
width: 1.0,
223+
radius: Radius::new(radius).top(0.0),
218224
},
225+
219226
shadow: iced::Shadow {
220227
color: Color::TRANSPARENT,
221228
offset: Vector::ZERO,

src/styles.rs

Lines changed: 40 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,39 @@
1+
use crate::config::Theme as ConfigTheme;
12
use iced::border::Radius;
23
use iced::widget::{button, container};
34
use iced::{Background, Border, Color, widget::text_input};
4-
5-
use crate::config::Theme as ConfigTheme;
6-
75
/// Helper: mix base color with white (simple “tint”)
86
pub fn tint(mut c: Color, amount: f32) -> Color {
97
c.r = c.r + (1.0 - c.r) * amount;
108
c.g = c.g + (1.0 - c.g) * amount;
119
c.b = c.b + (1.0 - c.b) * amount;
1210
c
1311
}
14-
1512
/// Helper: apply alpha
1613
pub fn with_alpha(mut c: Color, a: f32) -> Color {
1714
c.a = a;
1815
c
1916
}
20-
2117
pub fn rustcast_text_input_style(
2218
theme: &ConfigTheme,
2319
round_bottom_edges: bool,
2420
) -> text_input::Style {
25-
let base_bg = theme.bg_color();
26-
let surface = with_alpha(tint(base_bg, 0.06), 1.0);
27-
28-
let border_color = theme.text_color(1.);
29-
21+
let base = theme.bg_color();
22+
let focused = false; // if you have state, pass it in and use it
23+
let surface = glass_surface(base, focused);
3024
text_input::Style {
3125
background: Background::Color(surface),
3226
border: Border {
33-
color: border_color,
34-
width: 1.,
27+
color: glass_border(theme.text_color(1.0), focused),
28+
width: 1.0,
3529
radius: Radius::new(15.).bottom(if round_bottom_edges { 15. } else { 0. }),
3630
},
37-
icon: theme.text_color(0.7),
38-
placeholder: theme.text_color(0.45),
31+
icon: theme.text_color(0.75),
32+
placeholder: theme.text_color(0.50),
3933
value: theme.text_color(1.0),
40-
selection: theme.text_color(0.2),
34+
selection: with_alpha(theme.text_color(1.0), 0.20),
4135
}
4236
}
43-
4437
pub fn contents_style(theme: &ConfigTheme) -> container::Style {
4538
container::Style {
4639
background: None,
@@ -53,62 +46,62 @@ pub fn contents_style(theme: &ConfigTheme) -> container::Style {
5346
..Default::default()
5447
}
5548
}
56-
5749
pub fn result_button_style(theme: &ConfigTheme) -> button::Style {
5850
button::Style {
5951
text_color: theme.text_color(1.),
6052
background: Some(Background::Color(theme.bg_color())),
6153
..Default::default()
6254
}
6355
}
64-
6556
pub fn result_row_container_style(tile: &ConfigTheme, focused: bool) -> container::Style {
66-
let base = tile.bg_color();
67-
let row_bg = if focused {
68-
with_alpha(tint(base, 0.10), 1.0)
69-
} else {
70-
with_alpha(tint(base, 0.04), 1.0)
71-
};
72-
7357
container::Style {
74-
background: Some(Background::Color(row_bg)),
58+
background: Some(Background::Color(glass_surface(tile.bg_color(), focused))),
7559
border: Border {
76-
color: tile.text_color(1.),
77-
width: 0.,
78-
radius: Radius::new(0.),
60+
color: glass_border(tile.text_color(1.), focused),
61+
width: 1.,
62+
radius: Radius::new(0.0),
7963
},
64+
text_color: Some(tile.text_color(1.0)),
8065
..Default::default()
8166
}
8267
}
83-
8468
pub fn emoji_button_container_style(tile_theme: &ConfigTheme, focused: bool) -> container::Style {
85-
let base = tile_theme.bg_color();
86-
let row_bg = if focused {
87-
with_alpha(tint(base, 0.10), 1.0)
88-
} else {
89-
with_alpha(tint(base, 0.04), 1.0)
90-
};
9169
container::Style {
92-
background: Some(Background::Color(row_bg)),
93-
text_color: Some(tile_theme.text_color(1.)),
70+
background: Some(Background::Color(glass_surface(
71+
tile_theme.bg_color(),
72+
focused,
73+
))),
74+
text_color: Some(tile_theme.text_color(1.0)),
9475
border: Border {
95-
color: tile_theme.text_color(0.8),
96-
width: 0.,
97-
radius: Radius::new(10),
76+
color: glass_border(tile_theme.text_color(1.0), focused),
77+
width: 1.0,
78+
radius: Radius::new(10.0),
9879
},
9980
..Default::default()
10081
}
10182
}
102-
10383
pub fn emoji_button_style(tile_theme: &ConfigTheme) -> button::Style {
84+
let base = tile_theme.bg_color();
85+
let bg = with_alpha(tint(base, 0.10), 0.28);
10486
button::Style {
105-
background: Some(Background::Color(tint(tile_theme.bg_color(), 0.02))),
106-
text_color: tile_theme.text_color(1.),
87+
background: Some(Background::Color(bg)),
88+
text_color: tile_theme.text_color(1.0),
10789
border: Border {
108-
color: tile_theme.text_color(0.8),
109-
width: 0.1,
110-
radius: Radius::new(10),
90+
color: glass_border(tile_theme.text_color(1.0), false),
91+
width: 1.0,
92+
radius: Radius::new(10.0),
11193
},
11294
..Default::default()
11395
}
11496
}
97+
98+
pub fn glass_surface(base: Color, focused: bool) -> Color {
99+
let t = if focused { 0.5 } else { 0.06 };
100+
let a = if focused { 0.5 } else { 0.22 };
101+
with_alpha(tint(base, t), a)
102+
}
103+
104+
pub fn glass_border(base_text: Color, focused: bool) -> Color {
105+
let a = if focused { 0.35 } else { 0.22 };
106+
with_alpha(base_text, a)
107+
}

0 commit comments

Comments
 (0)