Painter
Provides the drawing operations used to render custom content. A Painter is passed to the paint
handler of a Canvas.
class Painter
A Painter cannot be instantiated directly. It is provided to the paint handler of a Canvas.
Methods
draw_arc
draw_arc(center: Point, radius: Float, start_angle: Angle, end_angle: Angle) -> ()
Draws an arc around center with the given radius, spanning from start_angle to end_angle.
A positive angle will draw counter-clockwise.
draw_circle
draw_circle(center: Point, radius: Float) -> ()
Draws a circle centered at the given center with radius.
draw_ellipse
draw_ellipse(_ frame: Rect) -> ()
Draws an ellipse into the given frame.
draw_line
draw_line(from: Point, to: Point) -> ()
Draws a line starting at from to to.
draw_path
draw_path(_ path: Path) -> ()
Draws the given path.
See Path
draw_pie
draw_pie(frame: Rect, start_angle: Angle, end_angle: Angle) -> ()
Draws a pie shape into the given frame, spanning from start_angle to end_angle.
A positive angle will draw counter-clockwise.
draw_rect
draw_rect(_ frame: Rect) -> ()
Draws a rectangle into the given frame.
restore
restore() -> ()
Restores a previously saved painter state. See save.
rotate
rotate(_ angle: Angle) -> ()
Rotates the coordinate system clockwise.
save
save() -> ()
Save the current painter state onto a stack. Use restore to rewind the painter to a previously saved state.
scale
scale(x: Float, y: Float) -> ()
Scales the coordinate system by x & y.
set_dash_offset
set_dash_offset(_ offset: Float) -> ()
Offsets the starting point of the dash pattern. The offset is measured in terms of the units used to specify the dash pattern.
set_dash_pattern
set_dash_pattern(_ pattern: [Float]) -> ()
Set the dash pattern for drawing the strokes. The array must specify an even number of positive numbers. The even entries define the dashes and the odd entries the spaces. The dash pattern is specified in units of the line width, e.g. a dash of length 4 in line width 10 is 40 pixels long. Note that a zero line width is equivalent to a 1 pixel width.
To enable solid line drawing set an empty pattern.
The dashes are also subject to the cap style, see set_line_cap
set_fill
set_fill(_ color: Color?) -> ()
Sets the fill color for drawing. Set to nil to disable drawing fills.
set_line_cap
set_line_cap(_ cap: CapStyle) -> ()
Defines how to draw the end caps of a line. See CapStyle
set_line_join
set_line_join(_ join: JoinStyle) -> ()
Defines how two lines are joined. See JoinStyle
set_line_width
set_line_width(_ width: Float) -> ()
Sets the width of the stroke.
set_opacity
set_opacity(_ value: Float) -> ()
Sets the opacity of the painter. The value should be in the range 0.0 and 1.0.
set_stroke
set_stroke(_ color: Color?) -> ()
Sets the stroke color for drawing. Set to nil to disable drawing strokes.
shear
shear(h: Float, v: Float) -> ()
Shears the coordinate system by h & v.
translate
translate(x: Float, y: Float) -> ()
Translates the coordinate system by x & y.