1use crate::{ffi, CssLocation};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9 #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
10 pub struct CssSection(Shared<ffi::GtkCssSection>);
11
12 match fn {
13 ref => |ptr| ffi::gtk_css_section_ref(ptr),
14 unref => |ptr| ffi::gtk_css_section_unref(ptr),
15 type_ => || ffi::gtk_css_section_get_type(),
16 }
17}
18
19impl CssSection {
20 #[doc(alias = "gtk_css_section_new")]
21 pub fn new(
22 file: Option<&impl IsA<gio::File>>,
23 start: &CssLocation,
24 end: &CssLocation,
25 ) -> CssSection {
26 assert_initialized_main_thread!();
27 unsafe {
28 from_glib_full(ffi::gtk_css_section_new(
29 file.map(|p| p.as_ref()).to_glib_none().0,
30 start.to_glib_none().0,
31 end.to_glib_none().0,
32 ))
33 }
34 }
35
36 #[cfg(feature = "v4_16")]
37 #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
38 #[doc(alias = "gtk_css_section_new_with_bytes")]
39 #[doc(alias = "new_with_bytes")]
40 pub fn with_bytes(
41 file: Option<&impl IsA<gio::File>>,
42 bytes: Option<&glib::Bytes>,
43 start: &CssLocation,
44 end: &CssLocation,
45 ) -> CssSection {
46 assert_initialized_main_thread!();
47 unsafe {
48 from_glib_full(ffi::gtk_css_section_new_with_bytes(
49 file.map(|p| p.as_ref()).to_glib_none().0,
50 bytes.to_glib_none().0,
51 start.to_glib_none().0,
52 end.to_glib_none().0,
53 ))
54 }
55 }
56
57 #[cfg(feature = "v4_16")]
58 #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
59 #[doc(alias = "gtk_css_section_get_bytes")]
60 #[doc(alias = "get_bytes")]
61 pub fn bytes(&self) -> Option<glib::Bytes> {
62 unsafe { from_glib_none(ffi::gtk_css_section_get_bytes(self.to_glib_none().0)) }
63 }
64
65 #[doc(alias = "gtk_css_section_get_end_location")]
66 #[doc(alias = "get_end_location")]
67 pub fn end_location(&self) -> CssLocation {
68 unsafe { from_glib_none(ffi::gtk_css_section_get_end_location(self.to_glib_none().0)) }
69 }
70
71 #[doc(alias = "gtk_css_section_get_file")]
72 #[doc(alias = "get_file")]
73 pub fn file(&self) -> Option<gio::File> {
74 unsafe { from_glib_none(ffi::gtk_css_section_get_file(self.to_glib_none().0)) }
75 }
76
77 #[doc(alias = "gtk_css_section_get_parent")]
78 #[doc(alias = "get_parent")]
79 #[must_use]
80 pub fn parent(&self) -> Option<CssSection> {
81 unsafe { from_glib_none(ffi::gtk_css_section_get_parent(self.to_glib_none().0)) }
82 }
83
84 #[doc(alias = "gtk_css_section_get_start_location")]
85 #[doc(alias = "get_start_location")]
86 pub fn start_location(&self) -> CssLocation {
87 unsafe {
88 from_glib_none(ffi::gtk_css_section_get_start_location(
89 self.to_glib_none().0,
90 ))
91 }
92 }
93
94 #[doc(alias = "gtk_css_section_to_string")]
95 #[doc(alias = "to_string")]
96 pub fn to_str(&self) -> glib::GString {
97 unsafe { from_glib_full(ffi::gtk_css_section_to_string(self.to_glib_none().0)) }
98 }
99}
100
101impl std::fmt::Display for CssSection {
102 #[inline]
103 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
104 f.write_str(&self.to_str())
105 }
106}