Skip to content

Commit

Permalink
more wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanabx committed Sep 2, 2024
1 parent 0432db2 commit aaf9aa9
Showing 1 changed file with 39 additions and 21 deletions.
60 changes: 39 additions & 21 deletions src/start_menu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ use freedesktop_desktop_entry::{get_languages_from_env, DesktopEntry, Locale};
use iced::{
alignment::{Horizontal, Vertical},
border::Radius,
widget::{button, row, scrollable::{Direction, Scrollbar}, text},
widget::{
button, row,
scrollable::{Direction, Scrollbar},
text,
},
Background, Border, Element, Length, Task, Theme,
};

Expand Down Expand Up @@ -77,32 +81,46 @@ impl<'a> StartMenu<'a> {

pub fn view_popup(&self) -> iced::Element<StartMenuMessage> {
iced::widget::scrollable(
iced::widget::column(self.de_cache.0.values().map(view_menu_item))
iced::widget::column(self.de_cache.0.values().filter_map(view_menu_item))
.height(Length::Shrink)
.width(Length::Fill),
).direction(Direction::Vertical(Scrollbar::new()))
.width(Length::Fill)
.spacing(10),
)
.direction(Direction::Vertical(Scrollbar::new()))
.height(Length::Fill)
.width(Length::Fill)
.into()
}
}

fn view_menu_item<'a>(desktop_entry: &DesktopEntry<'a>) -> iced::Element<'a, StartMenuMessage> {
fn view_menu_item<'a>(
desktop_entry: &DesktopEntry<'a>,
) -> Option<iced::Element<'a, StartMenuMessage>> {
if desktop_entry.no_display()
|| desktop_entry.name(&get_languages_from_env()).is_none()
|| desktop_entry.terminal()
|| desktop_entry.exec().is_none()
{
return None;
}
let icon_path = desktop_entry.icon();
row![
match icon_path {
Some(path) => {
app_icon(Path::new(path))
}
None => Element::from(iced::widget::horizontal_space()),
},
text!(
"{}",
desktop_entry
.name(&get_languages_from_env())
.unwrap_or("".into())
),
text!("{}", desktop_entry.appid)
]
.into()
Some(
iced::widget::button(row![
iced::widget::container(iced::widget::column![match icon_path {
Some(path) => {
app_icon(Path::new(path))
}
None => {
// log::warn!("No icon for {}", desktop_entry.appid);
Element::from(iced::widget::horizontal_space())
}
}])
.width(32)
.height(32),
text!("{}", desktop_entry.name(&get_languages_from_env()).unwrap()),
])
.on_press(StartMenuMessage::Launch(desktop_entry.appid.to_string()))
.width(Length::Fill)
.into(),
)
}

0 comments on commit aaf9aa9

Please sign in to comment.