Skip to main content

gtk/auto/
css_section.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{CssSectionType, ffi};
6use glib::translate::*;
7
8glib::wrapper! {
9    /// Defines a part of a CSS document. Because sections are nested into
10    /// one another, you can use [`parent()`][Self::parent()] to get the
11    /// containing region.
12    #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
13    pub struct CssSection(Shared<ffi::GtkCssSection>);
14
15    match fn {
16        ref => |ptr| ffi::gtk_css_section_ref(ptr),
17        unref => |ptr| ffi::gtk_css_section_unref(ptr),
18        type_ => || ffi::gtk_css_section_get_type(),
19    }
20}
21
22impl CssSection {
23    /// Returns the line in the CSS document where this section end.
24    /// The line number is 0-indexed, so the first line of the document
25    /// will return 0.
26    /// This value may change in future invocations of this function if
27    /// `self` is not yet parsed completely. This will for example
28    /// happen in the GtkCssProvider::parsing-error signal.
29    /// The end position and line may be identical to the start
30    /// position and line for sections which failed to parse anything
31    /// successfully.
32    ///
33    /// # Returns
34    ///
35    /// the line number
36    #[doc(alias = "gtk_css_section_get_end_line")]
37    #[doc(alias = "get_end_line")]
38    pub fn end_line(&self) -> u32 {
39        unsafe { ffi::gtk_css_section_get_end_line(self.to_glib_none().0) }
40    }
41
42    /// Returns the offset in bytes from the start of the current line
43    /// returned via [`end_line()`][Self::end_line()].
44    /// This value may change in future invocations of this function if
45    /// `self` is not yet parsed completely. This will for example
46    /// happen in the GtkCssProvider::parsing-error signal.
47    /// The end position and line may be identical to the start
48    /// position and line for sections which failed to parse anything
49    /// successfully.
50    ///
51    /// # Returns
52    ///
53    /// the offset in bytes from the start of the line.
54    #[doc(alias = "gtk_css_section_get_end_position")]
55    #[doc(alias = "get_end_position")]
56    pub fn end_position(&self) -> u32 {
57        unsafe { ffi::gtk_css_section_get_end_position(self.to_glib_none().0) }
58    }
59
60    /// Gets the file that `self` was parsed from. If no such file exists,
61    /// for example because the CSS was loaded via
62    /// [`CssProviderExt::load_from_data()`][crate::prelude::CssProviderExt::load_from_data()], then [`None`] is returned.
63    ///
64    /// # Returns
65    ///
66    /// the [`gio::File`][crate::gio::File] that `self` was parsed from
67    ///  or [`None`] if `self` was parsed from other data
68    #[doc(alias = "gtk_css_section_get_file")]
69    #[doc(alias = "get_file")]
70    pub fn file(&self) -> Option<gio::File> {
71        unsafe { from_glib_none(ffi::gtk_css_section_get_file(self.to_glib_none().0)) }
72    }
73
74    /// Gets the parent section for the given `self`. The parent section is
75    /// the section that contains this `self`. A special case are sections of
76    /// type [`CssSectionType::Document`][crate::CssSectionType::Document]. Their parent will either be [`None`]
77    /// if they are the original CSS document that was loaded by
78    /// [`CssProviderExt::load_from_file()`][crate::prelude::CssProviderExt::load_from_file()] or a section of type
79    /// [`CssSectionType::Import`][crate::CssSectionType::Import] if it was loaded with an import rule from
80    /// a different file.
81    ///
82    /// # Returns
83    ///
84    /// the parent section or [`None`] if none
85    #[doc(alias = "gtk_css_section_get_parent")]
86    #[doc(alias = "get_parent")]
87    #[must_use]
88    pub fn parent(&self) -> Option<CssSection> {
89        unsafe { from_glib_none(ffi::gtk_css_section_get_parent(self.to_glib_none().0)) }
90    }
91
92    /// Gets the type of information that `self` describes.
93    ///
94    /// # Returns
95    ///
96    /// the type of `self`
97    #[doc(alias = "gtk_css_section_get_section_type")]
98    #[doc(alias = "get_section_type")]
99    pub fn section_type(&self) -> CssSectionType {
100        unsafe { from_glib(ffi::gtk_css_section_get_section_type(self.to_glib_none().0)) }
101    }
102
103    /// Returns the line in the CSS document where this section starts.
104    /// The line number is 0-indexed, so the first line of the document
105    /// will return 0.
106    ///
107    /// # Returns
108    ///
109    /// the line number
110    #[doc(alias = "gtk_css_section_get_start_line")]
111    #[doc(alias = "get_start_line")]
112    pub fn start_line(&self) -> u32 {
113        unsafe { ffi::gtk_css_section_get_start_line(self.to_glib_none().0) }
114    }
115
116    /// Returns the offset in bytes from the start of the current line
117    /// returned via [`start_line()`][Self::start_line()].
118    ///
119    /// # Returns
120    ///
121    /// the offset in bytes from the start of the line.
122    #[doc(alias = "gtk_css_section_get_start_position")]
123    #[doc(alias = "get_start_position")]
124    pub fn start_position(&self) -> u32 {
125        unsafe { ffi::gtk_css_section_get_start_position(self.to_glib_none().0) }
126    }
127}