pub trait DrawScope {
Show 44 methods
// Required methods
fn size(&self) -> Size;
fn draw_content(&mut self);
fn draw_rect(&mut self, brush: Brush);
fn draw_rect_blend(&mut self, brush: Brush, blend_mode: BlendMode);
fn draw_rect_at(&mut self, rect: Rect, brush: Brush);
fn draw_rect_at_blend(
&mut self,
rect: Rect,
brush: Brush,
blend_mode: BlendMode,
);
fn draw_round_rect(&mut self, brush: Brush, radii: CornerRadii);
fn draw_round_rect_blend(
&mut self,
brush: Brush,
radii: CornerRadii,
blend_mode: BlendMode,
);
fn draw_round_rect_at(
&mut self,
rect: Rect,
brush: Brush,
radii: CornerRadii,
);
fn draw_circle(&mut self, brush: Brush, center: Point, radius: f32);
fn draw_circle_blend(
&mut self,
brush: Brush,
center: Point,
radius: f32,
blend_mode: BlendMode,
);
fn draw_rect_stroked(&mut self, brush: Brush, stroke: Stroke);
fn draw_rect_stroked_blend(
&mut self,
brush: Brush,
stroke: Stroke,
blend_mode: BlendMode,
);
fn draw_rect_at_stroked(&mut self, rect: Rect, brush: Brush, stroke: Stroke);
fn draw_rect_at_stroked_blend(
&mut self,
rect: Rect,
brush: Brush,
stroke: Stroke,
blend_mode: BlendMode,
);
fn draw_round_rect_stroked(
&mut self,
brush: Brush,
radii: CornerRadii,
stroke: Stroke,
);
fn draw_round_rect_stroked_blend(
&mut self,
brush: Brush,
radii: CornerRadii,
stroke: Stroke,
blend_mode: BlendMode,
);
fn draw_round_rect_at_stroked(
&mut self,
rect: Rect,
brush: Brush,
radii: CornerRadii,
stroke: Stroke,
);
fn draw_round_rect_at_stroked_blend(
&mut self,
rect: Rect,
brush: Brush,
radii: CornerRadii,
stroke: Stroke,
blend_mode: BlendMode,
);
fn draw_circle_stroked(
&mut self,
brush: Brush,
center: Point,
radius: f32,
stroke: Stroke,
);
fn draw_circle_stroked_blend(
&mut self,
brush: Brush,
center: Point,
radius: f32,
stroke: Stroke,
blend_mode: BlendMode,
);
fn draw_arc(
&mut self,
brush: Brush,
center: Point,
radius: f32,
start_angle: f32,
sweep_angle: f32,
stroke: Stroke,
);
fn draw_arc_blend(
&mut self,
brush: Brush,
center: Point,
radius: f32,
start_angle: f32,
sweep_angle: f32,
stroke: Stroke,
blend_mode: BlendMode,
);
fn draw_line(
&mut self,
brush: Brush,
start: Point,
end: Point,
stroke: Stroke,
);
fn draw_line_blend(
&mut self,
brush: Brush,
start: Point,
end: Point,
stroke: Stroke,
blend_mode: BlendMode,
);
fn draw_path(&mut self, path: &Path, brush: Brush, style: DrawStyle);
fn draw_path_blend(
&mut self,
path: &Path,
brush: Brush,
style: DrawStyle,
blend_mode: BlendMode,
);
fn draw_annular_sector(
&mut self,
brush: Brush,
center: Point,
inner_radius: f32,
outer_radius: f32,
start_angle: f32,
sweep_angle: f32,
);
fn draw_annular_sector_blend(
&mut self,
brush: Brush,
center: Point,
inner_radius: f32,
outer_radius: f32,
start_angle: f32,
sweep_angle: f32,
blend_mode: BlendMode,
);
fn draw_image(&mut self, image: ImageBitmap);
fn draw_image_blend(&mut self, image: ImageBitmap, blend_mode: BlendMode);
fn draw_image_at(
&mut self,
rect: Rect,
image: ImageBitmap,
alpha: f32,
color_filter: Option<ColorFilter>,
);
fn draw_image_at_sampled(
&mut self,
rect: Rect,
image: ImageBitmap,
alpha: f32,
color_filter: Option<ColorFilter>,
sampling: ImageSampling,
);
fn draw_image_at_blend(
&mut self,
rect: Rect,
image: ImageBitmap,
alpha: f32,
color_filter: Option<ColorFilter>,
blend_mode: BlendMode,
);
fn draw_image_src(
&mut self,
image: ImageBitmap,
src_rect: Rect,
dst_rect: Rect,
alpha: f32,
color_filter: Option<ColorFilter>,
);
fn draw_image_src_sampled(
&mut self,
image: ImageBitmap,
src_rect: Rect,
dst_rect: Rect,
alpha: f32,
color_filter: Option<ColorFilter>,
sampling: ImageSampling,
);
fn draw_image_src_blend(
&mut self,
image: ImageBitmap,
src_rect: Rect,
dst_rect: Rect,
alpha: f32,
color_filter: Option<ColorFilter>,
blend_mode: BlendMode,
);
fn draw_vector_path(&mut self, path: &VectorPath, brush: Brush);
fn measure_text(&self, text: &str, style: &DrawTextStyle) -> TextMeasurement;
fn draw_text_at(
&mut self,
rect: Rect,
brush: Brush,
text: &str,
style: &DrawTextStyle,
);
fn into_primitives(self) -> Vec<DrawPrimitive>;
// Provided methods
fn draw_svg_path(&mut self, d: &str, brush: Brush) { ... }
fn draw_text(&mut self, brush: Brush, text: &str, style: &DrawTextStyle) { ... }
fn draw_text_from(
&mut self,
top_left: Point,
brush: Brush,
text: &str,
style: &DrawTextStyle,
) { ... }
}Expand description
The drawing surface passed to draw modifiers. Compose’s DrawScope. Every method records a
primitive in scope coordinates, with the origin at the top-left corner of the node, and the
_blend forms composite with a given blend mode instead of SrcOver.
Required Methods§
Sourcefn draw_content(&mut self)
fn draw_content(&mut self)
Marks where the node’s own content draws, as Compose’s drawContent() does in
drawWithContent. Draws recorded before the marker paint under the content and draws after
it paint over it.
Sourcefn draw_rect_blend(&mut self, brush: Brush, blend_mode: BlendMode)
fn draw_rect_blend(&mut self, brush: Brush, blend_mode: BlendMode)
As draw_rect, composited with blend_mode instead of SrcOver.
Sourcefn draw_rect_at(&mut self, rect: Rect, brush: Brush)
fn draw_rect_at(&mut self, rect: Rect, brush: Brush)
Draws a rectangle at the specified position and size.
Sourcefn draw_rect_at_blend(
&mut self,
rect: Rect,
brush: Brush,
blend_mode: BlendMode,
)
fn draw_rect_at_blend( &mut self, rect: Rect, brush: Brush, blend_mode: BlendMode, )
As draw_rect_at, composited with blend_mode instead of SrcOver.
Sourcefn draw_round_rect(&mut self, brush: Brush, radii: CornerRadii)
fn draw_round_rect(&mut self, brush: Brush, radii: CornerRadii)
Fills the whole scope rect with rounded corners of radii.
Sourcefn draw_round_rect_blend(
&mut self,
brush: Brush,
radii: CornerRadii,
blend_mode: BlendMode,
)
fn draw_round_rect_blend( &mut self, brush: Brush, radii: CornerRadii, blend_mode: BlendMode, )
As draw_round_rect, composited with blend_mode instead of SrcOver.
Sourcefn draw_round_rect_at(&mut self, rect: Rect, brush: Brush, radii: CornerRadii)
fn draw_round_rect_at(&mut self, rect: Rect, brush: Brush, radii: CornerRadii)
Draws a rounded rectangle at the specified position and size.
Sourcefn draw_circle(&mut self, brush: Brush, center: Point, radius: f32)
fn draw_circle(&mut self, brush: Brush, center: Point, radius: f32)
Fills a circle of radius around center, in scope coordinates.
Sourcefn draw_circle_blend(
&mut self,
brush: Brush,
center: Point,
radius: f32,
blend_mode: BlendMode,
)
fn draw_circle_blend( &mut self, brush: Brush, center: Point, radius: f32, blend_mode: BlendMode, )
As draw_circle, composited with blend_mode instead of SrcOver.
Sourcefn draw_rect_stroked(&mut self, brush: Brush, stroke: Stroke)
fn draw_rect_stroked(&mut self, brush: Brush, stroke: Stroke)
Strokes the outline of the whole scope rect.
Sourcefn draw_rect_stroked_blend(
&mut self,
brush: Brush,
stroke: Stroke,
blend_mode: BlendMode,
)
fn draw_rect_stroked_blend( &mut self, brush: Brush, stroke: Stroke, blend_mode: BlendMode, )
As draw_rect_stroked, composited with blend_mode instead of SrcOver.
Sourcefn draw_rect_at_stroked(&mut self, rect: Rect, brush: Brush, stroke: Stroke)
fn draw_rect_at_stroked(&mut self, rect: Rect, brush: Brush, stroke: Stroke)
Strokes the outline of rect.
Sourcefn draw_rect_at_stroked_blend(
&mut self,
rect: Rect,
brush: Brush,
stroke: Stroke,
blend_mode: BlendMode,
)
fn draw_rect_at_stroked_blend( &mut self, rect: Rect, brush: Brush, stroke: Stroke, blend_mode: BlendMode, )
As draw_rect_at_stroked, composited with blend_mode instead of SrcOver.
Sourcefn draw_round_rect_stroked(
&mut self,
brush: Brush,
radii: CornerRadii,
stroke: Stroke,
)
fn draw_round_rect_stroked( &mut self, brush: Brush, radii: CornerRadii, stroke: Stroke, )
Strokes the outline of the whole scope rect with rounded corners.
Sourcefn draw_round_rect_stroked_blend(
&mut self,
brush: Brush,
radii: CornerRadii,
stroke: Stroke,
blend_mode: BlendMode,
)
fn draw_round_rect_stroked_blend( &mut self, brush: Brush, radii: CornerRadii, stroke: Stroke, blend_mode: BlendMode, )
As draw_round_rect_stroked, composited with blend_mode instead of SrcOver.
Sourcefn draw_round_rect_at_stroked(
&mut self,
rect: Rect,
brush: Brush,
radii: CornerRadii,
stroke: Stroke,
)
fn draw_round_rect_at_stroked( &mut self, rect: Rect, brush: Brush, radii: CornerRadii, stroke: Stroke, )
Strokes the outline of rect with rounded corners.
Sourcefn draw_round_rect_at_stroked_blend(
&mut self,
rect: Rect,
brush: Brush,
radii: CornerRadii,
stroke: Stroke,
blend_mode: BlendMode,
)
fn draw_round_rect_at_stroked_blend( &mut self, rect: Rect, brush: Brush, radii: CornerRadii, stroke: Stroke, blend_mode: BlendMode, )
As draw_round_rect_at_stroked, composited with blend_mode instead of SrcOver.
Sourcefn draw_circle_stroked(
&mut self,
brush: Brush,
center: Point,
radius: f32,
stroke: Stroke,
)
fn draw_circle_stroked( &mut self, brush: Brush, center: Point, radius: f32, stroke: Stroke, )
Strokes a circle outline. Lowers to a stroked rounded rect, so it shares the fill pipeline and batches with every other shape.
Sourcefn draw_circle_stroked_blend(
&mut self,
brush: Brush,
center: Point,
radius: f32,
stroke: Stroke,
blend_mode: BlendMode,
)
fn draw_circle_stroked_blend( &mut self, brush: Brush, center: Point, radius: f32, stroke: Stroke, blend_mode: BlendMode, )
As draw_circle_stroked, composited with blend_mode instead of SrcOver.
Sourcefn draw_arc(
&mut self,
brush: Brush,
center: Point,
radius: f32,
start_angle: f32,
sweep_angle: f32,
stroke: Stroke,
)
fn draw_arc( &mut self, brush: Brush, center: Point, radius: f32, start_angle: f32, sweep_angle: f32, stroke: Stroke, )
Strokes a circular arc.
Angles are in radians, 0 points along +X, and increasing
angles sweep clockwise on screen (Cranpose uses y-down device
coordinates, so this matches atan2(dy, dx) and the sweep-gradient
brush). A negative sweep_angle sweeps counter-clockwise; |sweep| >= 2π draws a closed ring.
The stroke is centered on radius, so the band covers
radius ± width/2. StrokeCap shapes the two ends.
Nothing is drawn for a zero sweep, a non-positive width, or non-finite
input.
Sourcefn draw_arc_blend(
&mut self,
brush: Brush,
center: Point,
radius: f32,
start_angle: f32,
sweep_angle: f32,
stroke: Stroke,
blend_mode: BlendMode,
)
fn draw_arc_blend( &mut self, brush: Brush, center: Point, radius: f32, start_angle: f32, sweep_angle: f32, stroke: Stroke, blend_mode: BlendMode, )
As draw_arc, composited with blend_mode instead of SrcOver.
Sourcefn draw_line(&mut self, brush: Brush, start: Point, end: Point, stroke: Stroke)
fn draw_line(&mut self, brush: Brush, start: Point, end: Point, stroke: Stroke)
Strokes the straight segment from start to end, centred on it and
stroke.width wide, its ends shaped by stroke.cap: Compose’s
drawLine(brush, start, end, strokeWidth, cap). Nothing is drawn
for a non-positive width, a non-finite end, or a segment of no length
between butt caps; round and square caps draw a dot there.
Sourcefn draw_line_blend(
&mut self,
brush: Brush,
start: Point,
end: Point,
stroke: Stroke,
blend_mode: BlendMode,
)
fn draw_line_blend( &mut self, brush: Brush, start: Point, end: Point, stroke: Stroke, blend_mode: BlendMode, )
As draw_line, composited with blend_mode instead of SrcOver.
Sourcefn draw_path(&mut self, path: &Path, brush: Brush, style: DrawStyle)
fn draw_path(&mut self, path: &Path, brush: Brush, style: DrawStyle)
Fills or strokes path with brush: Compose’s
drawPath(path, brush, style). A fill closes every contour and
rasterizes it as draw_vector_path does. A
stroke draws each flattened edge as a line on the GPU, capped at an
open contour’s ends and joined at its corners as
crate::for_each_stroke_line describes; a dashed stroke draws the
dashes its effect cuts. Where edges meet, a translucent stroke is
painted twice.
Sourcefn draw_path_blend(
&mut self,
path: &Path,
brush: Brush,
style: DrawStyle,
blend_mode: BlendMode,
)
fn draw_path_blend( &mut self, path: &Path, brush: Brush, style: DrawStyle, blend_mode: BlendMode, )
As draw_path, composited with blend_mode instead of SrcOver.
Sourcefn draw_annular_sector(
&mut self,
brush: Brush,
center: Point,
inner_radius: f32,
outer_radius: f32,
start_angle: f32,
sweep_angle: f32,
)
fn draw_annular_sector( &mut self, brush: Brush, center: Point, inner_radius: f32, outer_radius: f32, start_angle: f32, sweep_angle: f32, )
Fills an annular sector — the region between inner_radius and
outer_radius, limited to an angular sweep, with flat radial ends.
This is the shape a stroked arc cannot express: its ends are straight
lines through the center, not caps. inner_radius = 0 fills a pie
wedge. Angle convention is identical to draw_arc.
Nothing is drawn when inner_radius >= outer_radius, the sweep is zero,
or any input is non-finite.
Sourcefn draw_annular_sector_blend(
&mut self,
brush: Brush,
center: Point,
inner_radius: f32,
outer_radius: f32,
start_angle: f32,
sweep_angle: f32,
blend_mode: BlendMode,
)
fn draw_annular_sector_blend( &mut self, brush: Brush, center: Point, inner_radius: f32, outer_radius: f32, start_angle: f32, sweep_angle: f32, blend_mode: BlendMode, )
As draw_annular_sector, composited with blend_mode instead of SrcOver.
Sourcefn draw_image(&mut self, image: ImageBitmap)
fn draw_image(&mut self, image: ImageBitmap)
Draws image stretched over the whole scope rect.
Sourcefn draw_image_blend(&mut self, image: ImageBitmap, blend_mode: BlendMode)
fn draw_image_blend(&mut self, image: ImageBitmap, blend_mode: BlendMode)
As draw_image, composited with blend_mode instead of SrcOver.
Sourcefn draw_image_at(
&mut self,
rect: Rect,
image: ImageBitmap,
alpha: f32,
color_filter: Option<ColorFilter>,
)
fn draw_image_at( &mut self, rect: Rect, image: ImageBitmap, alpha: f32, color_filter: Option<ColorFilter>, )
Draws image stretched into rect, with alpha from 0.0 to 1.0 and an optional
color_filter.
Sourcefn draw_image_at_sampled(
&mut self,
rect: Rect,
image: ImageBitmap,
alpha: f32,
color_filter: Option<ColorFilter>,
sampling: ImageSampling,
)
fn draw_image_at_sampled( &mut self, rect: Rect, image: ImageBitmap, alpha: f32, color_filter: Option<ColorFilter>, sampling: ImageSampling, )
As draw_image_at, sampling the image with sampling instead of nearest-neighbor.
Sourcefn draw_image_at_blend(
&mut self,
rect: Rect,
image: ImageBitmap,
alpha: f32,
color_filter: Option<ColorFilter>,
blend_mode: BlendMode,
)
fn draw_image_at_blend( &mut self, rect: Rect, image: ImageBitmap, alpha: f32, color_filter: Option<ColorFilter>, blend_mode: BlendMode, )
As draw_image_at, composited with blend_mode instead of SrcOver.
Sourcefn draw_image_src(
&mut self,
image: ImageBitmap,
src_rect: Rect,
dst_rect: Rect,
alpha: f32,
color_filter: Option<ColorFilter>,
)
fn draw_image_src( &mut self, image: ImageBitmap, src_rect: Rect, dst_rect: Rect, alpha: f32, color_filter: Option<ColorFilter>, )
Draws a sub-region of an image. src_rect is in image-pixel
coordinates; dst_rect is in scope coordinates.
Sourcefn draw_image_src_sampled(
&mut self,
image: ImageBitmap,
src_rect: Rect,
dst_rect: Rect,
alpha: f32,
color_filter: Option<ColorFilter>,
sampling: ImageSampling,
)
fn draw_image_src_sampled( &mut self, image: ImageBitmap, src_rect: Rect, dst_rect: Rect, alpha: f32, color_filter: Option<ColorFilter>, sampling: ImageSampling, )
As draw_image_src, sampling the source region with sampling instead of nearest-neighbor.
Sourcefn draw_image_src_blend(
&mut self,
image: ImageBitmap,
src_rect: Rect,
dst_rect: Rect,
alpha: f32,
color_filter: Option<ColorFilter>,
blend_mode: BlendMode,
)
fn draw_image_src_blend( &mut self, image: ImageBitmap, src_rect: Rect, dst_rect: Rect, alpha: f32, color_filter: Option<ColorFilter>, blend_mode: BlendMode, )
As draw_image_src_sampled, composited with blend_mode instead of SrcOver.
Sourcefn draw_vector_path(&mut self, path: &VectorPath, brush: Brush)
fn draw_vector_path(&mut self, path: &VectorPath, brush: Brush)
Fills a parsed SVG path in scope coordinates (path units are dp).
The fill is rasterized on the CPU into a supersampled, anti-aliased
bitmap covering the path bounds and drawn as an image primitive, so
it works on every render backend. Parse the path once with
crate::VectorPath::parse and redraw it per frame. Solid brushes
are honored exactly; gradient brushes currently fall back to their
first stop color.
Sourcefn measure_text(&self, text: &str, style: &DrawTextStyle) -> TextMeasurement
fn measure_text(&self, text: &str, style: &DrawTextStyle) -> TextMeasurement
The block size, line height and first baseline text would occupy in
style.
Free to call repeatedly: the underlying text stack caches metrics on
(text, style), so a game can measure every label every frame to center
it without touching a font file more than once.
Sourcefn draw_text_at(
&mut self,
rect: Rect,
brush: Brush,
text: &str,
style: &DrawTextStyle,
)
fn draw_text_at( &mut self, rect: Rect, brush: Brush, text: &str, style: &DrawTextStyle, )
Draws text inside rect, positioned by DrawTextStyle::align and
DrawTextStyle::vertical_align.
The glyphs are not clipped to rect — it is an alignment box, not a
viewport. A rect narrower than the measured text overflows in the
direction the alignment implies; clip the layer if that matters.
Sourcefn into_primitives(self) -> Vec<DrawPrimitive>
fn into_primitives(self) -> Vec<DrawPrimitive>
Consumes the scope and returns the recorded primitives in draw order, including the
Content markers.
Provided Methods§
Sourcefn draw_svg_path(&mut self, d: &str, brush: Brush)
fn draw_svg_path(&mut self, d: &str, brush: Brush)
Parses SVG path data (the d attribute syntax: M/m L/l H/h V/v C/c S/s Q/q T/t A/a Z/z) and fills it. Invalid path data draws
nothing. Prefer crate::VectorPath::parse +
draw_vector_path to avoid re-parsing
and to surface parse errors.
Sourcefn draw_text(&mut self, brush: Brush, text: &str, style: &DrawTextStyle)
fn draw_text(&mut self, brush: Brush, text: &str, style: &DrawTextStyle)
Draws text inside the whole scope rect, positioned by
DrawTextStyle::align and DrawTextStyle::vertical_align.
Sourcefn draw_text_from(
&mut self,
top_left: Point,
brush: Brush,
text: &str,
style: &DrawTextStyle,
)
fn draw_text_from( &mut self, top_left: Point, brush: Brush, text: &str, style: &DrawTextStyle, )
Draws text with the top-left corner of its block at top_left.
Alignment is a no-op here because the box is the measurement — this is
the “I already know where it goes” form, and the one to pair with
measure_text for hand-rolled centering.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".