use egui::Pos2;
use crate::screenshot::action::{
ActionContext, ActionResult, DrawingContext, RenderContext, ScreenAction, ToolCategory,
};
use crate::screenshot::stroke::SequenceMarker;
pub struct SequenceAction {
active: bool,
}
impl SequenceAction {
pub fn new() -> Self {
Self { active: false }
}
}
impl Default for SequenceAction {
fn default() -> Self {
Self::new()
}
}
impl ScreenAction for SequenceAction {
fn id(&self) -> &str {
"sequence"
}
fn name(&self) -> &str {
"Sequence"
}
fn icon_id(&self) -> Option<&str> {
Some("sequence")
}
fn category(&self) -> ToolCategory {
ToolCategory::Drawing
}
fn is_active(&self) -> bool {
self.active
}
fn set_active(&mut self, active: bool) {
self.active = active;
}
fn on_click(&mut self, _ctx: &ActionContext) -> ActionResult {
self.active = !self.active;
ActionResult::Continue
}
fn is_drawing_tool(&self) -> bool {
true
}
fn on_draw_start(&mut self, pos: Pos2, ctx: &mut DrawingContext) {
let clamped_pos = ctx.clamp_to_bounds(pos);
ctx.annotations.add_marker(clamped_pos, ctx.settings.color);
}
fn render_annotations(&self, ctx: &RenderContext) {
for marker in &ctx.annotations.markers {
Self::render_marker(ctx.ui, marker);
}
}
}
impl SequenceAction {
fn render_marker(ui: &egui::Ui, marker: &SequenceMarker) {
ui.painter().circle_filled(marker.pos, marker.radius, marker.color);
ui.painter().circle_stroke(
marker.pos,
marker.radius,
egui::Stroke::new(2.0, egui::Color32::WHITE),
);
let label = marker.label();
let font = egui::FontId::proportional(marker.radius * 1.2);
ui.painter().text(
marker.pos,
egui::Align2::CENTER_CENTER,
label,
font,
egui::Color32::WHITE,
);
}
}