pub trait Draw {
// Required methods
fn shared(&mut self) -> &mut dyn DrawShared;
fn animate(&mut self);
fn animate_at(&mut self, time: Instant);
fn get_pass(&self) -> PassId;
fn new_dyn_pass<'b>(
&'b mut self,
rect: Rect,
offset: Offset,
class: PassType,
) -> Box<dyn Draw + 'b>;
fn get_clip_rect(&self) -> Rect;
fn rect(&mut self, rect: Quad, col: Rgba);
fn frame(&mut self, outer: Quad, inner: Quad, col: Rgba);
fn image(&mut self, id: ImageId, rect: Quad);
fn text(
&mut self,
pos: Vec2,
bounding_box: Quad,
text: &TextDisplay,
col: Rgba,
);
fn text_effects(
&mut self,
pos: Vec2,
bounding_box: Quad,
text: &TextDisplay,
effects: &[Effect],
colors: &[Rgba],
);
}
Expand description
Basic draw interface for DrawIface
Most methods draw some feature. Exceptions are those starting with get_
and Self::new_dyn_pass
.
Additional draw routines are available through extension traits, depending
on the graphics backend. Since Rust does not (yet) support trait-object-downcast,
accessing these requires reconstruction of the implementing type via
DrawIface::downcast_from
.
Required Methods§
Access shared draw state
Sourcefn animate(&mut self)
fn animate(&mut self)
Request redraw at the next frame time
Animations should call this each frame until complete.
Sourcefn animate_at(&mut self, time: Instant)
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.
Sourcefn new_dyn_pass<'b>(
&'b mut self,
rect: Rect,
offset: Offset,
class: PassType,
) -> Box<dyn Draw + 'b>
fn new_dyn_pass<'b>( &'b mut self, rect: Rect, offset: Offset, class: PassType, ) -> Box<dyn Draw + 'b>
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
.
Sourcefn get_clip_rect(&self) -> Rect
fn get_clip_rect(&self) -> 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
DrawIface::new_pass
.)
Sourcefn rect(&mut self, rect: Quad, col: Rgba)
fn rect(&mut self, rect: Quad, col: Rgba)
Draw a rectangle of uniform colour
Note: where the implementation batches and/or re-orders draw calls, this should be one of the first items drawn such that almost anything else will draw “in front of” a rect.
Sourcefn frame(&mut self, outer: Quad, inner: Quad, col: Rgba)
fn frame(&mut self, outer: Quad, inner: Quad, col: Rgba)
Draw a frame of uniform colour
The frame is defined by the area inside outer
and not inside inner
.
Sourcefn text(&mut self, pos: Vec2, bounding_box: Quad, text: &TextDisplay, col: Rgba)
fn text(&mut self, pos: Vec2, bounding_box: Quad, text: &TextDisplay, col: Rgba)
Draw text with a colour
Text is drawn from pos
and clipped to bounding_box
.
The text
object must be configured and prepared prior to calling this
method (see crate::theme::Text
or crate::text::Text
).
Sourcefn text_effects(
&mut self,
pos: Vec2,
bounding_box: Quad,
text: &TextDisplay,
effects: &[Effect],
colors: &[Rgba],
)
fn text_effects( &mut self, pos: Vec2, bounding_box: Quad, text: &TextDisplay, effects: &[Effect], colors: &[Rgba], )
Draw text with effects
Text is drawn from pos
and clipped to bounding_box
.
The effects
list provides underlining/strikethrough information via
Effect::flags
and an index Effect::e
. If effects
is empty,
this is equivalent to Self::text
.
Text colour lookup uses index e
and is essentially:
colors.get(e).unwrap_or(Rgba::BLACK)
.
The text
object must be configured and prepared prior to calling this
method (see crate::theme::Text
or crate::text::Text
).