pub struct DrawIface<'a, DS>where
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::DrawCx::draw_device
.
A concrete DrawIface
object may be obtained via downcast, e.g.:
impl CircleWidget {
fn draw(&mut self, mut draw: DrawCx) {
// 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 application
shared 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§
source§impl<'a, DS> DrawIface<'a, DS>where
DS: DrawSharedImpl,
impl<'a, DS> DrawIface<'a, DS>where
DS: DrawSharedImpl,
sourcepub fn downcast_from(obj: &'a mut dyn Draw) -> Option<DrawIface<'a, DS>>
pub fn downcast_from(obj: &'a mut dyn Draw) -> Option<DrawIface<'a, DS>>
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 graphics backend (e.g. kas_wgpu
).
See documentation on this type for an example, or 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§
source§impl<'a, DS> Draw for DrawIface<'a, DS>where
DS: DrawSharedImpl,
impl<'a, DS> Draw for DrawIface<'a, DS>where
DS: DrawSharedImpl,
source§fn animate_at(&mut self, time: Instant)
fn animate_at(&mut self, time: Instant)
source§fn 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>
source§fn get_clip_rect(&self) -> Rect
fn get_clip_rect(&self) -> Rect
pass
Read moresource§fn frame(&mut self, outer: Quad, inner: Quad, col: Rgba)
fn frame(&mut self, outer: Quad, inner: Quad, col: Rgba)
source§fn text(&mut self, rect: Rect, text: &TextDisplay, col: Rgba)
fn text(&mut self, rect: Rect, text: &TextDisplay, col: Rgba)
source§fn 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<()>] )
source§fn 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>] )
source§impl<'a, DS> DrawRounded for DrawIface<'a, DS>where
DS: DrawSharedImpl,
<DS as DrawSharedImpl>::Draw: DrawRoundedImpl,
impl<'a, DS> DrawRounded for DrawIface<'a, DS>where
DS: DrawSharedImpl,
<DS as DrawSharedImpl>::Draw: DrawRoundedImpl,
source§fn 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)
source§fn circle(&mut self, rect: Quad, inner_radius: f32, col: Rgba)
fn circle(&mut self, rect: Quad, inner_radius: f32, col: Rgba)
source§fn circle_2col(&mut self, rect: Quad, col1: Rgba, col2: Rgba)
fn circle_2col(&mut self, rect: Quad, col1: Rgba, col2: Rgba)
source§impl<'a, DS> DrawShaded for DrawIface<'a, DS>where
DS: DrawSharedImpl,
<DS as DrawSharedImpl>::Draw: DrawShadedImpl,
impl<'a, DS> DrawShaded for DrawIface<'a, DS>where
DS: DrawSharedImpl,
<DS as DrawSharedImpl>::Draw: DrawShadedImpl,
source§fn shaded_square(&mut self, rect: Quad, norm: (f32, f32), col: Rgba)
fn shaded_square(&mut self, rect: Quad, norm: (f32, f32), col: Rgba)
source§fn shaded_circle(&mut self, rect: Quad, norm: (f32, f32), col: Rgba)
fn shaded_circle(&mut self, rect: Quad, norm: (f32, f32), col: Rgba)
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>
impl<'a, DS> Sync for DrawIface<'a, DS>
impl<'a, DS> Unpin for DrawIface<'a, DS>
impl<'a, DS> !UnwindSafe for DrawIface<'a, DS>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
§fn try_cast_approx(self) -> Result<T, Error>
fn try_cast_approx(self) -> Result<T, Error>
§fn cast_approx(self) -> T
fn cast_approx(self) -> T
§impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
§fn cast_trunc(self) -> T
fn cast_trunc(self) -> T
§fn cast_nearest(self) -> T
fn cast_nearest(self) -> T
§fn cast_floor(self) -> T
fn cast_floor(self) -> T
§fn try_cast_trunc(self) -> Result<T, Error>
fn try_cast_trunc(self) -> Result<T, Error>
§fn try_cast_nearest(self) -> Result<T, Error>
fn try_cast_nearest(self) -> Result<T, Error>
§fn try_cast_floor(self) -> Result<T, Error>
fn try_cast_floor(self) -> Result<T, Error>
§fn try_cast_ceil(self) -> Result<T, Error>
fn try_cast_ceil(self) -> Result<T, Error>
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.