graphene/
size.rs

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
// Take a look at the license at the top of the repository in the LICENSE file.

use std::fmt;

use glib::translate::*;

use crate::{ffi, Size};

impl Size {
    #[doc(alias = "graphene_size_init")]
    pub fn new(width: f32, height: f32) -> Self {
        assert_initialized_main_thread!();
        unsafe {
            let mut siz = Self::uninitialized();
            ffi::graphene_size_init(siz.to_glib_none_mut().0, width, height);
            siz
        }
    }

    #[inline]
    pub fn width(&self) -> f32 {
        self.inner.width
    }

    #[inline]
    pub fn set_width(&mut self, width: f32) {
        self.inner.width = width;
    }

    #[inline]
    pub fn height(&self) -> f32 {
        self.inner.height
    }

    #[inline]
    pub fn set_height(&mut self, height: f32) {
        self.inner.height = height;
    }
}

impl fmt::Debug for Size {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("Size")
            .field("width", &self.width())
            .field("height", &self.height())
            .finish()
    }
}