1use crate::theme::Style;
2use blockworx_paint::{Canvas, Cursor, Event, Interaction};
3
4use crate::{
5 names::ToolName,
6 shape::ShapeId,
7 tool::{Action, ImageTarget, ToolTrait},
8 widget::drawing::Drawing,
9};
10
11pub struct IconTool;
18
19impl ToolTrait for IconTool {
20 fn name(&self) -> ToolName {
21 ToolName::Icon
22 }
23
24 fn widget<C: Canvas>(
25 &mut self,
26 data: &mut Drawing,
27 interaction: &Interaction,
28 painter: &mut Style<'_, C>,
29 ) -> Option<Action> {
30 crate::widget::display::widget(data, interaction, painter);
31 painter.set_cursor(Cursor::PointingHand);
32 if let Some(Event::Clicked { pos }) = interaction.event
33 && let Some(ShapeId::Rect(rid)) = data.shape_at_pos(pos)
34 {
35 return Some(Action::ImageWanted(ImageTarget::Icon(rid)));
36 }
37 None
38 }
39}