Skip to content

Commit 8e16009

Browse files
authored
Merge pull request #255 from niklasmarderx/fix/favourite-highlight-254
fix: highlight favourite icon and sort favourites alphabetically
2 parents 11ef5ac + 5a0a123 commit 8e16009

3 files changed

Lines changed: 23 additions & 15 deletions

File tree

src/app/apps.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,12 @@ impl App {
213213

214214
let name = self.search_name.clone();
215215
let theme_clone = theme.clone();
216+
let is_favourite = self.ranking == -1;
216217
row = row.push(
217218
Button::new(Text::new("♥️").width(Length::Fill).align_x(Alignment::End))
218219
.on_press_with(move || Message::ToggleFavouriteApp(name.clone()))
219220
.width(Length::Fill)
220-
.style(move |_, status| favourite_button_style(&theme_clone, status)),
221+
.style(move |_, status| favourite_button_style(&theme_clone, status, is_favourite)),
221222
);
222223

223224
let msg = on_press.or(match self.open_command.clone() {

src/app/tile.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,14 @@ impl AppIndex {
109109
}
110110

111111
fn get_favourites(&self) -> Vec<App> {
112-
self.by_name
112+
let mut favs: Vec<App> = self
113+
.by_name
113114
.values()
114-
.filter_map(|x| {
115-
if x.ranking == -1 {
116-
Some(x.to_owned())
117-
} else {
118-
None
119-
}
120-
})
121-
.collect()
115+
.filter(|x| x.ranking == -1)
116+
.cloned()
117+
.collect();
118+
favs.sort_by(|a, b| a.display_name.cmp(&b.display_name));
119+
favs
122120
}
123121

124122
fn empty() -> AppIndex {

src/styles.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,21 @@ pub fn result_button_style(theme: &ConfigTheme) -> button::Style {
7575
}
7676
}
7777

78-
pub fn favourite_button_style(theme: &ConfigTheme, status: button::Status) -> button::Style {
78+
pub fn favourite_button_style(
79+
theme: &ConfigTheme,
80+
status: button::Status,
81+
is_favourite: bool,
82+
) -> button::Style {
83+
let (base, pressed, hovered) = if is_favourite {
84+
(1.0, 0.8, 0.9)
85+
} else {
86+
(0.1, 1.0, 0.5)
87+
};
88+
7989
let text_color = match status {
80-
button::Status::Pressed => theme.text_color(1.),
81-
button::Status::Hovered => theme.text_color(0.5),
82-
button::Status::Active => theme.text_color(0.1),
83-
button::Status::Disabled => theme.text_color(0.1),
90+
button::Status::Pressed => theme.text_color(pressed),
91+
button::Status::Hovered => theme.text_color(hovered),
92+
_ => theme.text_color(base),
8493
};
8594

8695
button::Style {

0 commit comments

Comments
 (0)