improv(widget): share object-select svg handle between widgets using it

This commit is contained in:
Michael Aaron Murphy 2024-02-22 21:05:21 +01:00 committed by Michael Murphy
parent 552077bd8e
commit bd353c6b54
5 changed files with 51 additions and 71 deletions

View file

@ -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<f32>,
text_line_height: text::LineHeight,
selected_icon: Option<svg::Handle>,
}
impl<'a, S, Item, Message> Widget<Message, crate::Theme, crate::Renderer>
@ -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) {