1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Take a look at the license at the top of the repository in the LICENSE file.

use crate::{Path, PathForeachFlags, PathOperation};
use glib::translate::*;

impl Path {
    /// 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`][crate::PathForeachFlags]
    ///   for details about flags
    /// ## `func`
    /// the function to call for operations
    ///
    /// # Returns
    ///
    /// `FALSE` if @func returned FALSE`, `TRUE` otherwise.
    #[doc(alias = "gsk_path_foreach")]
    pub fn foreach<P: FnMut(&PathOperation, &graphene::Point, usize, f32) -> bool>(
        &self,
        flags: PathForeachFlags,
        func: P,
    ) -> bool {
        let func_data: P = func;
        unsafe extern "C" fn func_func<
            P: FnMut(&PathOperation, &graphene::Point, usize, f32) -> bool,
        >(
            op: ffi::GskPathOperation,
            pts: *const graphene::ffi::graphene_point_t,
            n_pts: libc::size_t,
            weight: libc::c_float,
            user_data: glib::ffi::gpointer,
        ) -> glib::ffi::gboolean {
            let op = from_glib(op);
            let pts = from_glib_borrow(pts);
            let callback: *mut P = user_data as *const _ as usize as *mut P;
            (*callback)(&op, &pts, n_pts, weight).into_glib()
        }
        let func = Some(func_func::<P> as _);
        let super_callback0: &P = &func_data;
        unsafe {
            from_glib(ffi::gsk_path_foreach(
                self.to_glib_none().0,
                flags.into_glib(),
                func,
                super_callback0 as *const _ as usize as *mut _,
            ))
        }
    }
}

impl std::str::FromStr for Path {
    type Err = glib::BoolError;
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        assert_initialized_main_thread!();
        Path::parse(s)
    }
}