gsk4

Struct PathBuilder

Source
pub struct PathBuilder { /* private fields */ }
Available on crate feature 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

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(ptr: &*mut GskPathBuilder) -> &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 as a new contour.

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 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

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 a rounded rectangle as a new contour.

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 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

Source

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().

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 @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

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

x coordinate of the endpoint

§y

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

x coordinate of the endpoint

§y

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.

§path

a path

Trait Implementations§

Source§

impl Clone for PathBuilder

Source§

fn clone(&self) -> Self

Makes a clone of this shared reference.

This increments the strong reference count of the reference. Dropping the reference will decrement it again.

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

Source§

type ParamSpec = ParamSpecBoxed

Source§

type SetValue = PathBuilder

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

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) -> Self
where Self: Sized,

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

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

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

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

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

impl PartialEq for PathBuilder

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd 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

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

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

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

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 StructuralPartialEq for PathBuilder

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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 T

Source§

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

Source§

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

Source§

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

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for T

Source§

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

Source§

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

Source§

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

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for T

Source§

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

Source§

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

Source§

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

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for T

Source§

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

Source§

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

Source§

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

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for T

Source§

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

Source§

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

Source§

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

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for T

Source§

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

Source§

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

Source§

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

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for T

Source§

unsafe fn from_glib_none_as_vec(ptr: *const GList) -> Vec<T>

Source§

unsafe fn from_glib_container_as_vec(_: *const GList) -> Vec<T>

Source§

unsafe fn from_glib_full_as_vec(_: *const GList) -> Vec<T>

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for T

Source§

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

Source§

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

Source§

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

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for T

Source§

unsafe fn from_glib_none_as_vec(ptr: *const GSList) -> Vec<T>

Source§

unsafe fn from_glib_container_as_vec(_: *const GSList) -> Vec<T>

Source§

unsafe fn from_glib_full_as_vec(_: *const GSList) -> Vec<T>

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for T

Source§

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

Source§

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

Source§

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

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for T

Source§

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

Source§

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

Source§

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

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for T

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl<T> Property for T
where T: HasParamSpec,

Source§

type Value = T

Source§

impl<T> PropertyGet for T
where T: HasParamSpec,

Source§

type Value = T

Source§

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

Source§

impl<T> StaticTypeExt for T
where T: StaticType,

Source§

fn ensure_type()

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

impl<T> ToOwned for T
where T: Clone,

Source§

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 T

Source§

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

Source§

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 T
where T: for<'a> FromValue<'a> + StaticType + 'static,

Source§

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

Source§

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 T
where T: FromValue<'a, Checker = C>, C: ValueTypeChecker<Error = ValueTypeMismatchOrNoneError<E>>, E: Error + Send + 'static,