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
49
50
51
52
53
54
55
// Take a look at the license at the top of the repository in the LICENSE file.

use crate::AxisFlags;
use glib::translate::*;
use std::fmt;

glib::wrapper! {
    /// A [`TimeCoord`][crate::TimeCoord] stores a single event in a motion history.
    ///
    /// To check whether an axis is present, check whether the corresponding
    /// flag from the [`AxisFlags`][crate::AxisFlags] enumeration is set in the @flags
    /// To access individual axis values, use the values of the values of
    /// the [`AxisUse`][crate::AxisUse] enumerations as indices.
    #[doc(alias = "GdkTimeCoord")]
    pub struct TimeCoord(BoxedInline<ffi::GdkTimeCoord>);
}

impl TimeCoord {
    #[inline]
    pub fn new(time: u32, axes: [f64; 12], flags: AxisFlags) -> Self {
        assert_initialized_main_thread!();
        unsafe {
            Self::unsafe_from(ffi::GdkTimeCoord {
                time,
                axes,
                flags: flags.into_glib(),
            })
        }
    }

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

    #[inline]
    pub fn axes(&self) -> &[f64; 12] {
        &self.inner.axes
    }

    #[inline]
    pub fn flags(&self) -> AxisFlags {
        unsafe { from_glib(self.inner.flags) }
    }
}

impl fmt::Debug for TimeCoord {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.debug_struct("TimeCoord")
            .field("time", &self.time())
            .field("axes", &self.axes())
            .field("flags", &self.flags())
            .finish()
    }
}