egui_canvas 0.1.2

A TKinter-like canvas widget for egui.
Documentation
use egui::{Ui, Shape};

/// This trait marks a struct/enum as something that can be finalised into
/// a shape (but may need the current [`egui::Ui`] object to do so).
pub trait ShapePredicate: Sync + Send {
    /// This method turns an unfinished [`ShapePredicate`] object into a
    /// renderable [`egui::Shape`]. Implementations can access properties
    /// of the current [`egui::Ui`] object non-mutably through a provided
    /// reference.
    fn finalise(&self, ui: &Ui) -> Option<Shape>;
}

/// Blanket implementation of [`ShapePredicate`] trait for any type that
/// does not need the current [`egui::Ui`] object to be turned into am
/// [`egui::Shape`] object.
impl<T: Into<Shape> + Clone + Sync + Send> ShapePredicate for T {
    fn finalise(&self, _ui: &Ui) -> Option<Shape> {
        Some(self.clone().into())
    }
}