Skip to main content

blockworx_tools/
add_pin.rs

1use crate::theme::Style;
2use blockworx_paint::{Canvas, Cursor, Interaction};
3
4use crate::{
5    names::ToolName,
6    new_pin::{draw_markers, markers_in_scope},
7    tool::{ToolTrait, Transition},
8    widget::drawing::Drawing,
9};
10
11/// Click-to-add a pin. Every block in scope that may take one shows its free
12/// slots' markers; a click on one adds the pin and opens its name for editing,
13/// as the "(+)" beside a selected block does. The click is a stamp
14/// ([`crate::stamp`]), so a cell dropped off the cluster onto a marker adds the
15/// same pin.
16pub struct AddPin;
17
18impl ToolTrait for AddPin {
19    fn name(&self) -> ToolName {
20        ToolName::AddPin
21    }
22
23    fn widget<C: Canvas>(
24        &mut self,
25        data: &mut Drawing,
26        interaction: &Interaction,
27        painter: &mut Style<'_, C>,
28    ) -> Option<Transition> {
29        crate::widget::display::widget(data, interaction, painter);
30        painter.set_cursor(Cursor::Crosshair);
31        draw_markers(&markers_in_scope(data), interaction, painter);
32        crate::stamp::on_click(self.name(), interaction)
33    }
34}