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
7impl Path {
8 /// Calls @func for every operation of the path.
9 ///
10 /// Note that this may only approximate @self, because paths can contain
11 /// optimizations for various specialized contours, and depending on the
12 /// @flags, the path may be decomposed into simpler curves than the ones
13 /// that it contained originally.
14 ///
15 /// This function serves two purposes:
16 ///
17 /// - When the @flags allow everything, it provides access to the raw,
18 /// unmodified data of the path.
19 /// - When the @flags disallow certain operations, it provides
20 /// an approximation of the path using just the allowed operations.
21 /// ## `flags`
22 /// flags to pass to the foreach function
23 /// ## `func`
24 /// the function to call for operations
25 ///
26 /// # Returns
27 ///
28 /// false if @func returned false, true otherwise.
29 #[doc(alias = "gsk_path_foreach")]
30 pub fn foreach<P: FnMut(&PathOperation, &graphene::Point, usize, f32) -> glib::ControlFlow>(
31 &self,
32 flags: PathForeachFlags,
33 func: P,
34 ) -> glib::ControlFlow {
35 let mut func_data: P = func;
36 unsafe extern "C" fn func_func<
37 P: FnMut(&PathOperation, &graphene::Point, usize, f32) -> glib::ControlFlow,
38 >(
39 op: ffi::GskPathOperation,
40 pts: *const graphene::ffi::graphene_point_t,
41 n_pts: libc::size_t,
42 weight: libc::c_float,
43 user_data: glib::ffi::gpointer,
44 ) -> glib::ffi::gboolean {
45 let op = from_glib(op);
46 let pts = from_glib_borrow(pts);
47 let callback = user_data as *mut P;
48 (*callback)(&op, &pts, n_pts, weight).into_glib()
49 }
50 let func = Some(func_func::<P> as _);
51 let super_callback0: &mut P = &mut func_data;
52 unsafe {
53 from_glib(ffi::gsk_path_foreach(
54 self.to_glib_none().0,
55 flags.into_glib(),
56 func,
57 super_callback0 as *mut _ as *mut _,
58 ))
59 }
60 }
61}
62
63impl std::str::FromStr for Path {
64 type Err = glib::BoolError;
65 fn from_str(s: &str) -> Result<Self, Self::Err> {
66 assert_initialized_main_thread!();
67 Path::parse(s)
68 }
69}