Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub fn default_settings() -> Settings {
minimizable: false,
level: window::Level::AlwaysOnTop,
transparent: true,
blur: true,
blur: false,
size: iced::Size {
width: WINDOW_WIDTH,
height: DEFAULT_WINDOW_HEIGHT,
Expand Down
10 changes: 5 additions & 5 deletions src/app/pages/clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub fn clipboard_view(
) -> Element<'static, Message> {
let theme_clone = theme.clone();
let theme_clone_2 = theme.clone();
Row::from_vec(vec![
container(Row::from_vec(vec![
container(
scrollable(
Column::from_iter(clipboard_content.iter().enumerate().map(|(i, content)| {
Expand All @@ -23,7 +23,7 @@ pub fn clipboard_view(
)
.id("results"),
)
.height(7 * 55)
.height(385)
.style(move |_| result_row_container_style(&theme_clone_2, false))
.into(),
container(Scrollable::with_direction(
Expand All @@ -33,7 +33,7 @@ pub fn clipboard_view(
.map(|x| x.to_app().name_lc)
.unwrap_or("".to_string()),
)
.height(Length::Fill)
.height(385)
.width(Length::Fill)
.align_x(Alignment::Start)
.font(theme.font())
Expand All @@ -46,8 +46,8 @@ pub fn clipboard_view(
.padding(10)
.style(move |_| result_row_container_style(&theme_clone, false))
.width((WINDOW_WIDTH / 3.) * 2.)
.height(7 * 55)
.into(),
])
]))
.height(280)
.into()
}
116 changes: 96 additions & 20 deletions src/app/tile/elm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use global_hotkey::hotkey::HotKey;
use iced::border::Radius;
use iced::widget::scrollable::{Anchor, Direction, Scrollbar};
use iced::widget::text::LineHeight;
use iced::widget::{Column, Scrollable, container, space};
use iced::{Color, window};
use iced::widget::{Column, Row, Scrollable, Text, container, space};
use iced::{Alignment, Color, Length, Vector, window};
use iced::{Element, Task};
use iced::{Length::Fill, widget::text_input};

Expand All @@ -15,10 +15,12 @@ use rayon::{
slice::ParallelSliceMut,
};

use crate::app::WINDOW_WIDTH;
use crate::app::pages::clipboard::clipboard_view;
use crate::app::pages::emoji::emoji_page;
use crate::app::tile::AppIndex;
use crate::styles::{contents_style, rustcast_text_input_style};
use crate::config::Theme;
use crate::styles::{contents_style, rustcast_text_input_style, tint, with_alpha};
use crate::{
app::{Message, Page, apps::App, default_settings, tile::Tile},
config::Config,
Expand Down Expand Up @@ -88,6 +90,10 @@ pub fn new(hotkey: HotKey, config: &Config) -> (Tile, Task<Message>) {

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))
Expand All @@ -96,7 +102,7 @@ pub fn view(tile: &Tile, wid: window::Id) -> Element<'_, Message> {
.id("query")
.width(Fill)
.line_height(LineHeight::Relative(1.75))
.style(|_, status| rustcast_text_input_style(&tile.config.theme, status))
.style(move |_, _| rustcast_text_input_style(&tile.config.theme, round_bottom_edges))
.padding(20);

let scrollbar_direction = if tile.config.theme.show_scroll_bar {
Expand Down Expand Up @@ -129,25 +135,48 @@ pub fn view(tile: &Tile, wid: window::Id) -> Element<'_, Message> {
tile.focus_id,
)
} else {
Column::from_iter(tile.results.iter().enumerate().map(|(i, app)| {
app.clone()
.render(tile.config.theme.clone(), i as u32, tile.focus_id)
}))
container(Column::from_iter(tile.results.iter().enumerate().map(
|(i, app)| {
app.clone()
.render(tile.config.theme.clone(), i as u32, tile.focus_id)
},
)))
.into()
};

let scrollable = Scrollable::with_direction(results, scrollbar_direction).id("results");
let contents = container(Column::new().push(title_input).push(scrollable).spacing(0))
.style(|_| container::Style {
text_color: None,
background: None,
border: iced::Border {
color: Color::WHITE,
width: 1.,
radius: Radius::new(5),
},
..Default::default()
});
let results_count = match &tile.page {
Page::Main => tile.results.len(),
Page::ClipboardHistory => tile.clipboard_content.len(),
Page::EmojiSearch => tile.results.len(),
};

let height = if tile.page == Page::ClipboardHistory {
385
} else {
std::cmp::min(tile.results.len() * 60, 290)
};

let scrollable = Scrollable::with_direction(results, scrollbar_direction)
.id("results")
.height(height as u32);

let contents = container(
Column::new()
.push(title_input)
.push(scrollable)
.push(footer(tile.config.theme.clone(), results_count))
.spacing(0),
)
.style(|_| container::Style {
text_color: None,
background: None,
border: iced::Border {
color: Color::TRANSPARENT,
width: 0.,
radius: Radius::new(15),
},
..Default::default()
});

container(contents.clip(false))
.style(|_| contents_style(&tile.config.theme))
Expand All @@ -156,3 +185,50 @@ pub fn view(tile: &Tile, wid: window::Id) -> Element<'_, Message> {
space().into()
}
}

fn footer(theme: Theme, results_count: usize) -> Element<'static, Message> {
let text = if results_count == 0 {
return space().into();
} else if results_count == 1 {
"1 result found"
} else {
&format!("{} results found", results_count)
};

container(
Row::new()
.push(
Text::new(text.to_string())
.size(12)
.height(30)
.color(theme.text_color(0.7))
.font(theme.font())
.align_x(Alignment::Center),
)
.padding(4)
.width(Fill)
.height(30),
)
.center(Length::Fill)
.width(WINDOW_WIDTH)
.padding(5)
.style(move |_| container::Style {
text_color: None,
background: Some(iced::Background::Color(with_alpha(
tint(theme.bg_color(), 0.04),
1.0,
))),
border: iced::Border {
color: Color::WHITE,
width: 0.,
radius: Radius::new(15).top(0),
},
shadow: iced::Shadow {
color: Color::TRANSPARENT,
offset: Vector::ZERO,
blur_radius: 0.,
},
snap: false,
})
.into()
}
6 changes: 3 additions & 3 deletions src/app/tile/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
_ => tile.results.len() as u32,
};

let old_focus_id = tile.focus_id.clone();
let old_focus_id = tile.focus_id;

if len == 0 {
return Task::none();
Expand Down Expand Up @@ -456,7 +456,7 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
id,
iced::Size {
width: WINDOW_WIDTH,
height: ((max_elem * 55) + DEFAULT_WINDOW_HEIGHT as usize) as f32,
height: ((max_elem * 55) + 35 + DEFAULT_WINDOW_HEIGHT as usize) as f32,
},
),
Task::done(Message::ChangeFocus(ArrowKey::Left)),
Expand All @@ -467,7 +467,7 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
id,
iced::Size {
width: WINDOW_WIDTH,
height: ((7 * 55) + DEFAULT_WINDOW_HEIGHT as usize) as f32,
height: ((7 * 55) + 35 + DEFAULT_WINDOW_HEIGHT as usize) as f32,
},
),
Task::done(Message::ChangeFocus(ArrowKey::Left)),
Expand Down
27 changes: 10 additions & 17 deletions src/styles.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use iced::border::Radius;
use iced::widget::text_input::Status;
use iced::widget::{button, container};
use iced::{Background, Border, Color, widget::text_input};

Expand All @@ -19,23 +18,21 @@ pub fn with_alpha(mut c: Color, a: f32) -> Color {
c
}

pub fn rustcast_text_input_style(theme: &ConfigTheme, status: Status) -> text_input::Style {
pub fn rustcast_text_input_style(
theme: &ConfigTheme,
round_bottom_edges: bool,
) -> text_input::Style {
let base_bg = theme.bg_color();
let surface = with_alpha(tint(base_bg, 0.06), 1.0);

let (border_color, border_width) = match status {
text_input::Status::Focused { .. } => (theme.text_color(0.20), 1.),
text_input::Status::Hovered => (theme.text_color(0.20), 1.),
text_input::Status::Active => (theme.text_color(0.20), 1.),
text_input::Status::Disabled => (theme.text_color(0.20), 1.),
};
let border_color = theme.text_color(1.);

text_input::Style {
background: Background::Color(surface),
border: Border {
color: border_color,
width: border_width,
radius: Radius::new(5.0).bottom(0.),
width: 1.,
radius: Radius::new(15.).bottom(if round_bottom_edges { 15. } else { 0. }),
},
icon: theme.text_color(0.7),
placeholder: theme.text_color(0.45),
Expand All @@ -50,7 +47,7 @@ pub fn contents_style(theme: &ConfigTheme) -> container::Style {
text_color: None,
border: iced::Border {
color: theme.text_color(0.7),
width: 1.0,
width: 0.,
radius: Radius::new(14.0),
},
..Default::default()
Expand All @@ -76,12 +73,8 @@ pub fn result_row_container_style(tile: &ConfigTheme, focused: bool) -> containe
container::Style {
background: Some(Background::Color(row_bg)),
border: Border {
color: if focused {
tile.text_color(0.35)
} else {
tile.text_color(0.10)
},
width: 0.2,
color: tile.text_color(1.),
width: 0.,
radius: Radius::new(0.),
},
..Default::default()
Expand Down