Skip to main content

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::{Surface, ffi, prelude::*};
6
7// rustdoc-stripper-ignore-next
8/// Trait containing manually implemented methods of
9/// [`Surface`](crate::Surface).
10pub trait SurfaceExtManual: IsA<Surface> + 'static {
11    ///  surface if @other is already in an error state
12    /// or any other error occurs.
13    ///
14    /// # Deprecated since 4.12
15    ///
16    /// Create a suitable cairo image surface yourself
17    /// ## `content`
18    /// the content for the new surface
19    /// ## `width`
20    /// width of the new surface
21    /// ## `height`
22    /// height of the new surface
23    ///
24    /// # Returns
25    ///
26    /// a pointer to the newly allocated surface. The caller
27    ///   owns the surface and should call cairo_surface_destroy() when done
28    ///   with it.
29    #[doc(alias = "gdk_surface_create_similar_surface")]
30    fn create_similar_surface(
31        &self,
32        content: cairo::Content,
33        width: i32,
34        height: i32,
35    ) -> cairo::Surface {
36        unsafe {
37            from_glib_full(ffi::gdk_surface_create_similar_surface(
38                self.as_ref().to_glib_none().0,
39                content.into(),
40                width,
41                height,
42            ))
43        }
44    }
45
46    // Returns true if the coordinates were successfully translated
47    /// Translates coordinates between two surfaces.
48    ///
49    /// Note that this only works if @to and @self are popups or
50    /// transient-for to the same toplevel (directly or indirectly).
51    /// ## `to`
52    /// the target surface
53    ///
54    /// # Returns
55    ///
56    /// [`true`] if the coordinates were successfully translated
57    ///
58    /// ## `x`
59    /// coordinates to translate
60    ///
61    /// ## `y`
62    /// coordinates to translate
63    #[doc(alias = "gdk_surface_translate_coordinates")]
64    fn translate_coordinates(&self, to: &Surface, mut x: f64, mut y: f64) -> bool {
65        unsafe {
66            from_glib(ffi::gdk_surface_translate_coordinates(
67                self.as_ref().to_glib_none().0,
68                to.to_glib_none().0,
69                &mut x,
70                &mut y,
71            ))
72        }
73    }
74}
75
76impl<O: IsA<Surface>> SurfaceExtManual for O {}