Struct gsk4::PathBuilder

source ·
#[repr(transparent)]
pub struct PathBuilder { /* private fields */ }
Available on crate feature v4_14 only.
Expand description

PathBuilder is 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.

Implementations§

source§

impl PathBuilder

source

pub fn as_ptr(&self) -> *mut GskPathBuilder

Return the inner pointer to the underlying C value.

source

pub unsafe fn from_glib_ptr_borrow<'a>( ptr: *const *const GskPathBuilder ) -> &'a Self

Borrows the underlying C value.

source§

impl PathBuilder

source

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

source

pub fn add_circle(&self, center: &Point, radius: f32)

Adds a circle with the @center and @radius.

The path is going around the circle in clockwise direction.

If @radius is zero, the contour will be a closed point.

center

the center of the circle

radius

the radius of the circle

source

pub fn add_layout(&self, layout: &Layout)

Adds the outlines for the glyphs in @layout to the builder.

layout

the pango layout to add

source

pub fn add_path(&self, path: &Path)

Appends all of @path to the builder.

path

the path to append

source

pub fn add_rect(&self, rect: &Rect)

Adds @rect as a new contour to the path built by the builder.

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

source

pub fn add_reverse_path(&self, path: &Path)

Appends all of @path to the builder, in reverse order.

path

the path to append

source

pub fn add_rounded_rect(&self, rect: &RoundedRect)

Adds @rect as a new contour to the path built in @self.

The path is going around the rectangle in clockwise direction.

rect

the rounded rect

source

pub fn add_segment(&self, path: &Path, start: &PathPoint, end: &PathPoint)

Adds to @self the segment of @path from @start to @end.

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

source

pub fn arc_to(&self, x1: f32, y1: f32, x2: f32, y2: f32)

Adds an elliptical arc from the current point to @x3, @y3 with @x1, @y1 determining the tangent directions.

After this, @x3, @y3 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().

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
source

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.

source

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.

Conic To ## `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 zero
source

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.

Cubic 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 ## `x3` x coordinate of the end of the curve ## `y3` y coordinate of the end of the curve
source

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

source

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

source

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.

Line To ## `x` x coordinate ## `y` y coordinate
source

pub fn move_to(&self, x: f32, y: f32)

Starts a new contour by placing the pen at @x, @y.

If this function is called twice in succession, the first call will result in a contour made up of a single point. The second call will start a new contour.

x

x coordinate

y

y coordinate

source

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.

Quad To ## `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
source

pub fn rel_arc_to(&self, x1: f32, y1: f32, x2: f32, y2: f32)

Adds an elliptical arc from the current point to @x3, @y3 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

source

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

source

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

source

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

source

pub fn rel_line_to(&self, x: f32, y: f32)

Draws a line from the current point to a point offset from it by @x, @y and makes it the new current point.

This is the relative version of line_to().

x

x offset

y

y offset

source

pub fn rel_move_to(&self, x: f32, y: f32)

Starts a new contour by placing the pen at @x, @y relative to the current point.

This is the relative version of move_to().

x

x offset

y

y offset

source

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

source

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

the X coordinate of the endpoint

y

the Y coordinate of the endpoint

source

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

the X coordinate of the endpoint

y

the Y coordinate of the endpoint

source

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

source

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.

Trait Implementations§

source§

impl Clone for PathBuilder

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for PathBuilder

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for PathBuilder

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl From<PathBuilder> for Value

source§

fn from(s: PathBuilder) -> Self

Converts to this type from the input type.
source§

impl HasParamSpec for PathBuilder

§

type ParamSpec = ParamSpecBoxed

§

type SetValue = PathBuilder

Preferred value to be used as setter for the associated ParamSpec.
§

type BuilderFn = fn(_: &str) -> ParamSpecBoxedBuilder<'_, PathBuilder>

source§

fn param_spec_builder() -> Self::BuilderFn

source§

impl Hash for PathBuilder

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for PathBuilder

source§

fn cmp(&self, other: &PathBuilder) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<PathBuilder> for PathBuilder

source§

fn eq(&self, other: &PathBuilder) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<PathBuilder> for PathBuilder

source§

fn partial_cmp(&self, other: &PathBuilder) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl StaticType for PathBuilder

source§

fn static_type() -> Type

Returns the type identifier of Self.
source§

impl Eq for PathBuilder

source§

impl StructuralEq for PathBuilder

source§

impl StructuralPartialEq for PathBuilder

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

unsafe fn from_glib_none_num_as_vec( ptr: *const GPtrArray, num: usize ) -> Vec<T, Global>

source§

unsafe fn from_glib_container_num_as_vec( _: *const GPtrArray, _: usize ) -> Vec<T, Global>

source§

unsafe fn from_glib_full_num_as_vec( _: *const GPtrArray, _: usize ) -> Vec<T, Global>

source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

unsafe fn from_glib_none_num_as_vec( ptr: *const GSList, num: usize ) -> Vec<T, Global>

source§

unsafe fn from_glib_container_num_as_vec( _: *const GSList, _: usize ) -> Vec<T, Global>

source§

unsafe fn from_glib_full_num_as_vec( _: *const GSList, _: usize ) -> Vec<T, Global>

source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

unsafe fn from_glib_none_num_as_vec( ptr: *mut GList, num: usize ) -> Vec<T, Global>

source§

unsafe fn from_glib_container_num_as_vec( ptr: *mut GList, num: usize ) -> Vec<T, Global>

source§

unsafe fn from_glib_full_num_as_vec( ptr: *mut GList, num: usize ) -> Vec<T, Global>

source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

unsafe fn from_glib_none_num_as_vec( ptr: *mut GPtrArray, num: usize ) -> Vec<T, Global>

source§

unsafe fn from_glib_container_num_as_vec( ptr: *mut GPtrArray, num: usize ) -> Vec<T, Global>

source§

unsafe fn from_glib_full_num_as_vec( ptr: *mut GPtrArray, num: usize ) -> Vec<T, Global>

source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

unsafe fn from_glib_none_num_as_vec( ptr: *mut GSList, num: usize ) -> Vec<T, Global>

source§

unsafe fn from_glib_container_num_as_vec( ptr: *mut GSList, num: usize ) -> Vec<T, Global>

source§

unsafe fn from_glib_full_num_as_vec( ptr: *mut GSList, num: usize ) -> Vec<T, Global>

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

unsafe fn from_glib_none_as_vec(ptr: *const GPtrArray) -> Vec<T, Global>

source§

unsafe fn from_glib_container_as_vec(_: *const GPtrArray) -> Vec<T, Global>

source§

unsafe fn from_glib_full_as_vec(_: *const GPtrArray) -> Vec<T, Global>

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

unsafe fn from_glib_none_as_vec(ptr: *mut GList) -> Vec<T, Global>

source§

unsafe fn from_glib_container_as_vec(ptr: *mut GList) -> Vec<T, Global>

source§

unsafe fn from_glib_full_as_vec(ptr: *mut GList) -> Vec<T, Global>

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

unsafe fn from_glib_none_as_vec(ptr: *mut GPtrArray) -> Vec<T, Global>

source§

unsafe fn from_glib_container_as_vec(ptr: *mut GPtrArray) -> Vec<T, Global>

source§

unsafe fn from_glib_full_as_vec(ptr: *mut GPtrArray) -> Vec<T, Global>

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

unsafe fn from_glib_none_as_vec(ptr: *mut GSList) -> Vec<T, Global>

source§

unsafe fn from_glib_container_as_vec(ptr: *mut GSList) -> Vec<T, Global>

source§

unsafe fn from_glib_full_as_vec(ptr: *mut GSList) -> Vec<T, Global>

source§

impl<T, U> Into<U> for Twhere 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> IntoClosureReturnValue for Twhere T: Into<Value>,

source§

impl<T> Property for Twhere T: HasParamSpec,

§

type Value = T

source§

impl<T> PropertyGet for Twhere T: HasParamSpec,

§

type Value = T

source§

fn get<R, F>(&self, f: F) -> Rwhere F: Fn(&<T as PropertyGet>::Value) -> R,

source§

impl<T> StaticTypeExt for Twhere T: StaticType,

source§

fn ensure_type()

Ensures that the type has been registered with the type system.
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> TransparentType for Twhere T: TransparentPtrType,

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T> TryFromClosureReturnValue for Twhere T: for<'a> FromValue<'a> + StaticType + 'static,

source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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.
source§

impl<'a, T, C, E> FromValueOptional<'a> for Twhere T: FromValue<'a, Checker = C>, C: ValueTypeChecker<Error = ValueTypeMismatchOrNoneError<E>>, E: Error + Send + 'static,