use crate::handwriting::{Handwriting, ToolEvent};
use std::mem;

/// Handle a [ToolEvent]. Returns true if a stroke was completed.
pub fn on_tool_event(handwriting: &mut Handwriting, tool_event: ToolEvent) -> bool {
    match tool_event {
        ToolEvent::Press { at } => {
            debug_assert!(handwriting.e.current_stroke.is_empty());
            handwriting.push_to_stroke(at);
            false
        }
        ToolEvent::Move { to } => {
            handwriting.push_to_stroke(to);
            false
        }
        ToolEvent::Release => {
            debug_assert!(!handwriting.e.current_stroke.is_empty());
            handwriting.strokes.push(mem::take(&mut handwriting.e.current_stroke));
            true
        }
    }
}
