From ae8c2c0d83af453d5e3283a3bc5c93e385036634 Mon Sep 17 00:00:00 2001 From: unsecretised Date: Tue, 3 Mar 2026 22:57:33 +0800 Subject: [PATCH] Improve rustcast UI --- src/app.rs | 2 +- src/app/tile/elm.rs | 51 ++++++++++++++++++++++----------------------- src/styles.rs | 13 +++++------- 3 files changed, 31 insertions(+), 35 deletions(-) diff --git a/src/app.rs b/src/app.rs index 41773d8..904b7d4 100644 --- a/src/app.rs +++ b/src/app.rs @@ -16,7 +16,7 @@ use iced::window::{self, Id, Settings}; pub const WINDOW_WIDTH: f32 = 500.; /// The default window height -pub const DEFAULT_WINDOW_HEIGHT: f32 = 80.; +pub const DEFAULT_WINDOW_HEIGHT: f32 = 100.; /// The rustcast descriptor name to be put for all rustcast commands pub const RUSTCAST_DESC_NAME: &str = "Utility"; diff --git a/src/app/tile/elm.rs b/src/app/tile/elm.rs index 5dcc1f4..c88c466 100644 --- a/src/app/tile/elm.rs +++ b/src/app/tile/elm.rs @@ -87,10 +87,6 @@ pub fn new(hotkey: HotKey, config: &Config) -> (Tile, Task) { pub fn view(tile: &Tile, wid: window::Id) -> Element<'_, Message> { if tile.visible { - let round_bottom_edges = match &tile.page { - Page::Main | Page::EmojiSearch => tile.results.is_empty(), - Page::ClipboardHistory => tile.clipboard_content.is_empty(), - }; let title_input = text_input(tile.config.placeholder.as_str(), &tile.query) .on_input(move |a| Message::SearchQueryChanged(a, wid)) .on_paste(move |a| Message::SearchQueryChanged(a, wid)) @@ -99,7 +95,7 @@ pub fn view(tile: &Tile, wid: window::Id) -> Element<'_, Message> { .id("query") .width(Fill) .line_height(LineHeight::Relative(1.75)) - .style(move |_, _| rustcast_text_input_style(&tile.config.theme, round_bottom_edges)) + .style(move |_, _| rustcast_text_input_style(&tile.config.theme)) .padding(20); let scrollbar_direction = if tile.config.theme.show_scroll_bar { @@ -120,8 +116,6 @@ pub fn view(tile: &Tile, wid: window::Id) -> Element<'_, Message> { tile.config.theme.clone(), tile.focus_id, ) - } else if tile.results.is_empty() { - space().into() } else if tile.page == Page::EmojiSearch { emoji_page( tile.config.theme.clone(), @@ -157,14 +151,26 @@ pub fn view(tile: &Tile, wid: window::Id) -> Element<'_, Message> { .id("results") .height(height as u32); + let text = if !tile.query_lc.is_empty() { + if results_count == 1 { + "1 result found".to_string() + } else if results_count == 0 { + "No results found".to_string() + } else { + format!("{results_count} results found") + } + } else { + String::from("♥️ Rustcast") + }; + let contents = container( Column::new() .push(title_input) .push(scrollable) .push(footer( tile.config.theme.clone(), - results_count, tile.current_mode.clone(), + text, )) .spacing(0), ) @@ -179,7 +185,7 @@ pub fn view(tile: &Tile, wid: window::Id) -> Element<'_, Message> { ..Default::default() }); - container(contents.clip(false)) + container(contents) .style(|_| contents_style(&tile.config.theme)) .into() } else { @@ -187,19 +193,7 @@ pub fn view(tile: &Tile, wid: window::Id) -> Element<'_, Message> { } } -fn footer(theme: Theme, results_count: usize, current_mode: String) -> Element<'static, Message> { - if results_count == 0 { - return space().into(); - } - - let text = if results_count == 1 { - "1 result found".to_string() - } else { - format!("{results_count} results found") - }; - - // “Liquid glass” parameters (match your other styles) - let focused = false; +fn footer(theme: Theme, current_mode: String, text: String) -> Element<'static, Message> { let radius = 15.0; let current_mode = format!( @@ -215,6 +209,7 @@ fn footer(theme: Theme, results_count: usize, current_mode: String) -> Element<' .height(30) .color(theme.text_color(0.7)) .font(theme.font()) + .align_y(Alignment::Center) .align_x(Alignment::Center), ) .push( @@ -224,24 +219,28 @@ fn footer(theme: Theme, results_count: usize, current_mode: String) -> Element<' .color(theme.text_color(0.7)) .font(theme.font()) .width(Fill) + .align_y(Alignment::Center) .align_x(Alignment::End), ) + .align_y(Alignment::Center) .padding(4) .width(Fill) - .height(30), + .height(Fill), ) + .align_y(Alignment::Center) .center(Length::Fill) .width(WINDOW_WIDTH) .padding(5) + .height(30) .style(move |_| container::Style { text_color: None, background: Some(iced::Background::Color(glass_surface( theme.bg_color(), - focused, + false, ))), border: iced::Border { - color: glass_border(theme.text_color(1.0), focused), - width: 1.0, + color: glass_border(theme.text_color(1.0), false), + width: 0., radius: Radius::new(radius).top(0.0), }, diff --git a/src/styles.rs b/src/styles.rs index 5a54c7e..c1cad8c 100644 --- a/src/styles.rs +++ b/src/styles.rs @@ -14,10 +14,7 @@ pub fn with_alpha(mut c: Color, a: f32) -> Color { c.a = a; c } -pub fn rustcast_text_input_style( - theme: &ConfigTheme, - round_bottom_edges: bool, -) -> text_input::Style { +pub fn rustcast_text_input_style(theme: &ConfigTheme) -> text_input::Style { let base = theme.bg_color(); let focused = false; // if you have state, pass it in and use it let surface = glass_surface(base, focused); @@ -25,8 +22,8 @@ pub fn rustcast_text_input_style( background: Background::Color(surface), border: Border { color: glass_border(theme.text_color(1.0), focused), - width: 1.0, - radius: Radius::new(15.).bottom(if round_bottom_edges { 15. } else { 0. }), + width: 0., + radius: Radius::new(15.).bottom(0.), }, icon: theme.text_color(0.75), placeholder: theme.text_color(0.50), @@ -40,7 +37,7 @@ pub fn contents_style(theme: &ConfigTheme) -> container::Style { text_color: None, border: iced::Border { color: theme.text_color(0.7), - width: 0., + width: 0.4, radius: Radius::new(14.0), }, ..Default::default() @@ -58,7 +55,7 @@ pub fn result_row_container_style(tile: &ConfigTheme, focused: bool) -> containe background: Some(Background::Color(glass_surface(tile.bg_color(), focused))), border: Border { color: glass_border(tile.text_color(1.), focused), - width: 1., + width: 0., radius: Radius::new(0.0), }, text_color: Some(tile.text_color(1.0)),