Skip to main content

DrawingTool

Trait DrawingTool 

Source
pub trait DrawingTool: Send {
    // Required methods
    fn kind(&self) -> &'static str;
    fn anchors(&self) -> &[Anchor];
    fn anchors_mut(&mut self) -> &mut Vec<Anchor>;
    fn anchor_count(&self) -> AnchorCount;
    fn build(&self, ctx: &DrawingCtx<'_>, out: &mut FrameBuilder<'_>);
    fn hit_test(&self, ctx: &DrawingCtx<'_>, p: PointPx) -> Option<HitPart>;
    fn handles(&self, ctx: &DrawingCtx<'_>, out: &mut Vec<PointPx>);
    fn style(&self) -> &DrawingStyle;
    fn save(&self) -> DrawingData;

    // Provided methods
    fn move_handle(&mut self, handle: usize, to: Anchor) { ... }
    fn finish(&mut self) { ... }
}
Expand description

A drawing tool. Built-in tools are listed in BUILTIN_KINDS; custom tools are registered with DrawingManager::register.

build runs for every frame and must not allocate (it only writes into the frame’s pools through out).

Required Methods§

Source

fn kind(&self) -> &'static str

Kind, e.g. "trend_line".

Source

fn anchors(&self) -> &[Anchor]

Anchors.

Source

fn anchors_mut(&mut self) -> &mut Vec<Anchor>

Anchors, for moving the drawing.

Source

fn anchor_count(&self) -> AnchorCount

How the drawing is created.

Source

fn build(&self, ctx: &DrawingCtx<'_>, out: &mut FrameBuilder<'_>)

Draws the drawing.

Source

fn hit_test(&self, ctx: &DrawingCtx<'_>, p: PointPx) -> Option<HitPart>

What p hits, if anything (within DrawingCtx::hit_tolerance of lines).

Source

fn handles(&self, ctx: &DrawingCtx<'_>, out: &mut Vec<PointPx>)

Handles of the selected drawing, written into out (empty on entry; core reuses it, so any number of handles does not allocate). Handle k is dragged with move_handle(k, …).

Source

fn style(&self) -> &DrawingStyle

Style.

Source

fn save(&self) -> DrawingData

Saved form; a factory given it builds an equal drawing.

Provided Methods§

Source

fn move_handle(&mut self, handle: usize, to: Anchor)

Drags handle handle to to. The default moves anchor handle.

Source

fn finish(&mut self)

Called once the drawing is created (after the last click, or by DrawingManager::add): tools with more anchors than clicks add the others here.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§