Skip to content

Commit 24c0e67

Browse files
committed
This adds a bunch of styling upgrades but is still slightly broken
1 parent 947de67 commit 24c0e67

File tree

9 files changed

+208
-147
lines changed

9 files changed

+208
-147
lines changed

src/app.rs

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

1313
/// The default window height
14-
pub const DEFAULT_WINDOW_HEIGHT: f32 = 65.;
14+
pub const DEFAULT_WINDOW_HEIGHT: f32 = 80.;
1515

1616
/// The rustcast descriptor name to be put for all rustcast commands
1717
pub const RUSTCAST_DESC_NAME: &str = "RustCast";

src/app/apps.rs

Lines changed: 76 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44
use std::path::Path;
55

66
use iced::{
7-
Alignment, Background,
7+
Alignment, Background, Border,
88
Length::Fill,
9-
alignment::Vertical,
109
border::Radius,
11-
widget::{Button, Row, Text, container, image::Viewer},
10+
widget::{Button, Row, Text, button, container, image::Viewer},
1211
};
1312

1413
use crate::{
1514
app::{Message, Page, RUSTCAST_DESC_NAME},
1615
commands::Function,
16+
config::Theme,
17+
styles::{tint, with_alpha},
1718
utils::handle_from_icns,
1819
};
1920

@@ -111,73 +112,88 @@ impl App {
111112
id_num: u32,
112113
focussed_id: u32,
113114
) -> impl Into<iced::Element<'a, Message>> {
114-
let mut tile = Row::new().width(Fill).height(55);
115+
let focused = focussed_id == id_num;
115116

116-
if theme.show_icons
117-
&& let Some(icon) = &self.icons
118-
{
119-
tile = tile
120-
.push(container(Viewer::new(icon).height(35).width(35)))
121-
.align_y(Alignment::Center);
122-
}
123-
124-
tile = tile.push(
125-
Button::new(
117+
// Title + subtitle (Raycast style)
118+
let text_block = iced::widget::Column::new()
119+
.spacing(2)
120+
.push(
126121
Text::new(&self.name)
127122
.font(theme.font())
128-
.height(Fill)
129-
.width(Fill)
130-
.color(theme.text_color(1.))
131-
.align_y(Vertical::Center),
123+
.size(16)
124+
.color(theme.text_color(1.0)),
132125
)
133-
.on_press_maybe({
134-
match self.open_command.clone() {
135-
AppCommand::Function(func) => Some(Message::RunFunction(func)),
136-
AppCommand::Message(msg) => Some(msg),
137-
AppCommand::Display => None,
138-
}
139-
})
140-
.style(|_, _| iced::widget::button::Style {
141-
background: None,
142-
text_color: theme.text_color(1.),
143-
..Default::default()
144-
})
126+
.push(
127+
Text::new(&self.desc)
128+
.font(theme.font())
129+
.size(13)
130+
.color(theme.text_color(0.55)),
131+
);
132+
133+
let mut row = Row::new()
134+
.align_y(Alignment::Center)
145135
.width(Fill)
146-
.height(55),
147-
);
136+
.spacing(0)
137+
.height(50);
148138

149-
tile = tile
150-
.push(
151-
container(
152-
Text::new(&self.desc)
153-
.font(theme.font())
154-
.color(theme.text_color(0.4)),
155-
)
156-
.padding(12),
157-
)
158-
.width(Fill);
139+
if theme.show_icons
140+
&& let Some(icon) = &self.icons
141+
{
142+
row = row.push(
143+
container(Viewer::new(icon).height(40).width(40))
144+
.width(40)
145+
.height(40),
146+
);
147+
}
148+
row = row.push(container(text_block).width(Fill));
159149

160-
let (highlight_opacity, border_width) = if focussed_id == id_num {
161-
(0.7, 0.55)
162-
} else {
163-
(0.5, 0.1)
150+
let msg = match self.open_command.clone() {
151+
AppCommand::Function(func) => Some(Message::RunFunction(func)),
152+
AppCommand::Message(msg) => Some(msg),
153+
AppCommand::Display => None,
164154
};
165155

166-
container(tile)
156+
let content = Button::new(row)
157+
.on_press_maybe(msg)
158+
.style(|_, _| result_button_style(theme))
159+
.width(Fill)
160+
.padding(0)
161+
.height(50);
162+
163+
container(content)
167164
.id(format!("result-{}", id_num))
168-
.style(move |_| iced::widget::container::Style {
169-
text_color: Some(theme.text_color(1.)),
170-
background: Some(Background::Color(theme.bg_color())),
171-
border: iced::Border {
172-
color: theme.text_color(highlight_opacity),
173-
width: border_width,
174-
radius: Radius::new(0),
175-
},
176-
..Default::default()
177-
})
178-
.max_height(55)
179-
.padding(5)
165+
.style(move |_| result_row_container_style(theme, focused))
166+
.padding(8)
180167
.width(Fill)
181-
.height(Fill)
168+
}
169+
}
170+
171+
fn result_button_style(theme: &Theme) -> button::Style {
172+
let mut s = button::Style::default();
173+
s.text_color = theme.text_color(1.0);
174+
s.background = None;
175+
s
176+
}
177+
178+
fn result_row_container_style(tile: &Theme, focused: bool) -> container::Style {
179+
let base = tile.bg_color();
180+
let row_bg = if focused {
181+
with_alpha(tint(base, 0.10), 1.0)
182+
} else {
183+
with_alpha(tint(base, 0.04), 1.0)
184+
};
185+
186+
container::Style {
187+
background: Some(Background::Color(row_bg)),
188+
border: Border {
189+
color: if focused {
190+
tile.text_color(0.35)
191+
} else {
192+
tile.text_color(0.10)
193+
},
194+
width: if focused { 1.1 } else { 0.8 },
195+
radius: Radius::new(10.0),
196+
},
197+
..Default::default()
182198
}
183199
}

src/app/tile.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,16 @@ impl AppIndex {
8484
/// - Page ([`Page`]) the current page of the window (main or clipboard history)
8585
#[derive(Clone)]
8686
pub struct Tile {
87-
theme: iced::Theme,
88-
focus_id: u32,
89-
query: String,
87+
pub theme: iced::Theme,
88+
pub focus_id: u32,
89+
pub query: String,
9090
query_lc: String,
9191
results: Vec<App>,
9292
options: AppIndex,
9393
visible: bool,
9494
focused: bool,
9595
frontmost: Option<Retained<NSRunningApplication>>,
96-
config: Config,
96+
pub config: Config,
9797
/// The opening hotkey
9898
hotkey: HotKey,
9999
clipboard_content: Vec<ClipBoardContentType>,

src/app/tile/elm.rs

Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use iced::border::Radius;
66
use iced::widget::scrollable::{Anchor, Direction, Scrollbar};
77
use iced::widget::text::LineHeight;
88
use iced::widget::{Column, Scrollable, container, space};
9-
use iced::{Color, window};
9+
use iced::window;
1010
use iced::{Element, Task};
1111
use iced::{Length::Fill, widget::text_input};
1212

@@ -15,9 +15,9 @@ use rayon::{
1515
slice::ParallelSliceMut,
1616
};
1717

18-
use crate::app::apps::AppCommand;
1918
use crate::app::tile::AppIndex;
2019
use crate::config::Theme;
20+
use crate::styles::rustcast_text_input_style;
2121
use crate::{
2222
app::{Message, Page, apps::App, default_settings, tile::Tile},
2323
config::Config,
@@ -93,8 +93,8 @@ pub fn view(tile: &Tile, wid: window::Id) -> Element<'_, Message> {
9393
.on_submit(Message::OpenFocused)
9494
.id("query")
9595
.width(Fill)
96-
.line_height(LineHeight::Relative(1.5))
97-
.style(|_, _| text_input_style(&tile.config.theme))
96+
.line_height(LineHeight::Relative(1.75))
97+
.style(rustcast_text_input_style(&tile.theme))
9898
.padding(20);
9999

100100
let scrollbar_direction = if tile.config.theme.show_scroll_bar {
@@ -109,7 +109,7 @@ pub fn view(tile: &Tile, wid: window::Id) -> Element<'_, Message> {
109109
};
110110
let results = match tile.page {
111111
Page::Main => {
112-
let mut search_results = Column::new();
112+
let mut search_results = Column::new().spacing(5);
113113
for (i, result) in tile.results.iter().enumerate() {
114114
search_results = search_results.push(result.render(
115115
&tile.config.theme,
@@ -128,49 +128,32 @@ pub fn view(tile: &Tile, wid: window::Id) -> Element<'_, Message> {
128128
clipboard_history
129129
}
130130
};
131+
131132
let scrollable = Scrollable::with_direction(results, scrollbar_direction).id("results");
132-
let contents = Column::new().push(title_input).push(scrollable);
133+
let contents = Column::new()
134+
.push(title_input)
135+
.push(scrollable)
136+
.spacing(if tile.results.is_empty() { 0 } else { 5 });
133137

134138
container(contents)
135-
.style(|_| iced::widget::container::Style {
136-
background: None,
137-
text_color: None,
138-
border: iced::Border {
139-
color: tile.config.theme.text_color(1.),
140-
width: 1.,
141-
radius: Radius::new(0),
142-
},
143-
..Default::default()
144-
})
145-
.padding(0)
139+
.style(|_| panel_style(&tile.config.theme))
140+
.padding(10)
146141
.clip(true)
147142
.into()
148143
} else {
149144
space().into()
150145
}
151146
}
152147

153-
fn text_input_style(theme: &Theme) -> iced::widget::text_input::Style {
154-
text_input::Style {
155-
background: iced::Background::Color(Color::TRANSPARENT),
148+
fn panel_style(theme: &Theme) -> container::Style {
149+
container::Style {
150+
background: Some(iced::Background::Color(theme.bg_color())),
151+
text_color: None,
156152
border: iced::Border {
157-
color: iced::Color {
158-
r: 0.95,
159-
g: 0.95,
160-
b: 0.95,
161-
a: 0.7,
162-
},
163-
width: 0.5,
164-
radius: iced::border::Radius {
165-
top_left: 0.,
166-
top_right: 0.,
167-
bottom_right: 0.,
168-
bottom_left: 0.,
169-
},
153+
color: theme.text_color(1.),
154+
width: 1.0,
155+
radius: Radius::new(14.0),
170156
},
171-
icon: theme.text_color(0.),
172-
placeholder: theme.text_color(0.7),
173-
value: theme.text_color(1.),
174-
selection: theme.text_color(0.2),
157+
..Default::default()
175158
}
176159
}

src/app/tile/update.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
219219
id,
220220
iced::Size {
221221
width: WINDOW_WIDTH,
222-
height: ((max_elem * 55) + DEFAULT_WINDOW_HEIGHT as usize) as f32,
222+
height: ((max_elem * 70) + DEFAULT_WINDOW_HEIGHT as usize) as f32,
223223
},
224224
),
225225
Task::done(Message::ChangeFocus(ArrowKey::Left)),
@@ -230,7 +230,7 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
230230
id,
231231
iced::Size {
232232
width: WINDOW_WIDTH,
233-
height: ((element_count * 55) + DEFAULT_WINDOW_HEIGHT as usize) as f32,
233+
height: ((element_count * 70) + DEFAULT_WINDOW_HEIGHT as usize) as f32,
234234
},
235235
)
236236
} else {

0 commit comments

Comments
 (0)