Skip to content

Commit e8c0e2c

Browse files
authored
Merge pull request #172 from unsecretised/better-ui
Improve rustcast UI
2 parents 088dc3e + ae8c2c0 commit e8c0e2c

File tree

3 files changed

+31
-35
lines changed

3 files changed

+31
-35
lines changed

src/app.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use iced::window::{self, Id, Settings};
1616
pub const WINDOW_WIDTH: f32 = 500.;
1717

1818
/// The default window height
19-
pub const DEFAULT_WINDOW_HEIGHT: f32 = 80.;
19+
pub const DEFAULT_WINDOW_HEIGHT: f32 = 100.;
2020

2121
/// The rustcast descriptor name to be put for all rustcast commands
2222
pub const RUSTCAST_DESC_NAME: &str = "Utility";

src/app/tile/elm.rs

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@ pub fn new(hotkey: HotKey, config: &Config) -> (Tile, Task<Message>) {
8787

8888
pub fn view(tile: &Tile, wid: window::Id) -> Element<'_, Message> {
8989
if tile.visible {
90-
let round_bottom_edges = match &tile.page {
91-
Page::Main | Page::EmojiSearch => tile.results.is_empty(),
92-
Page::ClipboardHistory => tile.clipboard_content.is_empty(),
93-
};
9490
let title_input = text_input(tile.config.placeholder.as_str(), &tile.query)
9591
.on_input(move |a| Message::SearchQueryChanged(a, wid))
9692
.on_paste(move |a| Message::SearchQueryChanged(a, wid))
@@ -99,7 +95,7 @@ pub fn view(tile: &Tile, wid: window::Id) -> Element<'_, Message> {
9995
.id("query")
10096
.width(Fill)
10197
.line_height(LineHeight::Relative(1.75))
102-
.style(move |_, _| rustcast_text_input_style(&tile.config.theme, round_bottom_edges))
98+
.style(move |_, _| rustcast_text_input_style(&tile.config.theme))
10399
.padding(20);
104100

105101
let scrollbar_direction = if tile.config.theme.show_scroll_bar {
@@ -120,8 +116,6 @@ pub fn view(tile: &Tile, wid: window::Id) -> Element<'_, Message> {
120116
tile.config.theme.clone(),
121117
tile.focus_id,
122118
)
123-
} else if tile.results.is_empty() {
124-
space().into()
125119
} else if tile.page == Page::EmojiSearch {
126120
emoji_page(
127121
tile.config.theme.clone(),
@@ -157,14 +151,26 @@ pub fn view(tile: &Tile, wid: window::Id) -> Element<'_, Message> {
157151
.id("results")
158152
.height(height as u32);
159153

154+
let text = if !tile.query_lc.is_empty() {
155+
if results_count == 1 {
156+
"1 result found".to_string()
157+
} else if results_count == 0 {
158+
"No results found".to_string()
159+
} else {
160+
format!("{results_count} results found")
161+
}
162+
} else {
163+
String::from("♥️ Rustcast")
164+
};
165+
160166
let contents = container(
161167
Column::new()
162168
.push(title_input)
163169
.push(scrollable)
164170
.push(footer(
165171
tile.config.theme.clone(),
166-
results_count,
167172
tile.current_mode.clone(),
173+
text,
168174
))
169175
.spacing(0),
170176
)
@@ -179,27 +185,15 @@ pub fn view(tile: &Tile, wid: window::Id) -> Element<'_, Message> {
179185
..Default::default()
180186
});
181187

182-
container(contents.clip(false))
188+
container(contents)
183189
.style(|_| contents_style(&tile.config.theme))
184190
.into()
185191
} else {
186192
space().into()
187193
}
188194
}
189195

190-
fn footer(theme: Theme, results_count: usize, current_mode: String) -> Element<'static, Message> {
191-
if results_count == 0 {
192-
return space().into();
193-
}
194-
195-
let text = if results_count == 1 {
196-
"1 result found".to_string()
197-
} else {
198-
format!("{results_count} results found")
199-
};
200-
201-
// “Liquid glass” parameters (match your other styles)
202-
let focused = false;
196+
fn footer(theme: Theme, current_mode: String, text: String) -> Element<'static, Message> {
203197
let radius = 15.0;
204198

205199
let current_mode = format!(
@@ -215,6 +209,7 @@ fn footer(theme: Theme, results_count: usize, current_mode: String) -> Element<'
215209
.height(30)
216210
.color(theme.text_color(0.7))
217211
.font(theme.font())
212+
.align_y(Alignment::Center)
218213
.align_x(Alignment::Center),
219214
)
220215
.push(
@@ -224,24 +219,28 @@ fn footer(theme: Theme, results_count: usize, current_mode: String) -> Element<'
224219
.color(theme.text_color(0.7))
225220
.font(theme.font())
226221
.width(Fill)
222+
.align_y(Alignment::Center)
227223
.align_x(Alignment::End),
228224
)
225+
.align_y(Alignment::Center)
229226
.padding(4)
230227
.width(Fill)
231-
.height(30),
228+
.height(Fill),
232229
)
230+
.align_y(Alignment::Center)
233231
.center(Length::Fill)
234232
.width(WINDOW_WIDTH)
235233
.padding(5)
234+
.height(30)
236235
.style(move |_| container::Style {
237236
text_color: None,
238237
background: Some(iced::Background::Color(glass_surface(
239238
theme.bg_color(),
240-
focused,
239+
false,
241240
))),
242241
border: iced::Border {
243-
color: glass_border(theme.text_color(1.0), focused),
244-
width: 1.0,
242+
color: glass_border(theme.text_color(1.0), false),
243+
width: 0.,
245244
radius: Radius::new(radius).top(0.0),
246245
},
247246

src/styles.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,16 @@ pub fn with_alpha(mut c: Color, a: f32) -> Color {
1414
c.a = a;
1515
c
1616
}
17-
pub fn rustcast_text_input_style(
18-
theme: &ConfigTheme,
19-
round_bottom_edges: bool,
20-
) -> text_input::Style {
17+
pub fn rustcast_text_input_style(theme: &ConfigTheme) -> text_input::Style {
2118
let base = theme.bg_color();
2219
let focused = false; // if you have state, pass it in and use it
2320
let surface = glass_surface(base, focused);
2421
text_input::Style {
2522
background: Background::Color(surface),
2623
border: Border {
2724
color: glass_border(theme.text_color(1.0), focused),
28-
width: 1.0,
29-
radius: Radius::new(15.).bottom(if round_bottom_edges { 15. } else { 0. }),
25+
width: 0.,
26+
radius: Radius::new(15.).bottom(0.),
3027
},
3128
icon: theme.text_color(0.75),
3229
placeholder: theme.text_color(0.50),
@@ -40,7 +37,7 @@ pub fn contents_style(theme: &ConfigTheme) -> container::Style {
4037
text_color: None,
4138
border: iced::Border {
4239
color: theme.text_color(0.7),
43-
width: 0.,
40+
width: 0.4,
4441
radius: Radius::new(14.0),
4542
},
4643
..Default::default()
@@ -58,7 +55,7 @@ pub fn result_row_container_style(tile: &ConfigTheme, focused: bool) -> containe
5855
background: Some(Background::Color(glass_surface(tile.bg_color(), focused))),
5956
border: Border {
6057
color: glass_border(tile.text_color(1.), focused),
61-
width: 1.,
58+
width: 0.,
6259
radius: Radius::new(0.0),
6360
},
6461
text_color: Some(tile.text_color(1.0)),

0 commit comments

Comments
 (0)