DrawImpl

Trait DrawImpl 

Source
pub trait DrawImpl: Any {
    // Required methods
    fn common_mut(&mut self) -> &mut WindowCommon;
    fn new_pass(
        &mut self,
        parent_pass: PassId,
        rect: Rect,
        offset: Offset,
        class: PassType,
    ) -> PassId;
    fn get_clip_rect(&self, pass: PassId) -> Rect;
    fn rect(&mut self, pass: PassId, rect: Quad, col: Rgba);
    fn frame(&mut self, pass: PassId, outer: Quad, inner: Quad, col: Rgba);

    // Provided methods
    fn animate(&mut self) { ... }
    fn animate_at(&mut self, time: Instant) { ... }
}
Expand description

Implementation target for Draw

This trait covers only the bare minimum of functionality which must be provided by the graphics backend; extension traits such as DrawRoundedImpl optionally provide more functionality.

Coordinates for many primitives are specified using floating-point types allowing fractional precision, deliberately excepting text which must be pixel-aligned for best appearance.

All draw operations may be batched; when drawn primitives overlap, the results are only loosely defined. Draw operations involving transparency should be ordered after those without transparency.

Draw operations take place over multiple render passes, identified by a handle of type PassId. In general the user only needs to pass this value into methods as required. DrawImpl::new_pass creates a new PassId.

Required Methods§

Source

fn common_mut(&mut self) -> &mut WindowCommon

Access common data

Source

fn new_pass( &mut self, parent_pass: PassId, rect: Rect, offset: Offset, class: PassType, ) -> PassId

Add a draw pass

Adds a new draw pass. Passes have the following effects:

  • Draw operations of a pass occur after those of the parent pass
  • Drawing is clipped to rect (in the base’s coordinate space) and translated by offset (relative to the base’s offset)

The parent pass is the one used as the self argument of this method. The base pass is dependent on class:

  • PassType::Clip: the base is the parent
  • PassType::Overlay: the base is the initial pass (i.e. whole window with no offset)
Source

fn get_clip_rect(&self, pass: PassId) -> Rect

Get drawable rect for a draw pass

The result is in the current target’s coordinate system, thus normally Rect::pos is zero (but this is not guaranteed).

(This is not guaranteed to equal the rect passed to DrawImpl::new_pass.)

Source

fn rect(&mut self, pass: PassId, rect: Quad, col: Rgba)

Draw a rectangle of uniform colour

Source

fn frame(&mut self, pass: PassId, outer: Quad, inner: Quad, col: Rgba)

Draw a frame of uniform colour

Provided Methods§

Source

fn animate(&mut self)

Request redraw at the next frame time

Animations should call this each frame until complete.

Source

fn animate_at(&mut self, time: Instant)

Request a redraw at a specific time

This may be used for animations with delays, e.g. flashing. Calling this method only ensures that the next draw happens no later than time, thus the method should be called again in each following frame.

Implementors§