gsk4/auto/
path_measure.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{ffi, Path, PathPoint};
6use glib::translate::*;
7
8glib::wrapper! {
9    /// An object that allows measurements on paths such as determining
10    /// the length of the path.
11    ///
12    /// Many measuring operations require sampling the path length
13    /// at intermediate points. Therefore, a [`PathMeasure`][crate::PathMeasure] has
14    /// a tolerance that determines what precision is required
15    /// for such approximations.
16    ///
17    /// A [`PathMeasure`][crate::PathMeasure] struct is a reference counted struct
18    /// and should be treated as opaque.
19    #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
20    pub struct PathMeasure(Shared<ffi::GskPathMeasure>);
21
22    match fn {
23        ref => |ptr| ffi::gsk_path_measure_ref(ptr),
24        unref => |ptr| ffi::gsk_path_measure_unref(ptr),
25        type_ => || ffi::gsk_path_measure_get_type(),
26    }
27}
28
29impl PathMeasure {
30    /// Creates a measure object for the given @path with the
31    /// default tolerance.
32    /// ## `path`
33    /// the path to measure
34    ///
35    /// # Returns
36    ///
37    /// a new [`PathMeasure`][crate::PathMeasure] representing @path
38    #[doc(alias = "gsk_path_measure_new")]
39    pub fn new(path: &Path) -> PathMeasure {
40        assert_initialized_main_thread!();
41        unsafe { from_glib_full(ffi::gsk_path_measure_new(path.to_glib_none().0)) }
42    }
43
44    /// Creates a measure object for the given @path and @tolerance.
45    /// ## `path`
46    /// the path to measure
47    /// ## `tolerance`
48    /// the tolerance for measuring operations
49    ///
50    /// # Returns
51    ///
52    /// a new [`PathMeasure`][crate::PathMeasure] representing @path
53    #[doc(alias = "gsk_path_measure_new_with_tolerance")]
54    #[doc(alias = "new_with_tolerance")]
55    pub fn with_tolerance(path: &Path, tolerance: f32) -> PathMeasure {
56        assert_initialized_main_thread!();
57        unsafe {
58            from_glib_full(ffi::gsk_path_measure_new_with_tolerance(
59                path.to_glib_none().0,
60                tolerance,
61            ))
62        }
63    }
64
65    /// Gets the length of the path being measured.
66    ///
67    /// The length is cached, so this function does not do any work.
68    ///
69    /// # Returns
70    ///
71    /// the length of the path measured by @self
72    #[doc(alias = "gsk_path_measure_get_length")]
73    #[doc(alias = "get_length")]
74    pub fn length(&self) -> f32 {
75        unsafe { ffi::gsk_path_measure_get_length(self.to_glib_none().0) }
76    }
77
78    /// Returns the path that the measure was created for.
79    ///
80    /// # Returns
81    ///
82    /// the path of @self
83    #[doc(alias = "gsk_path_measure_get_path")]
84    #[doc(alias = "get_path")]
85    pub fn path(&self) -> Path {
86        unsafe { from_glib_none(ffi::gsk_path_measure_get_path(self.to_glib_none().0)) }
87    }
88
89    /// Gets the point at the given distance into the path.
90    ///
91    /// An empty path has no points, so false is returned in that case.
92    /// ## `distance`
93    /// the distance
94    ///
95    /// # Returns
96    ///
97    /// true if @result was set
98    ///
99    /// ## `result`
100    /// return location for the point
101    #[doc(alias = "gsk_path_measure_get_point")]
102    #[doc(alias = "get_point")]
103    pub fn point(&self, distance: f32) -> Option<PathPoint> {
104        unsafe {
105            let mut result = PathPoint::uninitialized();
106            let ret = from_glib(ffi::gsk_path_measure_get_point(
107                self.to_glib_none().0,
108                distance,
109                result.to_glib_none_mut().0,
110            ));
111            if ret {
112                Some(result)
113            } else {
114                None
115            }
116        }
117    }
118
119    /// Returns the tolerance that the measure was created with.
120    ///
121    /// # Returns
122    ///
123    /// the tolerance of @self
124    #[doc(alias = "gsk_path_measure_get_tolerance")]
125    #[doc(alias = "get_tolerance")]
126    pub fn tolerance(&self) -> f32 {
127        unsafe { ffi::gsk_path_measure_get_tolerance(self.to_glib_none().0) }
128    }
129}