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, rect: Rect, text: &TextDisplay, col: Rgba);
fn text_effects(
&mut self,
rect: Rect,
text: &TextDisplay,
col: Rgba,
effects: &[Effect<()>]
);
fn text_effects_rgba(
&mut self,
rect: Rect,
text: &TextDisplay,
effects: &[Effect<Rgba>]
);
}
Expand description
Base drawing 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, rect: Rect, text: &TextDisplay, col: Rgba)
fn text(&mut self, rect: Rect, text: &TextDisplay, col: Rgba)
Draw text with a colour
Text is drawn from rect.pos
and clipped to rect
. If the text
scrolls, rect
should be the size of the whole text, not the window.
It is required to call TextApi::prepare
or equivalent
prior to this method to select a font, font size and perform layout.
sourcefn text_effects(
&mut self,
rect: Rect,
text: &TextDisplay,
col: Rgba,
effects: &[Effect<()>]
)
fn text_effects( &mut self, rect: Rect, text: &TextDisplay, col: Rgba, effects: &[Effect<()>] )
Draw text with a single color and effects
Text is drawn from rect.pos
and clipped to rect
. If the text
scrolls, rect
should be the size of the whole text, not the window.
The effects list does not contain colour information, but may contain underlining/strikethrough information. It may be empty.
It is required to call TextApi::prepare
or equivalent
prior to this method to select a font, font size and perform layout.
sourcefn text_effects_rgba(
&mut self,
rect: Rect,
text: &TextDisplay,
effects: &[Effect<Rgba>]
)
fn text_effects_rgba( &mut self, rect: Rect, text: &TextDisplay, effects: &[Effect<Rgba>] )
Draw text with effects (including Rgba
color)
Text is drawn from rect.pos
and clipped to rect
. If the text
scrolls, rect
should be the size of the whole text, not the window.
The effects
list provides both underlining and colour information.
If the effects
list is empty or the first entry has start > 0
, a
default entity will be assumed.
It is required to call TextApi::prepare
or equivalent
prior to this method to select a font, font size and perform layout.