gsk4/
path.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use glib::translate::*;
4
5use crate::{ffi, Path, PathForeachFlags, PathOperation};
6#[cfg(feature = "v4_20")]
7use crate::{PathIntersection, PathPoint};
8
9impl Path {
10    #[doc(alias = "gsk_path_foreach")]
11    pub fn foreach<P: FnMut(&PathOperation, &graphene::Point, usize, f32) -> glib::ControlFlow>(
12        &self,
13        flags: PathForeachFlags,
14        func: P,
15    ) -> glib::ControlFlow {
16        let mut func_data: P = func;
17        unsafe extern "C" fn func_func<
18            P: FnMut(&PathOperation, &graphene::Point, usize, f32) -> glib::ControlFlow,
19        >(
20            op: ffi::GskPathOperation,
21            pts: *const graphene::ffi::graphene_point_t,
22            n_pts: libc::size_t,
23            weight: libc::c_float,
24            user_data: glib::ffi::gpointer,
25        ) -> glib::ffi::gboolean {
26            let op = from_glib(op);
27            let pts = from_glib_borrow(pts);
28            let callback = user_data as *mut P;
29            (*callback)(&op, &pts, n_pts, weight).into_glib()
30        }
31        let func = Some(func_func::<P> as _);
32        let super_callback0: &mut P = &mut func_data;
33        unsafe {
34            from_glib(ffi::gsk_path_foreach(
35                self.to_glib_none().0,
36                flags.into_glib(),
37                func,
38                super_callback0 as *mut _ as *mut _,
39            ))
40        }
41    }
42
43    #[cfg(feature = "v4_20")]
44    #[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
45    #[doc(alias = "gsk_path_foreach_intersection")]
46    pub fn foreach_intersection<
47        P: FnMut(&Path, &PathPoint, &Path, &PathPoint, PathIntersection) -> bool,
48    >(
49        &self,
50        path2: Option<&Path>,
51        func: P,
52    ) -> bool {
53        let mut func_data: P = func;
54        unsafe extern "C" fn func_func<
55            P: FnMut(&Path, &PathPoint, &Path, &PathPoint, PathIntersection) -> bool,
56        >(
57            path1: *mut ffi::GskPath,
58            point1: *const ffi::GskPathPoint,
59            path2: *mut ffi::GskPath,
60            point2: *const ffi::GskPathPoint,
61            kind: ffi::GskPathIntersection,
62            user_data: glib::ffi::gpointer,
63        ) -> glib::ffi::gboolean {
64            let path1 = from_glib_borrow(path1);
65            let point1 = from_glib_borrow(point1);
66            let path2 = from_glib_borrow(path2);
67            let point2 = from_glib_borrow(point2);
68            let kind = from_glib(kind);
69            let callback = user_data as *mut P;
70            (*callback)(&path1, &point1, &path2, &point2, kind).into_glib()
71        }
72        let func = Some(func_func::<P> as _);
73        let super_callback0: &mut P = &mut func_data;
74        unsafe {
75            from_glib(ffi::gsk_path_foreach_intersection(
76                self.to_glib_none().0,
77                path2.to_glib_none().0,
78                func,
79                super_callback0 as *mut _ as *mut _,
80            ))
81        }
82    }
83}
84
85impl std::str::FromStr for Path {
86    type Err = glib::BoolError;
87    fn from_str(s: &str) -> Result<Self, Self::Err> {
88        assert_initialized_main_thread!();
89        Path::parse(s)
90    }
91}