pub struct PathBuilder { /* private fields */ }
v4_14
only.Expand description
An auxiliary object for constructing Path
objects.
A path is constructed like this:
⚠️ The following code is in C ⚠️
GskPath *
construct_path (void)
{
GskPathBuilder *builder;
builder = gsk_path_builder_new ();
// add contours to the path here
return gsk_path_builder_free_to_path (builder);
Adding contours to the path can be done in two ways.
The easiest option is to use the gsk_path_builder_add_*
group
of functions that add predefined contours to the current path,
either common shapes like add_circle()
or by adding from other paths like add_path()
.
The gsk_path_builder_add_*
methods always add complete contours,
and do not use or modify the current point.
The other option is to define each line and curve manually with
the gsk_path_builder_*_to
group of functions. You start with
a call to move_to()
to set the starting point
and then use multiple calls to any of the drawing functions to
move the pen along the plane. Once you are done, you can call
close()
to close the path by connecting it
back with a line to the starting point.
This is similar to how paths are drawn in Cairo.
Note that PathBuilder
will reduce the degree of added Bézier
curves as much as possible, to simplify rendering.
GLib type: Shared boxed type with reference counted clone semantics.
Implementations§
Source§impl PathBuilder
impl PathBuilder
Sourcepub fn as_ptr(&self) -> *mut GskPathBuilder
pub fn as_ptr(&self) -> *mut GskPathBuilder
Return the inner pointer to the underlying C value.
Sourcepub unsafe fn from_glib_ptr_borrow(ptr: &*mut GskPathBuilder) -> &Self
pub unsafe fn from_glib_ptr_borrow(ptr: &*mut GskPathBuilder) -> &Self
Borrows the underlying C value.
Source§impl PathBuilder
impl PathBuilder
Sourcepub fn new() -> PathBuilder
pub fn new() -> PathBuilder
Create a new PathBuilder
object.
The resulting builder would create an empty Path
.
Use addition functions to add types to it.
§Returns
a new PathBuilder
Sourcepub fn add_circle(&self, center: &Point, radius: f32)
pub fn add_circle(&self, center: &Point, radius: f32)
Sourcepub fn add_layout(&self, layout: &Layout)
pub fn add_layout(&self, layout: &Layout)
Sourcepub fn add_rect(&self, rect: &Rect)
pub fn add_rect(&self, rect: &Rect)
Adds a rectangle as a new contour.
The path is going around the rectangle in clockwise direction.
If the the width or height are 0, the path will be a closed horizontal or vertical line. If both are 0, it’ll be a closed dot.
§rect
the rectangle to create a path for
Sourcepub fn add_reverse_path(&self, path: &Path)
pub fn add_reverse_path(&self, path: &Path)
Sourcepub fn add_rounded_rect(&self, rect: &RoundedRect)
pub fn add_rounded_rect(&self, rect: &RoundedRect)
Adds a rounded rectangle as a new contour.
The path is going around the rectangle in clockwise direction.
§rect
the rounded rect
Sourcepub fn add_segment(&self, path: &Path, start: &PathPoint, end: &PathPoint)
pub fn add_segment(&self, path: &Path, start: &PathPoint, end: &PathPoint)
Adds a segment of a path to the builder.
If @start is equal to or after @end, the path will first add the segment from @start to the end of the path, and then add the segment from the beginning to @end. If the path is closed, these segments will be connected.
Note that this method always adds a path with the given start point
and end point. To add a closed path, use add_path()
.
§path
the path to take the segment to
§start
the point on @path to start at
§end
the point on @path to end at
Sourcepub fn arc_to(&self, x1: f32, y1: f32, x2: f32, y2: f32)
pub fn arc_to(&self, x1: f32, y1: f32, x2: f32, y2: f32)
Adds an elliptical arc from the current point to @x2, @y2 with @x1, @y1 determining the tangent directions.
After this, @x2, @y2 will be the new current point.
Note: Two points and their tangents do not determine
a unique ellipse, so GSK just picks one. If you need more
precise control, use conic_to()
or svg_arc_to()
.
Sourcepub fn close(&self)
pub fn close(&self)
Ends the current contour with a line back to the start point.
Note that this is different from calling line_to()
with the start point in that the contour will be closed. A closed
contour behaves differently from an open one. When stroking, its
start and end point are considered connected, so they will be
joined via the line join, and not ended with line caps.
Sourcepub fn conic_to(&self, x1: f32, y1: f32, x2: f32, y2: f32, weight: f32)
pub fn conic_to(&self, x1: f32, y1: f32, x2: f32, y2: f32, weight: f32)
Adds a conic curve from the current point to @x2, @y2 with the given @weight and @x1, @y1 as the control point.
The weight determines how strongly the curve is pulled towards the control point. A conic with weight 1 is identical to a quadratic Bézier curve with the same points.
Conic curves can be used to draw ellipses and circles. They are also known as rational quadratic Bézier curves.
After this, @x2, @y2 will be the new current point.
## `x1` x coordinate of control point ## `y1` y coordinate of control point ## `x2` x coordinate of the end of the curve ## `y2` y coordinate of the end of the curve ## `weight` weight of the control point, must be greater than zeroSourcepub fn cubic_to(&self, x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32)
pub fn cubic_to(&self, x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32)
Adds a cubic Bézier curve from the current point to @x3, @y3 with @x1, @y1 and @x2, @y2 as the control points.
After this, @x3, @y3 will be the new current point.
## `x1` x coordinate of first control point ## `y1` y coordinate of first control point ## `x2` x coordinate of second control point ## `y2` y coordinate of second control point ## `x3` x coordinate of the end of the curve ## `y3` y coordinate of the end of the curveSourcepub fn current_point(&self) -> Point
pub fn current_point(&self) -> Point
Gets the current point.
The current point is used for relative drawing commands and updated after every operation.
When the builder is created, the default current point is set
to 0, 0
. Note that this is different from cairo, which starts
out without a current point.
§Returns
the current point
Sourcepub fn html_arc_to(&self, x1: f32, y1: f32, x2: f32, y2: f32, radius: f32)
pub fn html_arc_to(&self, x1: f32, y1: f32, x2: f32, y2: f32, radius: f32)
Implements arc-to according to the HTML Canvas spec.
A convenience function that implements the HTML arc_to functionality.
After this, the current point will be the point where the circle with the given radius touches the line from @x1, @y1 to @x2, @y2.
§x1
x coordinate of first control point
§y1
y coordinate of first control point
§x2
x coordinate of second control point
§y2
y coordinate of second control point
§radius
radius of the circle
Sourcepub fn line_to(&self, x: f32, y: f32)
pub fn line_to(&self, x: f32, y: f32)
Draws a line from the current point to @x, @y and makes it the new current point.
## `x` x coordinate ## `y` y coordinateSourcepub fn quad_to(&self, x1: f32, y1: f32, x2: f32, y2: f32)
pub fn quad_to(&self, x1: f32, y1: f32, x2: f32, y2: f32)
Adds a quadratic Bézier curve from the current point to @x2, @y2 with @x1, @y1 as the control point.
After this, @x2, @y2 will be the new current point.
## `x1` x coordinate of control point ## `y1` y coordinate of control point ## `x2` x coordinate of the end of the curve ## `y2` y coordinate of the end of the curveSourcepub fn rel_arc_to(&self, x1: f32, y1: f32, x2: f32, y2: f32)
pub fn rel_arc_to(&self, x1: f32, y1: f32, x2: f32, y2: f32)
Adds an elliptical arc from the current point to @x2, @y2 with @x1, @y1 determining the tangent directions.
All coordinates are given relative to the current point.
This is the relative version of arc_to()
.
§x1
x coordinate of first control point
§y1
y coordinate of first control point
§x2
x coordinate of second control point
§y2
y coordinate of second control point
Sourcepub fn rel_conic_to(&self, x1: f32, y1: f32, x2: f32, y2: f32, weight: f32)
pub fn rel_conic_to(&self, x1: f32, y1: f32, x2: f32, y2: f32, weight: f32)
Adds a conic curve from the current point to @x2, @y2 with the given @weight and @x1, @y1 as the control point.
All coordinates are given relative to the current point.
This is the relative version of conic_to()
.
§x1
x offset of control point
§y1
y offset of control point
§x2
x offset of the end of the curve
§y2
y offset of the end of the curve
§weight
weight of the curve, must be greater than zero
Sourcepub fn rel_cubic_to(&self, x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32)
pub fn rel_cubic_to(&self, x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32)
Adds a cubic Bézier curve from the current point to @x3, @y3 with @x1, @y1 and @x2, @y2 as the control points.
All coordinates are given relative to the current point.
This is the relative version of cubic_to()
.
§x1
x offset of first control point
§y1
y offset of first control point
§x2
x offset of second control point
§y2
y offset of second control point
§x3
x offset of the end of the curve
§y3
y offset of the end of the curve
Sourcepub fn rel_html_arc_to(&self, x1: f32, y1: f32, x2: f32, y2: f32, radius: f32)
pub fn rel_html_arc_to(&self, x1: f32, y1: f32, x2: f32, y2: f32, radius: f32)
Implements arc-to according to the HTML Canvas spec.
All coordinates are given relative to the current point.
This is the relative version of html_arc_to()
.
§x1
x coordinate of first control point
§y1
y coordinate of first control point
§x2
x coordinate of second control point
§y2
y coordinate of second control point
§radius
radius of the circle
Sourcepub fn rel_line_to(&self, x: f32, y: f32)
pub fn rel_line_to(&self, x: f32, y: f32)
Sourcepub fn rel_move_to(&self, x: f32, y: f32)
pub fn rel_move_to(&self, x: f32, y: f32)
Sourcepub fn rel_quad_to(&self, x1: f32, y1: f32, x2: f32, y2: f32)
pub fn rel_quad_to(&self, x1: f32, y1: f32, x2: f32, y2: f32)
Adds a quadratic Bézier curve from the current point to @x2, @y2 with @x1, @y1 the control point.
All coordinates are given relative to the current point.
This is the relative version of quad_to()
.
§x1
x offset of control point
§y1
y offset of control point
§x2
x offset of the end of the curve
§y2
y offset of the end of the curve
Sourcepub fn rel_svg_arc_to(
&self,
rx: f32,
ry: f32,
x_axis_rotation: f32,
large_arc: bool,
positive_sweep: bool,
x: f32,
y: f32,
)
pub fn rel_svg_arc_to( &self, rx: f32, ry: f32, x_axis_rotation: f32, large_arc: bool, positive_sweep: bool, x: f32, y: f32, )
Implements arc-to according to the SVG spec.
All coordinates are given relative to the current point.
This is the relative version of svg_arc_to()
.
§rx
x radius
§ry
y radius
§x_axis_rotation
the rotation of the ellipsis
§large_arc
whether to add the large arc
§positive_sweep
whether to sweep in the positive direction
§x
x coordinate of the endpoint
§y
y coordinate of the endpoint
Sourcepub fn svg_arc_to(
&self,
rx: f32,
ry: f32,
x_axis_rotation: f32,
large_arc: bool,
positive_sweep: bool,
x: f32,
y: f32,
)
pub fn svg_arc_to( &self, rx: f32, ry: f32, x_axis_rotation: f32, large_arc: bool, positive_sweep: bool, x: f32, y: f32, )
Implements arc-to according to the SVG spec.
A convenience function that implements the SVG arc_to functionality.
After this, @x, @y will be the new current point.
§rx
x radius
§ry
y radius
§x_axis_rotation
the rotation of the ellipsis
§large_arc
whether to add the large arc
§positive_sweep
whether to sweep in the positive direction
§x
x coordinate of the endpoint
§y
y coordinate of the endpoint
Sourcepub fn to_path(&self) -> Path
pub fn to_path(&self) -> Path
Creates a new path from the given builder.
The given PathBuilder
is reset once this function returns;
you cannot call this function multiple times on the same builder
instance.
This function is intended primarily for language bindings.
C code should use Gsk::PathBuilder::free_to_path()
.
§Returns
the newly created path with all the contours added to the builder
Source§impl PathBuilder
impl PathBuilder
Sourcepub fn add_cairo_path(&self, path: &Path)
pub fn add_cairo_path(&self, path: &Path)
Adds a Cairo path to the builder.
You can use cairo_copy_path() to access the path from a Cairo context.
§path
a path
Trait Implementations§
Source§impl Clone for PathBuilder
impl Clone for PathBuilder
Source§impl Debug for PathBuilder
impl Debug for PathBuilder
Source§impl Default for PathBuilder
impl Default for PathBuilder
Source§impl From<PathBuilder> for Value
impl From<PathBuilder> for Value
Source§fn from(s: PathBuilder) -> Self
fn from(s: PathBuilder) -> Self
Source§impl HasParamSpec for PathBuilder
impl HasParamSpec for PathBuilder
type ParamSpec = ParamSpecBoxed
Source§type SetValue = PathBuilder
type SetValue = PathBuilder
type BuilderFn = fn(_: &str) -> ParamSpecBoxedBuilder<'_, PathBuilder>
fn param_spec_builder() -> Self::BuilderFn
Source§impl Hash for PathBuilder
impl Hash for PathBuilder
Source§impl Ord for PathBuilder
impl Ord for PathBuilder
Source§fn cmp(&self, other: &PathBuilder) -> Ordering
fn cmp(&self, other: &PathBuilder) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for PathBuilder
impl PartialEq for PathBuilder
Source§impl PartialOrd for PathBuilder
impl PartialOrd for PathBuilder
Source§impl StaticType for PathBuilder
impl StaticType for PathBuilder
Source§fn static_type() -> Type
fn static_type() -> Type
Self
.