use eframe::egui::{Pos2, Rect};
use crate::annotate::{Annotation, Style};
use crate::document::AnnotationId;
use crate::editor::geometry::ResizeEdges;
#[derive(Clone, Copy, Debug)]
pub enum RegionMode {
Move { grab: Pos2 },
Resize { edges: ResizeEdges },
}
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum ItemDragKind {
Move,
Resize { edges: ResizeEdges },
ScaleUniform,
Rotate,
Endpoint { second: bool },
}
pub struct TextEditState {
pub target: Option<AnnotationId>,
pub pos: Pos2,
pub buffer: String,
pub style: Style,
pub just_created: bool,
}
pub enum EditorState {
Idle,
Panning,
DrawingShape { start: Pos2, current: Pos2, points: Vec<Pos2> },
RegionDraw { anchor: Pos2 },
RegionAdjust { start_rect: Rect, mode: RegionMode },
ItemsDrag {
items: Vec<(AnnotationId, Annotation)>,
kind: ItemDragKind,
bbox0: Rect,
center: Pos2,
grab: Pos2,
},
RubberBand { anchor: Pos2, current: Pos2, additive: bool },
TextEditing(TextEditState),
ConfirmDiscard { until: f64 },
}
impl EditorState {
pub fn is_idle(&self) -> bool {
matches!(self, EditorState::Idle)
}
pub fn is_text_editing(&self) -> bool {
matches!(self, EditorState::TextEditing(_))
}
pub fn is_confirm_discard(&self) -> bool {
matches!(self, EditorState::ConfirmDiscard { .. })
}
pub fn is_pointer_op(&self) -> bool {
!matches!(
self,
EditorState::Idle | EditorState::TextEditing(_) | EditorState::ConfirmDiscard { .. }
)
}
}