Skip to content

Commit

Permalink
improv: menu item icons
Browse files Browse the repository at this point in the history
  • Loading branch information
edfloreshz committed Nov 18, 2024
1 parent 00400b3 commit cb8c733
Show file tree
Hide file tree
Showing 13 changed files with 121 additions and 53 deletions.
30 changes: 15 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions res/icons/bundled/cross-small-square-filled-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions res/icons/bundled/edit-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions res/icons/bundled/face-smile-big-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions res/icons/bundled/plus-square-filled-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions res/icons/bundled/settings-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions res/icons/bundled/tabs-stack-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 16 additions & 4 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use crate::details::Details;
use crate::{content, details, fl, todo};

pub mod config;
pub mod icon_cache;
pub mod icons;
mod key_bind;
pub mod localize;
pub mod markdown;
Expand Down Expand Up @@ -306,9 +306,21 @@ impl Application for Tasks {
Some(cosmic::widget::menu::items(
&HashMap::new(),
vec![
cosmic::widget::menu::Item::Button(fl!("rename"), NavMenuAction::Rename(id)),
cosmic::widget::menu::Item::Button(fl!("icon"), NavMenuAction::SetIcon(id)),
cosmic::widget::menu::Item::Button(fl!("delete"), NavMenuAction::Delete(id)),
cosmic::widget::menu::Item::Button(
fl!("rename"),
Some(icons::get_handle("edit-symbolic", 14)),
NavMenuAction::Rename(id),
),
cosmic::widget::menu::Item::Button(
fl!("icon"),
Some(icons::get_handle("face-smile-big-symbolic", 14)),
NavMenuAction::SetIcon(id),
),
cosmic::widget::menu::Item::Button(
fl!("delete"),
Some(icons::get_handle("user-trash-full-symbolic", 14)),
NavMenuAction::Delete(id),
),
],
))
}
Expand Down
34 changes: 22 additions & 12 deletions src/app/icon_cache.rs → src/app/icons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ impl IconCache {
};
}

// Menu icons
bundle!("edit-symbolic", 14);
bundle!("settings-symbolic", 14);
bundle!("tabs-stack-symbolic", 14);
bundle!("info-outline-symbolic", 14);
bundle!("plus-square-filled-symbolic", 14);
bundle!("cross-small-square-filled-symbolic", 14);
bundle!("face-smile-big-symbolic", 14);
bundle!("user-trash-full-symbolic", 14);

bundle!("edit-clear-symbolic", 18);
bundle!("folder-open-symbolic", 18);
bundle!("go-down-symbolic", 18);
Expand Down Expand Up @@ -68,18 +78,18 @@ impl IconCache {
.clone();
icon::icon(handle).size(size)
}
}

pub fn get(name: &'static str, size: u16) -> icon::Icon {
let mut icon_cache = ICON_CACHE.get().unwrap().lock().unwrap();
icon_cache.get_icon(name, size)
}
pub fn get_icon(name: &'static str, size: u16) -> icon::Icon {
let mut icon_cache = ICON_CACHE.get().unwrap().lock().unwrap();
icon_cache.get_icon(name, size)
}

pub fn get_handle(name: &'static str, size: u16) -> icon::Handle {
let mut icon_cache = ICON_CACHE.get().unwrap().lock().unwrap();
icon_cache
.cache
.entry(IconCacheKey { name, size })
.or_insert_with(|| icon::from_name(name).size(size).handle())
.clone()
}
pub fn get_handle(name: &'static str, size: u16) -> icon::Handle {
let mut icon_cache = ICON_CACHE.get().unwrap().lock().unwrap();
icon_cache
.cache
.entry(IconCacheKey { name, size })
.or_insert_with(|| icon::from_name(name).size(size).handle())
.clone()
}
50 changes: 42 additions & 8 deletions src/app/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,32 @@ use crate::{
fl,
};

use super::icons;

pub fn menu_bar<'a>(key_binds: &HashMap<KeyBind, Action>) -> Element<'a, Message> {
MenuBar::new(vec![
Tree::with_children(
root(fl!("file")),
items(
key_binds,
vec![
Item::Button(fl!("new-window"), Action::WindowNew),
Item::Button(
fl!("new-window"),
Some(icons::get_handle("tabs-stack-symbolic", 14)),
Action::WindowNew,
),
Item::Divider,
Item::Button(fl!("new-list"), Action::NewList),
Item::Button(
fl!("new-list"),
Some(icons::get_handle("plus-square-filled-symbolic", 14)),
Action::NewList,
),
Item::Divider,
Item::Button(fl!("quit"), Action::WindowClose),
Item::Button(
fl!("quit"),
Some(icons::get_handle("cross-small-square-filled-symbolic", 14)),
Action::WindowClose,
),
],
),
),
Expand All @@ -33,11 +47,23 @@ pub fn menu_bar<'a>(key_binds: &HashMap<KeyBind, Action>) -> Element<'a, Message
items(
key_binds,
vec![
Item::Button(fl!("rename"), Action::RenameList),
Item::Button(
fl!("rename"),
Some(icons::get_handle("edit-symbolic", 14)),
Action::RenameList,
),
Item::Divider,
Item::Button(fl!("icon"), Action::Icon),
Item::Button(
fl!("icon"),
Some(icons::get_handle("face-smile-big-symbolic", 14)),
Action::Icon,
),
Item::Divider,
Item::Button(fl!("delete"), Action::DeleteList),
Item::Button(
fl!("delete"),
Some(icons::get_handle("user-trash-full-symbolic", 14)),
Action::DeleteList,
),
],
),
),
Expand All @@ -46,9 +72,17 @@ pub fn menu_bar<'a>(key_binds: &HashMap<KeyBind, Action>) -> Element<'a, Message
items(
key_binds,
vec![
Item::Button(fl!("menu-settings"), Action::Settings),
Item::Button(
fl!("menu-settings"),
Some(icons::get_handle("settings-symbolic", 14)),
Action::Settings,
),
Item::Divider,
Item::Button(fl!("menu-about"), Action::About),
Item::Button(
fl!("menu-about"),
Some(icons::get_handle("info-outline-symbolic", 14)),
Action::About,
),
],
),
),
Expand Down
2 changes: 1 addition & 1 deletion src/app/settings.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::app::icon_cache::{IconCache, ICON_CACHE};
use crate::app::icons::{IconCache, ICON_CACHE};
use crate::app::Flags;
use cosmic::app::Settings;
use cosmic::iced::{Limits, Size};
Expand Down
14 changes: 7 additions & 7 deletions src/content.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::app::icon_cache::IconCache;
use crate::app::icons;
use crate::core::models::{self, List, Status};
use cosmic::iced::alignment::{Horizontal, Vertical};
use cosmic::iced::{Alignment, Length, Subscription};
Expand Down Expand Up @@ -55,7 +55,7 @@ impl Content {

fn list_header<'a>(&'a self, list: &'a List) -> Element<'a, Message> {
let spacing = theme::active().cosmic().spacing;
let export_button = widget::button::icon(IconCache::get_handle("share-symbolic", 18))
let export_button = widget::button::icon(icons::get_handle("share-symbolic", 18))
.class(cosmic::style::Button::Suggested)
.padding(spacing.space_xxs)
.on_press(Message::Export(self.tasks.values().cloned().collect()));
Expand Down Expand Up @@ -89,13 +89,13 @@ impl Content {
.on_toggle(move |value| Message::Complete(id, value));

let delete_button =
widget::button::icon(IconCache::get_handle("user-trash-full-symbolic", 18))
widget::button::icon(icons::get_handle("user-trash-full-symbolic", 18))
.padding(spacing.space_xxs)
.class(cosmic::style::Button::Destructive)
.on_press(Message::Delete(id));

let details_button =
widget::button::icon(IconCache::get_handle("info-outline-symbolic", 18))
widget::button::icon(icons::get_handle("info-outline-symbolic", 18))
.padding(spacing.space_xxs)
.class(cosmic::style::Button::Standard)
.on_press(Message::Select(item.clone()));
Expand Down Expand Up @@ -138,7 +138,7 @@ impl Content {

let container = widget::container(
widget::column::with_children(vec![
IconCache::get("task-past-due-symbolic", 56).into(),
icons::get_icon("task-past-due-symbolic", 56).into(),
widget::text::title1(fl!("no-tasks")).into(),
widget::text(fl!("no-tasks-suggestion")).into(),
])
Expand All @@ -165,7 +165,7 @@ impl Content {
.on_submit(Message::AddTask)
.width(Length::Fill)
.into(),
widget::button::icon(IconCache::get_handle("mail-send-symbolic", 18))
widget::button::icon(icons::get_handle("mail-send-symbolic", 18))
.padding(spacing.space_xxs)
.class(cosmic::style::Button::Suggested)
.on_press(Message::AddTask)
Expand Down Expand Up @@ -276,7 +276,7 @@ impl Content {
let Some(ref list) = self.list else {
return widget::container(
widget::column::with_children(vec![
IconCache::get("applications-office-symbolic", 56).into(),
icons::get_icon("applications-office-symbolic", 56).into(),
widget::text::title1(fl!("no-list-selected")).into(),
widget::text(fl!("no-list-suggestion")).into(),
])
Expand Down
Loading

0 comments on commit cb8c733

Please sign in to comment.