# DrawingContext

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-base/media/struct-drawingcontext/

**struct** · [`ferroui-base`](/docs/0.5.0/api/ferroui-base/) · v0.5.0

```rust
struct DrawingContext<'a>
```

The surface a visual draws itself onto during rendering.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/drawing_context.rs#L212)

## Members

- [`new`](#function-new)
- [`owned`](#function-owned)
- [`dispose`](#function-dispose)
- [`draw_image`](#function-draw_image)
- [`draw_image_with_rects`](#function-draw_image_with_rects)
- [`draw_line`](#function-draw_line)
- [`draw_geometry`](#function-draw_geometry)
- [`draw_rectangle`](#function-draw_rectangle)
- [`draw_rounded_rectangle`](#function-draw_rounded_rectangle)
- [`draw_rectangle_outline`](#function-draw_rectangle_outline)
- [`fill_rectangle`](#function-fill_rectangle)
- [`draw_ellipse_at`](#function-draw_ellipse_at)
- [`draw_ellipse`](#function-draw_ellipse)
- [`custom`](#function-custom)
- [`draw_text`](#function-draw_text)
- [`draw_glyph_run`](#function-draw_glyph_run)
- [`draw_rectangle_acrylic`](#function-draw_rectangle_acrylic)
- [`pop`](#function-pop)
- [`scope`](#function-scope)
- [`push_rounded_clip`](#function-push_rounded_clip)
- [`push_clip`](#function-push_clip)
- [`push_geometry_clip`](#function-push_geometry_clip)
- [`push_opacity`](#function-push_opacity)
- [`try_push_compositing_layer`](#function-try_push_compositing_layer)
- [`push_opacity_mask`](#function-push_opacity_mask)
- [`push_transform`](#function-push_transform)
- [`push_render_options`](#function-push_render_options)
- [`push_text_options`](#function-push_text_options)
- [`push_effect`](#function-push_effect)

<a id="function-new"></a>

### new

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/drawing_context.rs#L223)

<a id="function-owned"></a>

### owned

```rust
fn owned(core: Box<dyn IDrawingContextCore>) -> Self
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/drawing_context.rs#L229)

<a id="function-dispose"></a>

### dispose

```rust
fn dispose(self: Self)
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/drawing_context.rs#L243)

<a id="function-draw_image"></a>

### draw_image

```rust
fn draw_image(self: &mut Self, source: &dyn IImage, rect: Rect)
```

Draws an image into `rect`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/drawing_context.rs#L263)

<a id="function-draw_image_with_rects"></a>

### draw_image_with_rects

```rust
fn draw_image_with_rects(self: &mut Self, source: &dyn IImage, source_rect: Rect, dest_rect: Rect)
```

Draws the part of an image inside `source_rect` into `dest_rect`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/drawing_context.rs#L268)

<a id="function-draw_line"></a>

### draw_line

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

Draws a line.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/drawing_context.rs#L278)

<a id="function-draw_geometry"></a>

### draw_geometry

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

Draws a geometry.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/drawing_context.rs#L285)

<a id="function-draw_rectangle"></a>

### draw_rectangle

```rust
fn draw_rectangle(self: &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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/drawing_context.rs#L313)

<a id="function-draw_rounded_rectangle"></a>

### draw_rounded_rectangle

```rust
fn draw_rounded_rectangle(self: &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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/drawing_context.rs#L335)

<a id="function-draw_rectangle_outline"></a>

### draw_rectangle_outline

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

Draws the outline of a rectangle.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/drawing_context.rs#L349)

<a id="function-fill_rectangle"></a>

### fill_rectangle

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

Draws a filled rectangle.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/drawing_context.rs#L355)

<a id="function-draw_ellipse_at"></a>

### draw_ellipse_at

```rust
fn draw_ellipse_at(self: &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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/drawing_context.rs#L361)

<a id="function-draw_ellipse"></a>

### draw_ellipse

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

Draws an ellipse inscribed in a rectangle.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/drawing_context.rs#L379)

<a id="function-custom"></a>

### custom

```rust
fn custom(self: &mut Self, custom: &std::sync::Arc<dyn ICustomDrawOperation>)
```

Draws a custom drawing operation.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/drawing_context.rs#L386)

<a id="function-draw_text"></a>

### draw_text

```rust
fn draw_text(self: &mut Self, text: &FormattedText, origin: Point)
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/drawing_context.rs#L400)

<a id="function-draw_glyph_run"></a>

### draw_glyph_run

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

Draws a glyph run.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/drawing_context.rs#L405)

<a id="function-draw_rectangle_acrylic"></a>

### draw_rectangle_acrylic

```rust
fn draw_rectangle_acrylic(self: &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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/drawing_context.rs#L413)

<a id="function-pop"></a>

### pop

```rust
fn pop(self: &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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/drawing_context.rs#L445)

<a id="function-scope"></a>

### scope

```rust
fn scope(self: &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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/drawing_context.rs#L459)

<a id="function-push_rounded_clip"></a>

### push_rounded_clip

```rust
fn push_rounded_clip(self: &mut Self, clip: RoundedRect) -> PushedState
```

Pushes a rounded clip rectangle.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/drawing_context.rs#L464)

<a id="function-push_clip"></a>

### push_clip

```rust
fn push_clip(self: &mut Self, clip: Rect) -> PushedState
```

Pushes a clip rectangle.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/drawing_context.rs#L470)

<a id="function-push_geometry_clip"></a>

### push_geometry_clip

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

Pushes a clip geometry.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/drawing_context.rs#L476)

<a id="function-push_opacity"></a>

### push_opacity

```rust
fn push_opacity(self: &mut Self, opacity: f64) -> PushedState
```

Pushes an opacity value.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/drawing_context.rs#L482)

<a id="function-try_push_compositing_layer"></a>

### try_push_compositing_layer

```rust
fn try_push_compositing_layer(self: &mut Self, blend: BitmapBlendingMode, opacity: f64, bounds: Rect) -> Option<PushedState>
```

Draws subsequent vectors, text and images into one isolated group, then
blends that group with the content beneath it when the state is popped.
Opacity applies once to the complete group, including overlapping draws.

`bounds` is a conservative content/effect bound in the current coordinate
space. It is an allocation hint, not a clip. Blend modes reuse the same
enumeration as bitmap compositing but apply here to the entire group.

Returns None without pushing a state when the backend lacks compositing
layers or arguments are non-finite/invalid. Recording contexts consult
the registered backend capability; a caller can choose an explicit
bitmap fallback instead of silently accepting a different blend mode.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/drawing_context.rs#L499)

<a id="function-push_opacity_mask"></a>

### push_opacity_mask

```rust
fn push_opacity_mask(self: &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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/drawing_context.rs#L520)

<a id="function-push_transform"></a>

### push_transform

```rust
fn push_transform(self: &mut Self, matrix: Matrix) -> PushedState
```

Pushes a matrix transformation.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/drawing_context.rs#L526)

<a id="function-push_render_options"></a>

### push_render_options

```rust
fn push_render_options(self: &mut Self, render_options: RenderOptions) -> PushedState
```

Pushes render options.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/drawing_context.rs#L532)

<a id="function-push_text_options"></a>

### push_text_options

```rust
fn push_text_options(self: &mut Self, text_options: TextOptions) -> PushedState
```

Pushes text options.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/drawing_context.rs#L538)

<a id="function-push_effect"></a>

### push_effect

```rust
fn push_effect(self: &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.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/drawing_context.rs#L545)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- [`ClassDefaults`](/docs/0.5.0/api/ferroui-base/trait-classdefaults/)
- `Borrow<T>`
- `BorrowMut<T>`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- `ErasedDestructor`
- `IntoEither`
- [`ITextDrawingSink`](/docs/0.5.0/api/ferroui-base/media/text_formatting/trait-itextdrawingsink/)
- `Drop`

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
