gdk4/
surface.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, prelude::*, Surface};
6
7mod sealed {
8    pub trait Sealed {}
9    impl<T: super::IsA<super::Surface>> Sealed for T {}
10}
11
12// rustdoc-stripper-ignore-next
13/// Trait containing manually implemented methods of
14/// [`Surface`](crate::Surface).
15pub trait SurfaceExtManual: sealed::Sealed + IsA<Surface> + 'static {
16    /// Create a new Cairo surface that is as compatible as possible with the
17    /// given @self.
18    ///
19    /// For example the new surface will have the same fallback resolution
20    /// and font options as @self. Generally, the new surface will also
21    /// use the same backend as @self, unless that is not possible for
22    /// some reason. The type of the returned surface may be examined with
23    /// cairo_surface_get_type().
24    ///
25    /// Initially the surface contents are all 0 (transparent if contents
26    /// have transparency, black otherwise.)
27    ///
28    /// This function always returns a valid pointer, but it will return a
29    /// pointer to a “nil” surface if @other is already in an error state
30    /// or any other error occurs.
31    ///
32    /// # Deprecated since 4.12
33    ///
34    /// Create a suitable cairo image surface yourself
35    /// ## `content`
36    /// the content for the new surface
37    /// ## `width`
38    /// width of the new surface
39    /// ## `height`
40    /// height of the new surface
41    ///
42    /// # Returns
43    ///
44    /// a pointer to the newly allocated surface. The caller
45    ///   owns the surface and should call cairo_surface_destroy() when done
46    ///   with it.
47    #[doc(alias = "gdk_surface_create_similar_surface")]
48    fn create_similar_surface(
49        &self,
50        content: cairo::Content,
51        width: i32,
52        height: i32,
53    ) -> cairo::Surface {
54        unsafe {
55            from_glib_full(ffi::gdk_surface_create_similar_surface(
56                self.as_ref().to_glib_none().0,
57                content.into(),
58                width,
59                height,
60            ))
61        }
62    }
63
64    // Returns true if the coordinates were successfully translated
65    /// Translates coordinates between two surfaces.
66    ///
67    /// Note that this only works if @to and @self are popups or
68    /// transient-for to the same toplevel (directly or indirectly).
69    /// ## `to`
70    /// the target surface
71    /// ## `x`
72    /// coordinates to translate
73    /// ## `y`
74    /// coordinates to translate
75    ///
76    /// # Returns
77    ///
78    /// [`true`] if the coordinates were successfully translated
79    #[doc(alias = "gdk_surface_translate_coordinates")]
80    fn translate_coordinates(&self, to: &Surface, mut x: f64, mut y: f64) -> bool {
81        unsafe {
82            from_glib(ffi::gdk_surface_translate_coordinates(
83                self.as_ref().to_glib_none().0,
84                to.to_glib_none().0,
85                &mut x,
86                &mut y,
87            ))
88        }
89    }
90}
91
92impl<O: IsA<Surface>> SurfaceExtManual for O {}