[go: up one dir, main page]

gdk4/
time_coord.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, AxisFlags};
8
9glib::wrapper! {
10    #[doc(alias = "GdkTimeCoord")]
11    pub struct TimeCoord(BoxedInline<ffi::GdkTimeCoord>);
12}
13
14impl TimeCoord {
15    #[inline]
16    pub fn new(time: u32, axes: [f64; 12], flags: AxisFlags) -> Self {
17        assert_initialized_main_thread!();
18        unsafe {
19            Self::unsafe_from(ffi::GdkTimeCoord {
20                time,
21                axes,
22                flags: flags.into_glib(),
23            })
24        }
25    }
26
27    #[inline]
28    pub fn time(&self) -> u32 {
29        self.inner.time
30    }
31
32    #[inline]
33    pub fn axes(&self) -> &[f64; 12] {
34        &self.inner.axes
35    }
36
37    #[inline]
38    pub fn flags(&self) -> AxisFlags {
39        unsafe { from_glib(self.inner.flags) }
40    }
41}
42
43impl fmt::Debug for TimeCoord {
44    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
45        f.debug_struct("TimeCoord")
46            .field("time", &self.time())
47            .field("axes", &self.axes())
48            .field("flags", &self.flags())
49            .finish()
50    }
51}