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    /// A [`TimeCoord`][crate::TimeCoord] stores a single event in a motion history.
11    ///
12    /// To check whether an axis is present, check whether the corresponding
13    /// flag from the [`AxisFlags`][crate::AxisFlags] enumeration is set in the @flags
14    /// To access individual axis values, use the values of the values of
15    /// the [`AxisUse`][crate::AxisUse] enumerations as indices.
16    #[doc(alias = "GdkTimeCoord")]
17    pub struct TimeCoord(BoxedInline<ffi::GdkTimeCoord>);
18}
19
20impl TimeCoord {
21    #[inline]
22    pub fn new(time: u32, axes: [f64; 12], flags: AxisFlags) -> Self {
23        assert_initialized_main_thread!();
24        unsafe {
25            Self::unsafe_from(ffi::GdkTimeCoord {
26                time,
27                axes,
28                flags: flags.into_glib(),
29            })
30        }
31    }
32
33    #[inline]
34    pub fn time(&self) -> u32 {
35        self.inner.time
36    }
37
38    #[inline]
39    pub fn axes(&self) -> &[f64; 12] {
40        &self.inner.axes
41    }
42
43    #[inline]
44    pub fn flags(&self) -> AxisFlags {
45        unsafe { from_glib(self.inner.flags) }
46    }
47}
48
49impl fmt::Debug for TimeCoord {
50    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
51        f.debug_struct("TimeCoord")
52            .field("time", &self.time())
53            .field("axes", &self.axes())
54            .field("flags", &self.flags())
55            .finish()
56    }
57}