gtk4/
css_location.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::fmt;
4
5use crate::ffi;
6use glib::translate::*;
7
8glib::wrapper! {
9    /// A description of a location inside a CSS stream.
10    #[doc(alias = "GtkCssLocation")]
11    pub struct CssLocation(BoxedInline<ffi::GtkCssLocation>);
12}
13
14impl CssLocation {
15    #[inline]
16    pub fn new(
17        bytes: usize,
18        chars: usize,
19        lines: usize,
20        line_bytes: usize,
21        line_chars: usize,
22    ) -> Self {
23        assert_initialized_main_thread!();
24        unsafe {
25            Self::unsafe_from(ffi::GtkCssLocation {
26                bytes,
27                chars,
28                lines,
29                line_bytes,
30                line_chars,
31            })
32        }
33    }
34
35    #[inline]
36    pub fn bytes(&self) -> usize {
37        self.inner.bytes
38    }
39
40    #[inline]
41    pub fn chars(&self) -> usize {
42        self.inner.chars
43    }
44
45    #[inline]
46    pub fn lines(&self) -> usize {
47        self.inner.lines
48    }
49
50    #[inline]
51    pub fn line_bytes(&self) -> usize {
52        self.inner.line_bytes
53    }
54
55    #[inline]
56    pub fn line_chars(&self) -> usize {
57        self.inner.line_chars
58    }
59}
60
61impl fmt::Debug for CssLocation {
62    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
63        f.debug_struct("CssLocation")
64            .field("bytes", &self.bytes())
65            .field("chars", &self.chars())
66            .field("lines", &self.lines())
67            .field("line_bytes", &self.line_bytes())
68            .field("line_chars", &self.line_chars())
69            .finish()
70    }
71}