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 #[doc(alias = "graphene_size_init")]
11 pub fn new(width: f32, height: f32) -> Self {
12 assert_initialized_main_thread!();
13 unsafe {
14 let mut siz = Self::uninitialized();
15 ffi::graphene_size_init(siz.to_glib_none_mut().0, width, height);
16 siz
17 }
18 }
19
20 #[inline]
21 pub fn width(&self) -> f32 {
22 self.inner.width
23 }
24
25 #[inline]
26 pub fn set_width(&mut self, width: f32) {
27 self.inner.width = width;
28 }
29
30 #[inline]
31 pub fn height(&self) -> f32 {
32 self.inner.height
33 }
34
35 #[inline]
36 pub fn set_height(&mut self, height: f32) {
37 self.inner.height = height;
38 }
39}
40
41impl fmt::Debug for Size {
42 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
43 f.debug_struct("Size")
44 .field("width", &self.width())
45 .field("height", &self.height())
46 .finish()
47 }
48}