Struct vizia::context::DrawContext
source · pub struct DrawContext<'a> { /* private fields */ }
Expand description
A context used when drawing a view.
The DrawContext
is provided by the draw
method in View
and can be used to immutably access the
computed style and layout properties of the current view.
§Example
pub struct CustomView {}
impl CustomView {
pub fn new(cx: &mut Context) -> Handle<Self> {
Self{}.build(cx, |_|{})
}
}
impl View for CustomView {
fn draw(&self, cx: &mut DrawContext, canvas: &Canvas) {
// Get the computed bounds after layout of the current view
let bounds = cx.bounds();
// Draw to the canvas using the bounds of the current view
let path = vg::Path::new();
path.rect(bounds.x, bounds.y, bounds.w, bounds.h);
let mut paint = vg::Paint::default();
paint.set_color(Color::rgb(200, 100, 100));
canvas.draw_path(&path, &paint);
}
}
Implementations§
source§impl<'a> DrawContext<'a>
impl<'a> DrawContext<'a>
sourcepub fn bounds(&self) -> BoundingBox
pub fn bounds(&self) -> BoundingBox
Returns the bounds of the current view.
sourcepub fn scale_factor(&self) -> f32
pub fn scale_factor(&self) -> f32
Returns the scale factor.
sourcepub fn mouse(&self) -> &MouseState<Entity>
pub fn mouse(&self) -> &MouseState<Entity>
Returns a reference to the mouse state.
sourcepub fn visibility(&self) -> Option<Visibility>
pub fn visibility(&self) -> Option<Visibility>
Returns the visibility of the current view.
sourcepub fn default_font(&self) -> &[FamilyOwned]
pub fn default_font(&self) -> &[FamilyOwned]
Returns the lookup pattern to pick the default font.
sourcepub fn font_weight(&self) -> FontWeight
pub fn font_weight(&self) -> FontWeight
Returns the font-weight of the current view.
sourcepub fn font_width(&self) -> FontWidth
pub fn font_width(&self) -> FontWidth
Returns the font-width of the current view.
sourcepub fn font_slant(&self) -> FontSlant
pub fn font_slant(&self) -> FontSlant
Returns the font-slant of the current view.
sourcepub fn font_variation_settings(&self) -> &[FontVariation]
pub fn font_variation_settings(&self) -> &[FontVariation]
Returns the font variation settings of the current view.
sourcepub fn logical_to_physical(&self, logical: f32) -> f32
pub fn logical_to_physical(&self, logical: f32) -> f32
Function to convert logical points to physical pixels.
sourcepub fn physical_to_logical(&self, physical: f32) -> f32
pub fn physical_to_logical(&self, physical: f32) -> f32
Function to convert physical pixels to logical points.
sourcepub fn border_width(&self) -> f32
pub fn border_width(&self) -> f32
Returns the border width of the current view in physical pixels.
sourcepub fn outline_color(&self) -> Color
pub fn outline_color(&self) -> Color
Returns the outline color of the current view.
sourcepub fn outline_width(&self) -> f32
pub fn outline_width(&self) -> f32
Returns the outline width of the current view in physical pixels.
sourcepub fn outline_offset(&self) -> f32
pub fn outline_offset(&self) -> f32
Returns the outline offset of the current view in physcial pixels.
sourcepub fn corner_top_left_radius(&self) -> f32
pub fn corner_top_left_radius(&self) -> f32
Returns the corner radius for the top-left corner of the current view.
sourcepub fn corner_top_right_radius(&self) -> f32
pub fn corner_top_right_radius(&self) -> f32
Returns the corner radius for the top-right corner of the current view.
sourcepub fn corner_bottom_left_radius(&self) -> f32
pub fn corner_bottom_left_radius(&self) -> f32
Returns the corner radius for the bottom-left corner of the current view.
sourcepub fn corner_bottom_right_radius(&self) -> f32
pub fn corner_bottom_right_radius(&self) -> f32
Returns the corner radius for the bottom-right corner of the current view.
sourcepub fn corner_top_left_shape(&self) -> CornerShape
pub fn corner_top_left_shape(&self) -> CornerShape
Returns the corner shape for the top-left corner of the current view.
sourcepub fn corner_top_right_shape(&self) -> CornerShape
pub fn corner_top_right_shape(&self) -> CornerShape
Returns the corner shape for the top-left corner of the current view.
sourcepub fn corner_bottom_left_shape(&self) -> CornerShape
pub fn corner_bottom_left_shape(&self) -> CornerShape
Returns the corner shape for the top-left corner of the current view.
sourcepub fn corner_bottom_right_shape(&self) -> CornerShape
pub fn corner_bottom_right_shape(&self) -> CornerShape
Returns the corner shape for the top-left corner of the current view.
sourcepub fn corner_top_left_smoothing(&self) -> f32
pub fn corner_top_left_smoothing(&self) -> f32
Returns the corner smoothing for the top-left corner of the current view.
sourcepub fn corner_top_right_smoothing(&self) -> f32
pub fn corner_top_right_smoothing(&self) -> f32
Returns the corner shape for the top-left corner of the current view.
sourcepub fn corner_bottom_left_smoothing(&self) -> f32
pub fn corner_bottom_left_smoothing(&self) -> f32
Returns the corner shape for the top-left corner of the current view.
sourcepub fn corner_bottom_right_smoothing(&self) -> f32
pub fn corner_bottom_right_smoothing(&self) -> f32
Returns the corner shape for the top-left corner of the current view.
sourcepub fn child_left(&self) -> Units
pub fn child_left(&self) -> Units
Returns the child-left space of the current view.
sourcepub fn child_right(&self) -> Units
pub fn child_right(&self) -> Units
Returns the child-right space of the current view.
sourcepub fn child_bottom(&self) -> Units
pub fn child_bottom(&self) -> Units
Returns the child-bottom space of the current view.
pub fn background_color(&self) -> Color
pub fn border_color(&self) -> Color
sourcepub fn border_style(&self) -> BorderStyleKeyword
pub fn border_style(&self) -> BorderStyleKeyword
Returns the border style of the current view.
pub fn selection_color(&self) -> Color
pub fn caret_color(&self) -> Color
pub fn font_color(&self) -> Color
sourcepub fn text_align(&self) -> TextAlign
pub fn text_align(&self) -> TextAlign
Returns the text alignment of the current view.
sourcepub fn text_overflow(&self) -> TextOverflow
pub fn text_overflow(&self) -> TextOverflow
Returns the text overflow preference of the current view.
sourcepub fn line_clamp(&self) -> Option<usize>
pub fn line_clamp(&self) -> Option<usize>
Returns the line clamp Of the current view.
sourcepub fn shadows(&self) -> Option<&Vec<Shadow>>
pub fn shadows(&self) -> Option<&Vec<Shadow>>
Returns a reference to the shadows of the current view.
pub fn backdrop_filter(&self) -> Option<&Filter>
pub fn background_images(&self) -> Option<&Vec<ImageOrGradient>>
pub fn background_size(&self) -> Vec<BackgroundSize>
sourcepub fn build_path(
&self,
bounds: BoundingBox,
outset: (f32, f32),
) -> Handle<SkPath>
pub fn build_path( &self, bounds: BoundingBox, outset: (f32, f32), ) -> Handle<SkPath>
Get the vector path of the current view.
sourcepub fn draw_background(&mut self, canvas: &Canvas)
pub fn draw_background(&mut self, canvas: &Canvas)
Draw background color or background image (including gradients) for the current view.
sourcepub fn draw_border(&mut self, canvas: &Canvas)
pub fn draw_border(&mut self, canvas: &Canvas)
Draw the border of the current view.
sourcepub fn draw_outline(&mut self, canvas: &Canvas)
pub fn draw_outline(&mut self, canvas: &Canvas)
Draw the outline of the current view.
sourcepub fn draw_shadows(&mut self, canvas: &Canvas)
pub fn draw_shadows(&mut self, canvas: &Canvas)
Draw shadows for the current view.
Trait Implementations§
source§impl<'a> DataContext for DrawContext<'a>
impl<'a> DataContext for DrawContext<'a>
source§fn data<T>(&self) -> Option<&T>where
T: 'static,
fn data<T>(&self) -> Option<&T>where
T: 'static,
None
if the data does not exist.fn as_context(&self) -> Option<LocalizationContext<'_>>
Auto Trait Implementations§
impl<'a> Freeze for DrawContext<'a>
impl<'a> !RefUnwindSafe for DrawContext<'a>
impl<'a> !Send for DrawContext<'a>
impl<'a> !Sync for DrawContext<'a>
impl<'a> Unpin for DrawContext<'a>
impl<'a> !UnwindSafe for DrawContext<'a>
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<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.