Struct vizia_core::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>

source

pub fn bounds(&self) -> BoundingBox

Returns the bounds of the current view.

source

pub fn z_index(&self) -> i32

Returns the z-index of the current view.

source

pub fn scale_factor(&self) -> f32

Returns the scale factor.

source

pub fn modifiers(&self) -> &Modifiers

Returns a reference to the keyboard modifiers state.

source

pub fn mouse(&self) -> &MouseState<Entity>

Returns a reference to the mouse state.

source

pub fn clip_path(&self) -> Option<Path>

Returns the clip path of the current view.

source

pub fn transform(&self) -> Matrix

Returns the 2D transform of the current view.

source

pub fn visibility(&self) -> Option<Visibility>

Returns the visibility of the current view.

source

pub fn display(&self) -> Display

Returns the display of the current view.

source

pub fn opacity(&self) -> f32

Returns the opacity of the current view.

source

pub fn default_font(&self) -> &[FamilyOwned]

Returns the lookup pattern to pick the default font.

source

pub fn font_size(&self) -> f32

Returns the font-size of the current view in physical pixels.

source

pub fn font_weight(&self) -> FontWeight

Returns the font-weight of the current view.

source

pub fn font_width(&self) -> FontWidth

Returns the font-width of the current view.

source

pub fn font_slant(&self) -> FontSlant

Returns the font-slant of the current view.

source

pub fn font_variation_settings(&self) -> &[FontVariation]

Returns the font variation settings of the current view.

source

pub fn logical_to_physical(&self, logical: f32) -> f32

Function to convert logical points to physical pixels.

source

pub fn physical_to_logical(&self, physical: f32) -> f32

Function to convert physical pixels to logical points.

source

pub fn border_width(&self) -> f32

Returns the border width of the current view in physical pixels.

source

pub fn outline_color(&self) -> Color

Returns the outline color of the current view.

source

pub fn outline_width(&self) -> f32

Returns the outline width of the current view in physical pixels.

source

pub fn outline_offset(&self) -> f32

Returns the outline offset of the current view in physcial pixels.

source

pub fn corner_top_left_radius(&self) -> f32

Returns the corner radius for the top-left corner of the current view.

source

pub fn corner_top_right_radius(&self) -> f32

Returns the corner radius for the top-right corner of the current view.

source

pub fn corner_bottom_left_radius(&self) -> f32

Returns the corner radius for the bottom-left corner of the current view.

source

pub fn corner_bottom_right_radius(&self) -> f32

Returns the corner radius for the bottom-right corner of the current view.

source

pub fn corner_top_left_shape(&self) -> CornerShape

Returns the corner shape for the top-left corner of the current view.

source

pub fn corner_top_right_shape(&self) -> CornerShape

Returns the corner shape for the top-left corner of the current view.

source

pub fn corner_bottom_left_shape(&self) -> CornerShape

Returns the corner shape for the top-left corner of the current view.

source

pub fn corner_bottom_right_shape(&self) -> CornerShape

Returns the corner shape for the top-left corner of the current view.

source

pub fn corner_top_left_smoothing(&self) -> f32

Returns the corner smoothing for the top-left corner of the current view.

source

pub fn corner_top_right_smoothing(&self) -> f32

Returns the corner shape for the top-left corner of the current view.

source

pub fn corner_bottom_left_smoothing(&self) -> f32

Returns the corner shape for the top-left corner of the current view.

source

pub fn corner_bottom_right_smoothing(&self) -> f32

Returns the corner shape for the top-left corner of the current view.

source

pub fn child_left(&self) -> Units

Returns the child-left space of the current view.

source

pub fn child_right(&self) -> Units

Returns the child-right space of the current view.

source

pub fn child_top(&self) -> Units

Returns the child-top space of the current view.

source

pub fn child_bottom(&self) -> Units

Returns the child-bottom space of the current view.

source

pub fn background_color(&self) -> Color

source

pub fn border_color(&self) -> Color

source

pub fn border_style(&self) -> BorderStyleKeyword

Returns the border style of the current view.

source

pub fn selection_color(&self) -> Color

source

pub fn caret_color(&self) -> Color

source

pub fn font_color(&self) -> Color

source

pub fn text_wrap(&self) -> bool

Returns whether the current view should have its text wrapped.

source

pub fn text_align(&self) -> TextAlign

Returns the text alignment of the current view.

source

pub fn text_overflow(&self) -> TextOverflow

Returns the text overflow preference of the current view.

source

pub fn line_clamp(&self) -> Option<usize>

Returns the line clamp Of the current view.

source

pub fn shadows(&self) -> Option<&Vec<Shadow>>

Returns a reference to the shadows of the current view.

source

pub fn backdrop_filter(&self) -> Option<&Filter>

source

pub fn background_images(&self) -> Option<&Vec<ImageOrGradient>>

source

pub fn background_size(&self) -> Vec<BackgroundSize>

source

pub fn build_path(&self, bounds: BoundingBox, outset: (f32, f32)) -> Path

Get the vector path of the current view.

source

pub fn draw_background(&mut self, canvas: &Canvas)

Draw background color or background image (including gradients) for the current view.

source

pub fn draw_border(&mut self, canvas: &Canvas)

Draw the border of the current view.

source

pub fn draw_outline(&mut self, canvas: &Canvas)

Draw the outline of the current view.

source

pub fn draw_shadows(&mut self, canvas: &Canvas)

Draw shadows for the current view.

source

pub fn draw_text(&mut self, canvas: &Canvas)

Draw any text for the current view.

Trait Implementations§

source§

impl<'a> DataContext for DrawContext<'a>

source§

fn data<T: 'static>(&self) -> Option<&T>

Get model/view data from the context. Returns None if the data does not exist.
source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

source§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more