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::DrawCx::draw_device
.
A concrete DrawIface
object may be obtained via downcast, e.g.:
impl CircleWidget {
fn draw(&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);
}
}
}
This object is effectively a fat pointer to draw state (both window-local
and shared components). 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: 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 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: DrawSharedImpl> Draw for DrawIface<'a, DS>
impl<'a, DS: DrawSharedImpl> Draw for DrawIface<'a, DS>
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, pos: Vec2, bb: Quad, text: &TextDisplay, col: Rgba)
fn text(&mut self, pos: Vec2, bb: Quad, text: &TextDisplay, col: Rgba)
Source§fn text_effects(
&mut self,
pos: Vec2,
bb: Quad,
text: &TextDisplay,
effects: &[Effect],
colors: &[Rgba],
)
fn text_effects( &mut self, pos: Vec2, bb: Quad, text: &TextDisplay, effects: &[Effect], colors: &[Rgba], )
Source§impl<'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,
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)
Auto Trait Implementations§
impl<'a, DS> Freeze for DrawIface<'a, DS>
impl<'a, DS> RefUnwindSafe for DrawIface<'a, DS>
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
Source§impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
Source§fn try_cast_approx(self) -> Result<T, Error>
fn try_cast_approx(self) -> Result<T, Error>
Source§fn cast_approx(self) -> T
fn cast_approx(self) -> T
Source§impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
Source§fn cast_trunc(self) -> T
fn cast_trunc(self) -> T
Source§fn cast_nearest(self) -> T
fn cast_nearest(self) -> T
Source§fn cast_floor(self) -> T
fn cast_floor(self) -> T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§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
.Source§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
.Source§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.Source§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.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more