Skip to main content

blockworx_tools/
add_text.rs

1use crate::theme::Style;
2use blockworx_paint::{Canvas, Cursor, Interaction};
3
4use crate::{
5    names::ToolName,
6    tool::{ToolTrait, Transition},
7    widget::drawing::Drawing,
8};
9
10/// Click-to-place a text box. The pointer shows an I-beam over the canvas; a
11/// click stamps a box there with its editor already open, as a cell dropped
12/// off the cluster does ([`crate::stamp`]).
13pub struct AddText;
14
15impl ToolTrait for AddText {
16    fn name(&self) -> ToolName {
17        ToolName::AddText
18    }
19
20    fn widget<C: Canvas>(
21        &mut self,
22        data: &mut Drawing,
23        interaction: &Interaction,
24        painter: &mut Style<'_, C>,
25    ) -> Option<Transition> {
26        crate::widget::display::widget(data, interaction, painter);
27        painter.set_cursor(Cursor::Text);
28        crate::stamp::on_click(self.name(), interaction)
29    }
30}