[go: up one dir, main page]

gdk4/
toplevel_size.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use crate::{ffi, prelude::*};
4use glib::translate::*;
5
6#[repr(transparent)]
7#[doc(alias = "GdkToplevelSize")]
8pub struct ToplevelSize(std::ptr::NonNull<ffi::GdkToplevelSize>);
9
10impl StaticType for ToplevelSize {
11    fn static_type() -> glib::Type {
12        unsafe { from_glib(ffi::gdk_toplevel_size_get_type()) }
13    }
14}
15
16impl ToplevelSize {
17    #[doc(alias = "gdk_toplevel_size_get_bounds")]
18    #[doc(alias = "get_bounds")]
19    pub fn bounds(&self) -> (i32, i32) {
20        unsafe {
21            let mut bounds_width = std::mem::MaybeUninit::uninit();
22            let mut bounds_height = std::mem::MaybeUninit::uninit();
23
24            ffi::gdk_toplevel_size_get_bounds(
25                self.0.as_ptr(),
26                bounds_width.as_mut_ptr(),
27                bounds_height.as_mut_ptr(),
28            );
29            (bounds_width.assume_init(), bounds_height.assume_init())
30        }
31    }
32
33    #[doc(alias = "gdk_toplevel_size_set_min_size")]
34    pub fn set_min_size(&mut self, min_width: i32, min_height: i32) {
35        unsafe {
36            ffi::gdk_toplevel_size_set_min_size(self.0.as_mut(), min_width, min_height);
37        }
38    }
39
40    #[doc(alias = "gdk_toplevel_size_set_shadow_width")]
41    pub fn set_shadow_width(&mut self, left: i32, right: i32, top: i32, bottom: i32) {
42        unsafe {
43            ffi::gdk_toplevel_size_set_shadow_width(self.0.as_mut(), left, right, top, bottom);
44        }
45    }
46
47    #[doc(alias = "gdk_toplevel_size_set_size")]
48    pub fn set_size(&mut self, width: i32, height: i32) {
49        unsafe {
50            ffi::gdk_toplevel_size_set_size(self.0.as_mut(), width, height);
51        }
52    }
53}
54
55impl std::fmt::Debug for ToplevelSize {
56    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
57        f.debug_struct("ToplevelSize")
58            .field("bounds", &self.bounds())
59            .finish()
60    }
61}