Skip to main content

DrawingContext

Struct DrawingContext 

Source
pub struct DrawingContext<'a> { /* private fields */ }
Expand description

The surface a visual draws itself onto during rendering.

Implementations§

Source§

impl<'a> DrawingContext<'a>

Source

pub fn new(core: &'a mut dyn IDrawingContextCore) -> Self

Creates a context over a borrowed core. Dropping (or disposing) the context pops the states still pushed but leaves the core alive.

Source

pub fn owned(core: Box<dyn IDrawingContextCore + 'a>) -> Self

Creates a context that owns its core: disposing (or dropping) the context pops the states still pushed and disposes the core.

Source

pub fn dispose(self)

Pops every state still pushed and releases the context (and the core, if the context owns it).

Source

pub fn draw_image(&mut self, source: &dyn IImage, rect: Rect)

Draws an image into rect.

Source

pub fn draw_image_with_rects( &mut self, source: &dyn IImage, source_rect: Rect, dest_rect: Rect, )

Draws the part of an image inside source_rect into dest_rect.

Source

pub fn draw_bitmap( &mut self, source: &RefCounted<SharedBitmapImpl>, opacity: f64, source_rect: Rect, dest_rect: Rect, )

Draws a platform bitmap.

Source

pub fn draw_line(&mut self, pen: &Rc<dyn IPen>, p1: Point, p2: Point)

Draws a line.

Source

pub fn draw_geometry( &mut self, brush: Option<&Rc<dyn IBrush>>, pen: Option<&Rc<dyn IPen>>, geometry: &Ref<Geometry>, )

Draws a geometry.

Source

pub fn draw_geometry_impl( &mut self, brush: Option<&Rc<dyn IBrush>>, pen: Option<&Rc<dyn IPen>>, geometry: &Arc<dyn IGeometryImpl>, )

Draws a platform geometry.

Source

pub fn draw_rectangle( &mut self, brush: Option<&Rc<dyn IBrush>>, pen: Option<&Rc<dyn IPen>>, rect: Rect, radius_x: f64, radius_y: f64, box_shadows: &BoxShadows, )

Draws a rectangle with the specified brush and pen.

The brush and the pen can both be None. If the brush is None, no fill is performed. If the pen is None, no stroke is performed. If both are None and there are no box shadows, the call is a no-op.

Source

pub fn draw_rounded_rectangle( &mut self, brush: Option<&Rc<dyn IBrush>>, pen: Option<&Rc<dyn IPen>>, rrect: RoundedRect, box_shadows: &BoxShadows, )

Draws a rounded rectangle with the specified brush and pen.

Source

pub fn draw_rectangle_outline( &mut self, pen: &Rc<dyn IPen>, rect: Rect, corner_radius: f32, )

Draws the outline of a rectangle.

Source

pub fn fill_rectangle( &mut self, brush: &Rc<dyn IBrush>, rect: Rect, corner_radius: f32, )

Draws a filled rectangle.

Source

pub fn draw_ellipse_at( &mut self, brush: Option<&Rc<dyn IBrush>>, pen: Option<&Rc<dyn IPen>>, center: Point, radius_x: f64, radius_y: f64, )

Draws an ellipse given its center and radii.

Source

pub fn draw_ellipse( &mut self, brush: Option<&Rc<dyn IBrush>>, pen: Option<&Rc<dyn IPen>>, rect: Rect, )

Draws an ellipse inscribed in a rectangle.

Source

pub fn custom(&mut self, custom: &Arc<dyn ICustomDrawOperation>)

Draws a custom drawing operation.

Source

pub fn draw_text(&mut self, text: &FormattedText, origin: Point)

Draws text. origin is the upper-left corner of the text.

Source

pub fn draw_glyph_run( &mut self, foreground: Option<&Rc<dyn IBrush>>, glyph_run: &Rc<GlyphRun>, )

Draws a glyph run.

Source

pub fn draw_rectangle_acrylic( &mut self, material: &dyn IExperimentalAcrylicMaterial, rect: RoundedRect, )

Draws a rectangle filled with an acrylic-like material. A core without acrylic support fills the rectangle with the fallback color of the material; see IDrawingContextCore::draw_rectangle_acrylic_core.

Source

pub fn pop(&mut self, state: PushedState)

Pops a pushed state (C# PushedState.Dispose).

Panics if the state is not the most recently pushed one. Popping PushedState::NONE, or any state after the context has been disposed, does nothing.

Source

pub fn scope(&mut self, state: PushedState) -> PushedScope<'_, 'a>

Turns a pushed state into a guard that derefs to the context and pops the state when dropped.

Source

pub fn push_rounded_clip(&mut self, clip: RoundedRect) -> PushedState

Pushes a rounded clip rectangle.

Source

pub fn push_clip(&mut self, clip: Rect) -> PushedState

Pushes a clip rectangle.

Source

pub fn push_geometry_clip(&mut self, clip: &Ref<Geometry>) -> PushedState

Pushes a clip geometry.

Source

pub fn push_opacity(&mut self, opacity: f64) -> PushedState

Pushes an opacity value.

Source

pub fn push_opacity_mask( &mut self, mask: &Rc<dyn IBrush>, bounds: Rect, ) -> PushedState

Pushes an opacity mask.

bounds are the bounds of the control, used to place brushes correctly.

Source

pub fn push_transform(&mut self, matrix: Matrix) -> PushedState

Pushes a matrix transformation.

Source

pub fn push_render_options( &mut self, render_options: RenderOptions, ) -> PushedState

Pushes render options.

Source

pub fn push_text_options(&mut self, text_options: TextOptions) -> PushedState

Pushes text options.

Source

pub fn push_effect( &mut self, effect: &Rc<dyn IEffect>, bounds: Rect, ) -> PushedState

Pushes an effect applied to everything drawn until the state is popped. bounds are the bounds of the affected content.

Trait Implementations§

Source§

impl Drop for DrawingContext<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl ITextDrawingSink for DrawingContext<'_>

Text draws itself through the sink members, which are the corresponding drawing context members. A sink push has no state token: its pop restores the state pushed last, which is the transform the matching push pushed because text balances its pushes.

Source§

fn draw_glyph_run( &mut self, foreground: Option<&Rc<dyn IBrush>>, glyph_run: &Rc<GlyphRun>, )

Draws a glyph run (DrawingContext.DrawGlyphRun(IBrush? foreground, GlyphRun glyphRun)).
Source§

fn draw_rectangle( &mut self, brush: Option<&Rc<dyn IBrush>>, pen: Option<&Rc<dyn IPen>>, rect: Rect, )

Draws a rectangle with the specified brush and pen (DrawingContext.DrawRectangle(IBrush? brush, IPen? pen, Rect rect)).
Source§

fn draw_line(&mut self, pen: &Rc<dyn IPen>, p1: Point, p2: Point)

Draws a line (DrawingContext.DrawLine(IPen pen, Point p1, Point p2)).
Source§

fn push_transform(&mut self, matrix: Matrix)

Pushes a matrix transformation (DrawingContext.PushTransform(Matrix matrix)). Every push is balanced by one ITextDrawingSink::pop_transform.
Source§

fn pop_transform(&mut self)

Pops the transformation pushed last (disposing upstream’s PushedState).

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for DrawingContext<'a>

§

impl<'a> !Send for DrawingContext<'a>

§

impl<'a> !Sync for DrawingContext<'a>

§

impl<'a> !UnwindSafe for DrawingContext<'a>

§

impl<'a> Freeze for DrawingContext<'a>

§

impl<'a> Unpin for DrawingContext<'a>

§

impl<'a> UnsafeUnpin for DrawingContext<'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
Source§

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

Source§

fn static_constructor()

The static constructor of a type: work done once per thread, after the properties of the type are registered and before its first instance exists (class handlers, affects_render, metadata overrides). Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.