Skip to content

Commit ebf2520

Browse files
committed
fix: highlight favourite icon and sort favourites alphabetically
The heart icon now shows ❤️ for favourites and 🤍 for non-favourites, with brighter text when the app is marked as a favourite. Previously the icon looked the same regardless of favourite status. Favourites are now sorted alphabetically by display name. Closes #254
1 parent 11ef5ac commit ebf2520

3 files changed

Lines changed: 28 additions & 17 deletions

File tree

src/app/apps.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,13 @@ impl App {
213213

214214
let name = self.search_name.clone();
215215
let theme_clone = theme.clone();
216+
let is_favourite = self.ranking == -1;
217+
let heart = if is_favourite { "❤️" } else { "🤍" };
216218
row = row.push(
217-
Button::new(Text::new("♥️").width(Length::Fill).align_x(Alignment::End))
219+
Button::new(Text::new(heart).width(Length::Fill).align_x(Alignment::End))
218220
.on_press_with(move || Message::ToggleFavouriteApp(name.clone()))
219221
.width(Length::Fill)
220-
.style(move |_, status| favourite_button_style(&theme_clone, status)),
222+
.style(move |_, status| favourite_button_style(&theme_clone, status, is_favourite)),
221223
);
222224

223225
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: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,23 @@ 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 {
79-
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),
78+
pub fn favourite_button_style(
79+
theme: &ConfigTheme,
80+
status: button::Status,
81+
is_favourite: bool,
82+
) -> button::Style {
83+
let text_color = if is_favourite {
84+
match status {
85+
button::Status::Pressed => theme.text_color(0.8),
86+
button::Status::Hovered => theme.text_color(0.9),
87+
_ => theme.text_color(1.),
88+
}
89+
} else {
90+
match status {
91+
button::Status::Pressed => theme.text_color(1.),
92+
button::Status::Hovered => theme.text_color(0.5),
93+
_ => theme.text_color(0.1),
94+
}
8495
};
8596

8697
button::Style {

0 commit comments

Comments
 (0)