Skip to main content

gdk/
geometry.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use crate::{Gravity, ffi};
4use glib::translate::*;
5use std::fmt;
6
7glib::wrapper! {
8    /// hints,
9    ///  GDK_HINT_RESIZE_INC |
10    ///  GDK_HINT_MIN_SIZE |
11    ///  GDK_HINT_BASE_SIZE);
12    /// ]|
13    ///
14    /// The other useful fields are the `min_aspect` and `max_aspect` fields; these
15    /// contain a width/height ratio as a floating point number. If a geometry widget
16    /// is set, the aspect applies to the geometry widget rather than the entire
17    /// window. The most common use of these hints is probably to set `min_aspect` and
18    /// `max_aspect` to the same value, thus forcing the window to keep a constant
19    /// aspect ratio.
20    #[doc(alias = "GdkGeometry")]
21    pub struct Geometry(BoxedInline<ffi::GdkGeometry>);
22}
23
24impl Geometry {
25    #[allow(clippy::too_many_arguments)]
26    pub fn new(
27        min_width: i32,
28        min_height: i32,
29        max_width: i32,
30        max_height: i32,
31        base_width: i32,
32        base_height: i32,
33        width_inc: i32,
34        height_inc: i32,
35        min_aspect: f64,
36        max_aspect: f64,
37        win_gravity: Gravity,
38    ) -> Self {
39        assert_initialized_main_thread!();
40        unsafe {
41            Geometry::unsafe_from(ffi::GdkGeometry {
42                min_width,
43                min_height,
44                max_width,
45                max_height,
46                base_width,
47                base_height,
48                width_inc,
49                height_inc,
50                min_aspect,
51                max_aspect,
52                win_gravity: win_gravity.into_glib(),
53            })
54        }
55    }
56
57    pub fn min_width(&self) -> i32 {
58        self.inner.min_width
59    }
60    pub fn min_height(&self) -> i32 {
61        self.inner.min_height
62    }
63    pub fn max_width(&self) -> i32 {
64        self.inner.max_width
65    }
66    pub fn max_height(&self) -> i32 {
67        self.inner.max_height
68    }
69    pub fn base_width(&self) -> i32 {
70        self.inner.base_width
71    }
72    pub fn base_height(&self) -> i32 {
73        self.inner.base_height
74    }
75    pub fn width_inc(&self) -> i32 {
76        self.inner.width_inc
77    }
78    pub fn height_inc(&self) -> i32 {
79        self.inner.height_inc
80    }
81    pub fn min_aspect(&self) -> f64 {
82        self.inner.min_aspect
83    }
84    pub fn max_aspect(&self) -> f64 {
85        self.inner.max_aspect
86    }
87    pub fn win_gravity(&self) -> Gravity {
88        unsafe { from_glib(self.inner.win_gravity) }
89    }
90}
91
92impl fmt::Debug for Geometry {
93    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
94        f.debug_struct("Geometry")
95            .field("min_width", &self.min_width())
96            .field("min_height", &self.min_height())
97            .field("max_width", &self.max_width())
98            .field("max_height", &self.max_height())
99            .field("base_width", &self.base_width())
100            .field("base_height", &self.base_height())
101            .field("width_inc", &self.width_inc())
102            .field("height_inc", &self.height_inc())
103            .field("min_aspect", &self.min_aspect())
104            .field("max_aspect", &self.max_aspect())
105            .field("win_gravity", &self.win_gravity())
106            .finish()
107    }
108}