1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
// Take a look at the license at the top of the repository in the LICENSE file.
use glib::translate::*;
/// The [`ToplevelSize`][crate::ToplevelSize] struct contains information that is useful
/// to compute the size of a toplevel.
#[derive(Debug)]
#[repr(transparent)]
#[doc(alias = "GdkToplevelSize")]
pub struct ToplevelSize(ffi::GdkToplevelSize);
impl ToplevelSize {
/// Retrieves the bounds the toplevel is placed within.
///
/// The bounds represent the largest size a toplevel may have while still being
/// able to fit within some type of boundary. Depending on the backend, this may
/// be equivalent to the dimensions of the work area or the monitor on which the
/// window is being presented on, or something else that limits the way a
/// toplevel can be presented.
///
/// # Returns
///
///
/// ## `bounds_width`
/// return location for width
///
/// ## `bounds_height`
/// return location for height
#[doc(alias = "gdk_toplevel_size_get_bounds")]
#[doc(alias = "get_bounds")]
pub fn bounds(&self) -> (i32, i32) {
unsafe {
let bounds_width = std::ptr::null_mut();
let bounds_height = std::ptr::null_mut();
ffi::gdk_toplevel_size_get_bounds(
self.to_glib_none().0 as *mut _,
bounds_width,
bounds_height,
);
(bounds_width as i32, bounds_height as i32)
}
}
/// Sets the minimum size of the toplevel.
///
/// The minimum size corresponds to the limitations the toplevel can be shrunk
/// to, without resulting in incorrect painting. A user of a [`Toplevel`][crate::Toplevel] should
/// calculate these given both the existing size, and the bounds retrieved from
/// the [`ToplevelSize`][crate::ToplevelSize] object.
///
/// The minimum size should be within the bounds (see
/// [``bounds()``][`Self::bounds()`]).
/// ## `min_width`
/// the minimum width
/// ## `min_height`
/// the minimum height
#[doc(alias = "gdk_toplevel_size_set_min_size")]
pub fn set_min_size(&mut self, min_width: i32, min_height: i32) {
unsafe {
ffi::gdk_toplevel_size_set_min_size(self.to_glib_none_mut().0, min_width, min_height);
}
}
/// Sets the shadows size of the toplevel.
///
/// The shadow width corresponds to the part of the computed surface size
/// that would consist of the shadow margin surrounding the window, would
/// there be any.
/// ## `left`
/// width of the left part of the shadow
/// ## `right`
/// width of the right part of the shadow
/// ## `top`
/// height of the top part of the shadow
/// ## `bottom`
/// height of the bottom part of the shadow
#[doc(alias = "gdk_toplevel_size_set_shadow_width")]
pub fn set_shadow_width(&mut self, left: i32, right: i32, top: i32, bottom: i32) {
unsafe {
ffi::gdk_toplevel_size_set_shadow_width(
self.to_glib_none_mut().0,
left,
right,
top,
bottom,
);
}
}
/// Sets the size the toplevel prefers to be resized to.
///
/// The size should be within the bounds (see
/// [``bounds()``][`Self::bounds()`]). The set size should
/// be considered as a hint, and should not be assumed to be
/// respected by the windowing system, or backend.
/// ## `width`
/// the width
/// ## `height`
/// the height
#[doc(alias = "gdk_toplevel_size_set_size")]
pub fn set_size(&mut self, width: i32, height: i32) {
unsafe {
ffi::gdk_toplevel_size_set_size(self.to_glib_none_mut().0, width, height);
}
}
}
#[doc(hidden)]
impl<'a> ToGlibPtr<'a, *const ffi::GdkToplevelSize> for ToplevelSize {
type Storage = &'a Self;
#[inline]
fn to_glib_none(&'a self) -> Stash<'a, *const ffi::GdkToplevelSize, Self> {
let ptr: *const ToplevelSize = &*self;
Stash(ptr as *const ffi::GdkToplevelSize, self)
}
}
#[doc(hidden)]
impl<'a> ToGlibPtrMut<'a, *mut ffi::GdkToplevelSize> for ToplevelSize {
type Storage = &'a mut Self;
#[inline]
fn to_glib_none_mut(&'a mut self) -> StashMut<'a, *mut ffi::GdkToplevelSize, Self> {
let ptr: *mut ToplevelSize = &mut *self;
StashMut(ptr as *mut ffi::GdkToplevelSize, self)
}
}