graphene/
size.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::fmt;
4
5use glib::translate::*;
6
7use crate::{ffi, Size};
8
9impl Size {
10    /// Initializes a [`Size`][crate::Size] using the given `width` and `height`.
11    /// ## `width`
12    /// the width
13    /// ## `height`
14    /// the height
15    ///
16    /// # Returns
17    ///
18    /// the initialized [`Size`][crate::Size]
19    #[doc(alias = "graphene_size_init")]
20    pub fn new(width: f32, height: f32) -> Self {
21        assert_initialized_main_thread!();
22        unsafe {
23            let mut siz = Self::uninitialized();
24            ffi::graphene_size_init(siz.to_glib_none_mut().0, width, height);
25            siz
26        }
27    }
28
29    #[inline]
30    pub fn width(&self) -> f32 {
31        self.inner.width
32    }
33
34    #[inline]
35    pub fn set_width(&mut self, width: f32) {
36        self.inner.width = width;
37    }
38
39    #[inline]
40    pub fn height(&self) -> f32 {
41        self.inner.height
42    }
43
44    #[inline]
45    pub fn set_height(&mut self, height: f32) {
46        self.inner.height = height;
47    }
48}
49
50impl fmt::Debug for Size {
51    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
52        f.debug_struct("Size")
53            .field("width", &self.width())
54            .field("height", &self.height())
55            .finish()
56    }
57}