pub struct DrawIface<'a, DS: DrawSharedImpl> { /* private fields */ }
Expand description

Draw interface object

Draw and extension traits such as DrawRounded provide draw functionality over this object.

This type is used to present a unified mid-level draw interface, as available from crate::theme::DrawMgr::draw_device. A concrete DrawIface object may be obtained via downcast, e.g.:

impl CircleWidget {
    fn draw(&mut self, mut draw: DrawMgr) {
        // This type assumes usage of kas_wgpu without a custom draw pipe:
        type DrawIface = DrawIface<kas_wgpu::draw::DrawPipe<()>>;
        if let Some(mut draw) = DrawIface::downcast_from(draw.draw_device()) {
            draw.circle(self.rect.into(), 0.9, Rgba::BLACK);
        }
    }
}

Note that this object is little more than a mutable reference to the shell’s per-window draw state. As such, it is normal to pass a new copy created via DrawIface::re as a method argument. (Note that Rust automatically “reborrows” reference types passed as method arguments, but cannot do so automatically for structs containing references.)

Implementations

Attempt to downcast a &mut dyn Draw to a concrete DrawIface object

Note: Rust does not (yet) support trait-object-downcast: it not possible to cast from &mut dyn Draw to (for example) &mut dyn DrawRounded. Instead, the target type must be the implementing object, which is provided by the shell (e.g. kas_wgpu). See documentation on this type for an example, or see examine clock.rs.

Reborrow with a new lifetime

Add a draw pass

Adds a new draw pass. Passes affect draw order (operations in new passes happen after their parent pass), may clip drawing to a “clip rect” (see Draw::get_clip_rect) and may offset (translate) draw operations.

Case class == PassType::Clip: the new pass is derived from parent_pass; rect and offset are specified relative to this parent and the intersecton of rect and the parent’s “clip rect” is used. be clipped to rect (expressed in the parent’s coordinate system).

Case class == PassType::Overlay: the new pass is derived from the base pass (i.e. the window). Draw operations still happen after those in parent_pass.

Trait Implementations

Access shared draw state

Request redraw at the next frame time Read more

Request a redraw at a specific time Read more

Get the current draw pass

Add a draw pass Read more

Get drawable rect for a draw pass Read more

Draw a rectangle of uniform colour Read more

Draw a frame of uniform colour Read more

Draw the image in the given rect

Draw text with a colour Read more

Draw text with a single color and effects Read more

Draw text with effects (including Rgba color) Read more

Draw a line with rounded ends and uniform colour Read more

Draw a circle or oval of uniform colour Read more

Draw a circle or oval with two colours Read more

Draw a frame with rounded corners and uniform colour Read more

Draw a frame with rounded corners with two colours Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Cast from Self to T Read more

Try converting from Self to T Read more

Try approximate conversion from Self to T Read more

Cast approximately from Self to T Read more

Cast to integer, truncating Read more

Cast to the nearest integer Read more

Cast the floor to an integer Read more

Cast the ceiling to an integer Read more

Try converting to integer with truncation Read more

Try converting to the nearest integer Read more

Try converting the floor to an integer Read more

Try convert the ceiling to an integer Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.