Struct gsk4::Path

source ·
pub struct Path { /* private fields */ }
Available on crate feature v4_14 only.
Expand description

A Path describes lines and curves that are more complex than simple rectangles.

Paths can used for rendering (filling or stroking) and for animations (e.g. as trajectories).

Path is an immutable, opaque, reference-counted struct. After creation, you cannot change the types it represents. Instead, new Path objects have to be created. The PathBuilder structure is meant to help in this endeavor.

Conceptually, a path consists of zero or more contours (continuous, connected curves), each of which may or may not be closed. Contours are typically constructed from Bézier segments.

A Path

Implementations§

source§

impl Path

source

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

Return the inner pointer to the underlying C value.

source

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

Borrows the underlying C value.

source§

impl Path

source

pub fn bounds(&self) -> Option<Rect>

Computes the bounds of the given path.

The returned bounds may be larger than necessary, because this function aims to be fast, not accurate. The bounds are guaranteed to contain the path.

It is possible that the returned rectangle has 0 width and/or height. This can happen when the path only describes a point or an axis-aligned line.

If the path is empty, FALSE is returned and @bounds are set to graphene_rect_zero(). This is different from the case where the path is a single point at the origin, where the @bounds will also be set to the zero rectangle but TRUE will be returned.

§Returns

TRUE if the path has bounds, FALSE if the path is known to be empty and have no bounds.

§bounds

the bounds of the given path

source

pub fn closest_point( &self, point: &Point, threshold: f32 ) -> Option<(PathPoint, f32)>

Computes the closest point on the path to the given point and sets the @result to it.

If there is no point closer than the given threshold, FALSE is returned.

§point

the point

§threshold

maximum allowed distance

§Returns

TRUE if @point was set to the closest point on @self, FALSE if no point is closer than @threshold

§result

return location for the closest point

§distance

return location for the distance

source

pub fn end_point(&self) -> Option<PathPoint>

Gets the end point of the path.

An empty path has no points, so FALSE is returned in this case.

§Returns

TRUE if @result was filled

§result

return location for point

source

pub fn start_point(&self) -> Option<PathPoint>

Gets the start point of the path.

An empty path has no points, so FALSE is returned in this case.

§Returns

TRUE if @result was filled

§result

return location for point

source

pub fn stroke_bounds(&self, stroke: &Stroke) -> Option<Rect>

Computes the bounds for stroking the given path with the parameters in @stroke.

The returned bounds may be larger than necessary, because this function aims to be fast, not accurate. The bounds are guaranteed to contain the area affected by the stroke, including protrusions like miters.

§stroke

stroke parameters

§Returns

TRUE if the path has bounds, FALSE if the path is known to be empty and have no bounds.

§bounds

the bounds to fill in

source

pub fn in_fill(&self, point: &Point, fill_rule: FillRule) -> bool

Returns whether the given point is inside the area that would be affected if the path was filled according to @fill_rule.

Note that this function assumes that filling a contour implicitly closes it.

§point

the point to test

§fill_rule

the fill rule to follow

§Returns

TRUE if @point is inside

source

pub fn is_closed(&self) -> bool

Returns if the path represents a single closed contour.

§Returns

TRUE if the path is closed

source

pub fn is_empty(&self) -> bool

Checks if the path is empty, i.e. contains no lines or curves.

§Returns

TRUE if the path is empty

source

pub fn to_cairo(&self, cr: &Context)

Appends the given @path to the given cairo context for drawing with Cairo.

This may cause some suboptimal conversions to be performed as Cairo does not support all features of Path.

This function does not clear the existing Cairo path. Call cairo_new_path() if you want this.

§cr

a cairo context

source

pub fn to_str(&self) -> GString

Converts the path into a string that is suitable for printing.

You can use this function in a debugger to get a quick overview of the path.

This is a wrapper around Gsk::Path::print(), see that function for details.

§Returns

A new string for @self

source

pub fn parse(string: &str) -> Result<Path, BoolError>

This is a convenience function that constructs a Path from a serialized form.

The string is expected to be in (a superset of) SVG path syntax, as e.g. produced by to_str().

A high-level summary of the syntax:

  • M x y Move to (x, y)
  • L x y Add a line from the current point to (x, y)
  • Q x1 y1 x2 y2 Add a quadratic Bézier from the current point to (x2, y2), with control point (x1, y1)
  • C x1 y1 x2 y2 x3 y3 Add a cubic Bézier from the current point to (x3, y3), with control points (x1, y1) and (x2, y2)
  • Z Close the contour by drawing a line back to the start point
  • H x Add a horizontal line from the current point to the given x value
  • V y Add a vertical line from the current point to the given y value
  • T x2 y2 Add a quadratic Bézier, using the reflection of the previous segments’ control point as control point
  • S x2 y2 x3 y3 Add a cubic Bézier, using the reflection of the previous segments’ second control point as first control point
  • A rx ry r l s x y Add an elliptical arc from the current point to (x, y) with radii rx and ry. See the SVG documentation for how the other parameters influence the arc.
  • O x1 y1 x2 y2 w Add a rational quadratic Bézier from the current point to (x2, y2) with control point (x1, y1) and weight w.

All the commands have lowercase variants that interpret coordinates relative to the current point.

The O command is an extension that is not supported in SVG.

§string

a string

§Returns

a new Path, or NULL if @string could not be parsed

source§

impl Path

source

pub fn foreach<P: FnMut(&PathOperation, &Point, usize, f32) -> ControlFlow>( &self, flags: PathForeachFlags, func: P ) -> ControlFlow

Calls @func for every operation of the path.

Note that this may only approximate @self, because paths can contain optimizations for various specialized contours, and depending on the @flags, the path may be decomposed into simpler curves than the ones that it contained originally.

This function serves two purposes:

  • When the @flags allow everything, it provides access to the raw, unmodified data of the path.
  • When the @flags disallow certain operations, it provides an approximation of the path using just the allowed operations.
§flags

flags to pass to the foreach function. See PathForeachFlags for details about flags

§func

the function to call for operations

§Returns

FALSE if @func returned FALSE, TRUE` otherwise.

Trait Implementations§

source§

impl Clone for Path

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 Path

source§

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

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

impl Display for Path

source§

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

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

impl From<Path> for Value

source§

fn from(s: Path) -> Self

Converts to this type from the input type.
source§

impl FromStr for Path

§

type Err = BoolError

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl HasParamSpec for Path

§

type ParamSpec = ParamSpecBoxed

§

type SetValue = Path

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

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

source§

fn param_spec_builder() -> Self::BuilderFn

source§

impl Hash for Path

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 Path

source§

fn cmp(&self, other: &Path) -> 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 + PartialOrd,

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

impl PartialEq for Path

source§

fn eq(&self, other: &Path) -> 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 for Path

source§

fn partial_cmp(&self, other: &Path) -> 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 Path

source§

fn static_type() -> Type

Returns the type identifier of Self.
source§

impl Eq for Path

source§

impl StructuralPartialEq for Path

Auto Trait Implementations§

§

impl Freeze for Path

§

impl RefUnwindSafe for Path

§

impl !Send for Path

§

impl !Sync for Path

§

impl Unpin for Path

§

impl UnwindSafe for Path

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

§

type Value = T

source§

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

§

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,

§

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T> TransparentType for T

source§

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

source§

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