diff --git a/src/widget/button/widget.rs b/src/widget/button/widget.rs index 81a9fdb0..033fe24d 100644 --- a/src/widget/button/widget.rs +++ b/src/widget/button/widget.rs @@ -32,7 +32,6 @@ enum Variant { Normal, Image { close_icon: svg::Handle, - selection_icon: svg::Handle, on_remove: Option, }, } @@ -117,14 +116,6 @@ where let bytes: &'static [u8] = &[]; iced_core::svg::Handle::from_memory(bytes) }), - selection_icon: crate::widget::icon::from_name("object-select-symbolic") - .size(16) - .icon() - .into_svg_handle() - .unwrap_or_else(|| { - let bytes: &'static [u8] = &[]; - iced_core::svg::Handle::from_memory(bytes) - }), }, } } @@ -380,7 +371,6 @@ where if let Variant::Image { close_icon, - selection_icon, on_remove, } = &self.variant { @@ -407,14 +397,14 @@ where .into(), ..Default::default() }, - shadow: Default::default(), + shadow: Shadow::default(), }, selection_background, ); iced_core::svg::Renderer::draw( renderer, - selection_icon.clone(), + crate::widget::common::object_select().clone(), styling.icon_color, Rectangle { width: 16.0, @@ -432,7 +422,7 @@ where renderer.fill_quad( renderer::Quad { bounds, - shadow: Default::default(), + shadow: Shadow::default(), border: Border { radius: c_rad.radius_m.into(), ..Default::default() @@ -731,7 +721,7 @@ where color: styling.outline_color, radius: styling.border_radius, }, - shadow: Default::default(), + shadow: Shadow::default(), }, Color::TRANSPARENT, ); @@ -767,7 +757,7 @@ where radius: styling.border_radius, ..Default::default() }, - shadow: Default::default(), + shadow: Shadow::default(), }, background, ); @@ -785,7 +775,7 @@ where color: styling.border_color, radius: styling.border_radius, }, - shadow: Default::default(), + shadow: Shadow::default(), }, Color::TRANSPARENT, ); diff --git a/src/widget/common.rs b/src/widget/common.rs new file mode 100644 index 00000000..fc1363e1 --- /dev/null +++ b/src/widget/common.rs @@ -0,0 +1,18 @@ +use crate::widget::svg; +use std::sync::OnceLock; + +/// Static `svg::Handle` to the `object-select-symbolic` icon. +pub fn object_select() -> &'static svg::Handle { + static SELECTION_ICON: OnceLock = OnceLock::new(); + + SELECTION_ICON.get_or_init(|| { + crate::widget::icon::from_name("object-select-symbolic") + .size(16) + .icon() + .into_svg_handle() + .unwrap_or_else(|| { + let bytes: &'static [u8] = &[]; + iced_core::svg::Handle::from_memory(bytes) + }) + }) +} diff --git a/src/widget/dropdown/menu/mod.rs b/src/widget/dropdown/menu/mod.rs index 8939350e..e214ec36 100644 --- a/src/widget/dropdown/menu/mod.rs +++ b/src/widget/dropdown/menu/mod.rs @@ -5,9 +5,7 @@ mod appearance; pub use appearance::{Appearance, StyleSheet}; -use std::ffi::OsStr; - -use crate::widget::{icon, Container}; +use crate::widget::Container; use iced_core::event::{self, Event}; use iced_core::layout::{self, Layout}; use iced_core::text::{self, Text}; @@ -149,8 +147,6 @@ impl<'a, Message: 'a> Overlay<'a, Message> { style, } = menu; - let selected_icon = icon::from_name("object-select-symbolic").size(16).handle(); - let mut container = Container::new(Scrollable::new(List { options, hovered_option, @@ -160,14 +156,6 @@ impl<'a, Message: 'a> Overlay<'a, Message> { text_size, text_line_height, padding, - selected_icon: match selected_icon.data { - icon::Data::Name(named) => named - .path() - .filter(|path| path.extension().is_some_and(|ext| ext == OsStr::new("svg"))) - .map(iced_core::svg::Handle::from_path), - icon::Data::Svg(handle) => Some(handle), - icon::Data::Image(_) => None, - }, })); container = container @@ -286,7 +274,6 @@ struct List<'a, S: AsRef, Message> { padding: Padding, text_size: Option, text_line_height: text::LineHeight, - selected_icon: Option, } impl<'a, S: AsRef, Message> Widget @@ -460,19 +447,17 @@ impl<'a, S: AsRef, Message> Widget appearance.selected_background, ); - if let Some(handle) = self.selected_icon.clone() { - svg::Renderer::draw( - renderer, - handle, - Some(appearance.selected_text_color), - Rectangle { - x: item_x + item_width - 16.0 - 8.0, - y: bounds.y + (bounds.height / 2.0 - 8.0), - width: 16.0, - height: 16.0, - }, - ); - } + svg::Renderer::draw( + renderer, + crate::widget::common::object_select().clone(), + Some(appearance.selected_text_color), + Rectangle { + x: item_x + item_width - 16.0 - 8.0, + y: bounds.y + (bounds.height / 2.0 - 8.0), + width: 16.0, + height: 16.0, + }, + ); (appearance.selected_text_color, crate::font::FONT_SEMIBOLD) } else if *self.hovered_option == Some(i) { diff --git a/src/widget/dropdown/multi/menu.rs b/src/widget/dropdown/multi/menu.rs index c0497274..2f87d123 100644 --- a/src/widget/dropdown/multi/menu.rs +++ b/src/widget/dropdown/multi/menu.rs @@ -1,9 +1,7 @@ use super::Model; pub use crate::widget::dropdown::menu::{Appearance, StyleSheet}; -use std::ffi::OsStr; - -use crate::widget::{icon, Container}; +use crate::widget::Container; use iced_core::event::{self, Event}; use iced_core::layout::{self, Layout}; use iced_core::text::{self, Text}; @@ -152,25 +150,15 @@ impl<'a, Message: 'a> Overlay<'a, Message> { style, } = menu; - let selected_icon = icon::from_name("object-select-symbolic").size(16).handle(); - let mut container = Container::new(Scrollable::new(InnerList { options, hovered_option, selected_option, on_selected, on_option_hovered, + padding, text_size, text_line_height, - padding, - selected_icon: match selected_icon.data { - icon::Data::Name(named) => named - .path() - .filter(|path| path.extension().is_some_and(|ext| ext == OsStr::new("svg"))) - .map(iced_core::svg::Handle::from_path), - icon::Data::Svg(handle) => Some(handle), - icon::Data::Image(_) => None, - }, })); container = container @@ -291,7 +279,6 @@ struct InnerList<'a, S, Item, Message> { padding: Padding, text_size: Option, text_line_height: text::LineHeight, - selected_icon: Option, } impl<'a, S, Item, Message> Widget @@ -550,19 +537,17 @@ where appearance.selected_background, ); - if let Some(handle) = self.selected_icon.clone() { - svg::Renderer::draw( - renderer, - handle, - Some(appearance.selected_text_color), - Rectangle { - x: item_x + item_width - 16.0 - 8.0, - y: bounds.y + (bounds.height / 2.0 - 8.0), - width: 16.0, - height: 16.0, - }, - ); - } + svg::Renderer::draw( + renderer, + crate::widget::common::object_select().clone(), + Some(appearance.selected_text_color), + Rectangle { + x: item_x + item_width - 16.0 - 8.0, + y: bounds.y + (bounds.height / 2.0 - 8.0), + width: 16.0, + height: 16.0, + }, + ); (appearance.selected_text_color, crate::font::FONT_SEMIBOLD) } else if self.hovered_option.as_ref() == Some(item) { diff --git a/src/widget/mod.rs b/src/widget/mod.rs index 645d120f..97b1f50d 100644 --- a/src/widget/mod.rs +++ b/src/widget/mod.rs @@ -24,6 +24,8 @@ pub mod aspect_ratio; pub mod button; pub use button::{button, Button, IconButton, LinkButton, TextButton}; +pub(crate) mod common; + pub mod card; pub use card::*;