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
sourceimpl<'a, DS: DrawSharedImpl> DrawIface<'a, DS>
impl<'a, DS: DrawSharedImpl> DrawIface<'a, DS>
sourcepub fn downcast_from(obj: &'a mut dyn Draw) -> Option<Self>
pub fn downcast_from(obj: &'a mut dyn Draw) -> Option<Self>
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.
sourcepub fn new_pass(
&mut self,
rect: Rect,
offset: Offset,
class: PassType
) -> DrawIface<'_, DS>
pub fn new_pass(
&mut self,
rect: Rect,
offset: Offset,
class: PassType
) -> DrawIface<'_, DS>
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
sourceimpl<'a, DS: DrawSharedImpl> Draw for DrawIface<'a, DS>
impl<'a, DS: DrawSharedImpl> Draw for DrawIface<'a, DS>
Access shared draw state
sourcefn animate_at(&mut self, time: Instant)
fn animate_at(&mut self, time: Instant)
Request a redraw at a specific time Read more
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 Read more
sourcefn get_clip_rect(&self) -> Rect
fn get_clip_rect(&self) -> Rect
Get drawable rect for a draw pass Read more
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 Read more
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 Read more
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 Read more
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>]
)
sourceimpl<'a, DS: DrawSharedImpl> DrawRounded for DrawIface<'a, DS>where
DS::Draw: DrawRoundedImpl,
impl<'a, DS: DrawSharedImpl> DrawRounded for DrawIface<'a, DS>where
DS::Draw: DrawRoundedImpl,
sourcefn rounded_line(&mut self, p1: Vec2, p2: Vec2, radius: f32, col: Rgba)
fn rounded_line(&mut self, p1: Vec2, p2: Vec2, radius: f32, col: Rgba)
Draw a line with rounded ends and uniform colour Read more
sourcefn circle(&mut self, rect: Quad, inner_radius: f32, col: Rgba)
fn circle(&mut self, rect: Quad, inner_radius: f32, col: Rgba)
Draw a circle or oval of uniform colour Read more
sourcefn circle_2col(&mut self, rect: Quad, col1: Rgba, col2: Rgba)
fn circle_2col(&mut self, rect: Quad, col1: Rgba, col2: Rgba)
Draw a circle or oval with two colours Read more
Auto Trait Implementations
impl<'a, DS> RefUnwindSafe for DrawIface<'a, DS>where
DS: RefUnwindSafe,
<DS as DrawSharedImpl>::Draw: RefUnwindSafe,
impl<'a, DS> Send for DrawIface<'a, DS>where
DS: Send,
<DS as DrawSharedImpl>::Draw: Send,
impl<'a, DS> Sync for DrawIface<'a, DS>where
DS: Sync,
<DS as DrawSharedImpl>::Draw: Sync,
impl<'a, DS> Unpin for DrawIface<'a, DS>
impl<'a, DS> !UnwindSafe for DrawIface<'a, DS>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
sourcefn try_cast_approx(self) -> Result<T, Error>
fn try_cast_approx(self) -> Result<T, Error>
Try approximate conversion from Self to T Read more
sourcefn cast_approx(self) -> T
fn cast_approx(self) -> T
Cast approximately from Self to T Read more
sourceimpl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
sourcefn cast_trunc(self) -> T
fn cast_trunc(self) -> T
Cast to integer, truncating Read more
sourcefn cast_nearest(self) -> T
fn cast_nearest(self) -> T
Cast to the nearest integer Read more
sourcefn cast_floor(self) -> T
fn cast_floor(self) -> T
Cast the floor to an integer Read more
sourcefn try_cast_trunc(self) -> Result<T, Error>
fn try_cast_trunc(self) -> Result<T, Error>
Try converting to integer with truncation Read more
sourcefn try_cast_nearest(self) -> Result<T, Error>
fn try_cast_nearest(self) -> Result<T, Error>
Try converting to the nearest integer Read more
sourcefn try_cast_floor(self) -> Result<T, Error>
fn try_cast_floor(self) -> Result<T, Error>
Try converting the floor to an integer Read more
sourcefn try_cast_ceil(self) -> Result<T, Error>
fn try_cast_ceil(self) -> Result<T, Error>
Try convert the ceiling to an integer Read more