gtk4/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::{ffi, CssLocation};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9    /// Defines a part of a CSS document.
10    ///
11    /// Because sections are nested into one another, you can use
12    /// [`parent()`][Self::parent()] to get the containing region.
13    #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
14    pub struct CssSection(Shared<ffi::GtkCssSection>);
15
16    match fn {
17        ref => |ptr| ffi::gtk_css_section_ref(ptr),
18        unref => |ptr| ffi::gtk_css_section_unref(ptr),
19        type_ => || ffi::gtk_css_section_get_type(),
20    }
21}
22
23impl CssSection {
24    /// Creates a new [`CssSection`][crate::CssSection] referring to the section
25    /// in the given `file` from the `start` location to the
26    /// `end` location.
27    /// ## `file`
28    /// The file this section refers to
29    /// ## `start`
30    /// The start location
31    /// ## `end`
32    /// The end location
33    ///
34    /// # Returns
35    ///
36    /// a new [`CssSection`][crate::CssSection]
37    #[doc(alias = "gtk_css_section_new")]
38    pub fn new(
39        file: Option<&impl IsA<gio::File>>,
40        start: &CssLocation,
41        end: &CssLocation,
42    ) -> CssSection {
43        assert_initialized_main_thread!();
44        unsafe {
45            from_glib_full(ffi::gtk_css_section_new(
46                file.map(|p| p.as_ref()).to_glib_none().0,
47                start.to_glib_none().0,
48                end.to_glib_none().0,
49            ))
50        }
51    }
52
53    /// Creates a new [`CssSection`][crate::CssSection] referring to the section
54    /// in the given `file` or the given `bytes` from the `start` location to the
55    /// `end` location.
56    /// ## `file`
57    /// The file this section refers to
58    /// ## `bytes`
59    /// The bytes this sections refers to
60    /// ## `start`
61    /// The start location
62    /// ## `end`
63    /// The end location
64    ///
65    /// # Returns
66    ///
67    /// a new [`CssSection`][crate::CssSection]
68    #[cfg(feature = "v4_16")]
69    #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
70    #[doc(alias = "gtk_css_section_new_with_bytes")]
71    #[doc(alias = "new_with_bytes")]
72    pub fn with_bytes(
73        file: Option<&impl IsA<gio::File>>,
74        bytes: Option<&glib::Bytes>,
75        start: &CssLocation,
76        end: &CssLocation,
77    ) -> CssSection {
78        assert_initialized_main_thread!();
79        unsafe {
80            from_glib_full(ffi::gtk_css_section_new_with_bytes(
81                file.map(|p| p.as_ref()).to_glib_none().0,
82                bytes.to_glib_none().0,
83                start.to_glib_none().0,
84                end.to_glib_none().0,
85            ))
86        }
87    }
88
89    /// Gets the bytes that @self was parsed from.
90    ///
91    /// # Returns
92    ///
93    /// the `GBytes` from which the `section`
94    ///   was parsed
95    #[cfg(feature = "v4_16")]
96    #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
97    #[doc(alias = "gtk_css_section_get_bytes")]
98    #[doc(alias = "get_bytes")]
99    pub fn bytes(&self) -> Option<glib::Bytes> {
100        unsafe { from_glib_none(ffi::gtk_css_section_get_bytes(self.to_glib_none().0)) }
101    }
102
103    /// Returns the location in the CSS document where this section ends.
104    ///
105    /// # Returns
106    ///
107    /// The end location of
108    ///   this section
109    #[doc(alias = "gtk_css_section_get_end_location")]
110    #[doc(alias = "get_end_location")]
111    pub fn end_location(&self) -> CssLocation {
112        unsafe { from_glib_none(ffi::gtk_css_section_get_end_location(self.to_glib_none().0)) }
113    }
114
115    /// Gets the file that @self was parsed from.
116    ///
117    /// If no such file exists, for example because the CSS was loaded via
118    /// [`CssProvider::load_from_data()`][crate::CssProvider::load_from_data()], then `NULL` is returned.
119    ///
120    /// # Returns
121    ///
122    /// the `GFile` from which the `section`
123    ///   was parsed
124    #[doc(alias = "gtk_css_section_get_file")]
125    #[doc(alias = "get_file")]
126    pub fn file(&self) -> Option<gio::File> {
127        unsafe { from_glib_none(ffi::gtk_css_section_get_file(self.to_glib_none().0)) }
128    }
129
130    /// Gets the parent section for the given `section`.
131    ///
132    /// The parent section is the section that contains this `section`. A special
133    /// case are sections of  type `GTK_CSS_SECTION_DOCUMENT`. Their parent will
134    /// either be `NULL` if they are the original CSS document that was loaded by
135    /// [`CssProvider::load_from_file()`][crate::CssProvider::load_from_file()] or a section of type
136    /// `GTK_CSS_SECTION_IMPORT` if it was loaded with an `@import` rule from
137    /// a different file.
138    ///
139    /// # Returns
140    ///
141    /// the parent section
142    #[doc(alias = "gtk_css_section_get_parent")]
143    #[doc(alias = "get_parent")]
144    #[must_use]
145    pub fn parent(&self) -> Option<CssSection> {
146        unsafe { from_glib_none(ffi::gtk_css_section_get_parent(self.to_glib_none().0)) }
147    }
148
149    /// Returns the location in the CSS document where this section starts.
150    ///
151    /// # Returns
152    ///
153    /// The start location of
154    ///   this section
155    #[doc(alias = "gtk_css_section_get_start_location")]
156    #[doc(alias = "get_start_location")]
157    pub fn start_location(&self) -> CssLocation {
158        unsafe {
159            from_glib_none(ffi::gtk_css_section_get_start_location(
160                self.to_glib_none().0,
161            ))
162        }
163    }
164
165    /// Prints the section into a human-readable text form using
166    /// `Gtk::CssSection::print()`.
167    ///
168    /// # Returns
169    ///
170    /// A new string.
171    #[doc(alias = "gtk_css_section_to_string")]
172    #[doc(alias = "to_string")]
173    pub fn to_str(&self) -> glib::GString {
174        unsafe { from_glib_full(ffi::gtk_css_section_to_string(self.to_glib_none().0)) }
175    }
176}
177
178impl std::fmt::Display for CssSection {
179    #[inline]
180    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
181        f.write_str(&self.to_str())
182    }
183}