1use std::ffi::c_void;
4
5use crate::{ffi, prelude::*};
6use glib::translate::*;
7
8#[repr(transparent)]
9#[doc(alias = "GdkToplevelSize")]
10pub struct ToplevelSize(pub(crate) std::ptr::NonNull<ffi::GdkToplevelSize>);
11
12impl StaticType for ToplevelSize {
13 fn static_type() -> glib::Type {
14 unsafe { from_glib(ffi::gdk_toplevel_size_get_type()) }
15 }
16}
17
18impl ToplevelSize {
19 #[doc(alias = "gdk_toplevel_size_get_bounds")]
20 #[doc(alias = "get_bounds")]
21 pub fn bounds(&self) -> (i32, i32) {
22 unsafe {
23 let mut bounds_width = std::mem::MaybeUninit::uninit();
24 let mut bounds_height = std::mem::MaybeUninit::uninit();
25
26 ffi::gdk_toplevel_size_get_bounds(
27 self.0.as_ptr(),
28 bounds_width.as_mut_ptr(),
29 bounds_height.as_mut_ptr(),
30 );
31 (bounds_width.assume_init(), bounds_height.assume_init())
32 }
33 }
34
35 #[doc(alias = "gdk_toplevel_size_set_min_size")]
36 pub fn set_min_size(&mut self, min_width: i32, min_height: i32) {
37 unsafe {
38 ffi::gdk_toplevel_size_set_min_size(self.0.as_mut(), min_width, min_height);
39 }
40 }
41
42 #[doc(alias = "gdk_toplevel_size_set_shadow_width")]
43 pub fn set_shadow_width(&mut self, left: i32, right: i32, top: i32, bottom: i32) {
44 unsafe {
45 ffi::gdk_toplevel_size_set_shadow_width(self.0.as_mut(), left, right, top, bottom);
46 }
47 }
48
49 #[doc(alias = "gdk_toplevel_size_set_size")]
50 pub fn set_size(&mut self, width: i32, height: i32) {
51 unsafe {
52 ffi::gdk_toplevel_size_set_size(self.0.as_mut(), width, height);
53 }
54 }
55}
56
57impl std::fmt::Debug for ToplevelSize {
58 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
59 f.debug_struct("ToplevelSize")
60 .field("bounds", &self.bounds())
61 .finish()
62 }
63}
64
65unsafe impl<'a> glib::value::FromValue<'a> for ToplevelSize {
66 type Checker = glib::value::GenericValueTypeChecker<Self>;
67
68 #[inline]
69 unsafe fn from_value(value: &'a glib::Value) -> Self {
70 unsafe {
71 let ptr = glib::gobject_ffi::g_value_get_pointer(value.to_glib_none().0);
72 debug_assert!(
73 !ptr.is_null(),
74 "ToplevelSize in glib::Value is a NULL pointer"
75 );
76 ToplevelSize(std::ptr::NonNull::new_unchecked(
77 ptr as *mut ffi::_GdkToplevelSize,
78 ))
79 }
80 }
81}
82
83impl ToValue for ToplevelSize {
84 #[inline]
85 fn to_value(&self) -> glib::Value {
86 unsafe {
87 let mut v = glib::Value::from_type(Self::static_type());
88 glib::gobject_ffi::g_value_set_pointer(
89 v.to_glib_none_mut().0,
90 self.0.as_ptr() as *mut c_void,
91 );
92 v
93 }
94 }
95
96 #[inline]
97 fn value_type(&self) -> glib::Type {
98 Self::static_type()
99 }
100}