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: &mut 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 mut path = vg::Path::new();
        path.rect(bounds.x, bounds.y, bounds.w, bounds.h);
        canvas.fill_path(&mut path, &vg::Paint::color(vg::Color::rgb(200, 100, 100)));
    }
}

Implementations§

source§

impl<'a> DrawContext<'a>

source

pub fn bounds(&self) -> BoundingBox

Returns the bounds 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_region(&self) -> BoundingBox

Returns the bounding box of the clip region of the current view.

source

pub fn transform(&self) -> Transform2D

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, entity: Entity) -> f32

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

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 border_top_left_radius(&self) -> f32

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

source

pub fn border_top_right_radius(&self) -> f32

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

source

pub fn border_bottom_left_radius(&self) -> f32

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

source

pub fn border_bottom_right_radius(&self) -> f32

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

source

pub fn border_top_left_shape(&self) -> BorderCornerShape

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

source

pub fn border_top_right_shape(&self) -> BorderCornerShape

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

source

pub fn border_bottom_left_shape(&self) -> BorderCornerShape

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

source

pub fn border_bottom_right_shape(&self) -> BorderCornerShape

Returns the border 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 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) -> Option<TextAlign>

source

pub fn box_shadows(&self) -> Option<&Vec<BoxShadow>>

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(&mut self) -> Path

Get the vector path of the current view.

source

pub fn draw_backdrop_filter( &mut self, canvas: &mut Canvas<OpenGl>, path: &mut Path )

Draw backdrop filters for the current view.

source

pub fn draw_background(&mut self, canvas: &mut Canvas<OpenGl>, path: &mut Path)

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

source

pub fn draw_text_and_selection(&mut self, canvas: &mut Canvas<OpenGl>)

source

pub fn draw_border(&mut self, canvas: &mut Canvas<OpenGl>, path: &mut Path)

Draw the border of the current view.

source

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

Draw the outline of the current view.

source

pub fn draw_inset_box_shadows( &mut self, canvas: &mut Canvas<OpenGl>, path: &mut Path )

Draw inset box shadows for the current view.

source

pub fn draw_shadows(&mut self, canvas: &mut Canvas<OpenGl>, path: &mut Path)

Draw non-inset box shadows for the current view.

source

pub fn draw_text( &mut self, canvas: &mut Canvas<OpenGl>, bounds: BoundingBox, justify: (f32, f32) )

Draw any text for the current view.

source

pub fn draw_text_selection( &mut self, canvas: &mut Canvas<OpenGl>, bounds: BoundingBox, justify: (f32, f32) )

Draw the selection box for the text of the current view.

source

pub fn draw_text_caret( &mut self, canvas: &mut Canvas<OpenGl>, bounds: BoundingBox, justify: (f32, f32), width: f32 )

Draw text caret for the current view.

Trait Implementations§

source§

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

source§

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

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, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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