sourceview5/auto/
style_scheme.rs1use crate::{Style, ffi};
7use glib::{
8 prelude::*,
9 signal::{SignalHandlerId, connect_raw},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 #[doc(alias = "GtkSourceStyleScheme")]
16 pub struct StyleScheme(Object<ffi::GtkSourceStyleScheme, ffi::GtkSourceStyleSchemeClass>);
17
18 match fn {
19 type_ => || ffi::gtk_source_style_scheme_get_type(),
20 }
21}
22
23impl StyleScheme {
24 pub fn builder() -> StyleSchemeBuilder {
29 StyleSchemeBuilder::new()
30 }
31
32 #[doc(alias = "gtk_source_style_scheme_get_authors")]
33 #[doc(alias = "get_authors")]
34 pub fn authors(&self) -> Vec<glib::GString> {
35 unsafe {
36 FromGlibPtrContainer::from_glib_none(ffi::gtk_source_style_scheme_get_authors(
37 self.to_glib_none().0,
38 ))
39 }
40 }
41
42 #[doc(alias = "gtk_source_style_scheme_get_description")]
43 #[doc(alias = "get_description")]
44 pub fn description(&self) -> Option<glib::GString> {
45 unsafe {
46 from_glib_none(ffi::gtk_source_style_scheme_get_description(
47 self.to_glib_none().0,
48 ))
49 }
50 }
51
52 #[doc(alias = "gtk_source_style_scheme_get_filename")]
53 #[doc(alias = "get_filename")]
54 pub fn filename(&self) -> Option<glib::GString> {
55 unsafe {
56 from_glib_none(ffi::gtk_source_style_scheme_get_filename(
57 self.to_glib_none().0,
58 ))
59 }
60 }
61
62 #[doc(alias = "gtk_source_style_scheme_get_id")]
63 #[doc(alias = "get_id")]
64 pub fn id(&self) -> glib::GString {
65 unsafe { from_glib_none(ffi::gtk_source_style_scheme_get_id(self.to_glib_none().0)) }
66 }
67
68 #[cfg(feature = "v5_4")]
69 #[cfg_attr(docsrs, doc(cfg(feature = "v5_4")))]
70 #[doc(alias = "gtk_source_style_scheme_get_metadata")]
71 #[doc(alias = "get_metadata")]
72 pub fn metadata(&self, name: &str) -> Option<glib::GString> {
73 unsafe {
74 from_glib_none(ffi::gtk_source_style_scheme_get_metadata(
75 self.to_glib_none().0,
76 name.to_glib_none().0,
77 ))
78 }
79 }
80
81 #[doc(alias = "gtk_source_style_scheme_get_name")]
82 #[doc(alias = "get_name")]
83 pub fn name(&self) -> glib::GString {
84 unsafe { from_glib_none(ffi::gtk_source_style_scheme_get_name(self.to_glib_none().0)) }
85 }
86
87 #[doc(alias = "gtk_source_style_scheme_get_style")]
88 #[doc(alias = "get_style")]
89 pub fn style(&self, style_id: &str) -> Option<Style> {
90 unsafe {
91 from_glib_none(ffi::gtk_source_style_scheme_get_style(
92 self.to_glib_none().0,
93 style_id.to_glib_none().0,
94 ))
95 }
96 }
97
98 #[doc(alias = "description")]
99 pub fn connect_description_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
100 unsafe extern "C" fn notify_description_trampoline<F: Fn(&StyleScheme) + 'static>(
101 this: *mut ffi::GtkSourceStyleScheme,
102 _param_spec: glib::ffi::gpointer,
103 f: glib::ffi::gpointer,
104 ) {
105 unsafe {
106 let f: &F = &*(f as *const F);
107 f(&from_glib_borrow(this))
108 }
109 }
110 unsafe {
111 let f: Box_<F> = Box_::new(f);
112 connect_raw(
113 self.as_ptr() as *mut _,
114 c"notify::description".as_ptr(),
115 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
116 notify_description_trampoline::<F> as *const (),
117 )),
118 Box_::into_raw(f),
119 )
120 }
121 }
122
123 #[doc(alias = "filename")]
124 pub fn connect_filename_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
125 unsafe extern "C" fn notify_filename_trampoline<F: Fn(&StyleScheme) + 'static>(
126 this: *mut ffi::GtkSourceStyleScheme,
127 _param_spec: glib::ffi::gpointer,
128 f: glib::ffi::gpointer,
129 ) {
130 unsafe {
131 let f: &F = &*(f as *const F);
132 f(&from_glib_borrow(this))
133 }
134 }
135 unsafe {
136 let f: Box_<F> = Box_::new(f);
137 connect_raw(
138 self.as_ptr() as *mut _,
139 c"notify::filename".as_ptr(),
140 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
141 notify_filename_trampoline::<F> as *const (),
142 )),
143 Box_::into_raw(f),
144 )
145 }
146 }
147
148 #[doc(alias = "name")]
149 pub fn connect_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
150 unsafe extern "C" fn notify_name_trampoline<F: Fn(&StyleScheme) + 'static>(
151 this: *mut ffi::GtkSourceStyleScheme,
152 _param_spec: glib::ffi::gpointer,
153 f: glib::ffi::gpointer,
154 ) {
155 unsafe {
156 let f: &F = &*(f as *const F);
157 f(&from_glib_borrow(this))
158 }
159 }
160 unsafe {
161 let f: Box_<F> = Box_::new(f);
162 connect_raw(
163 self.as_ptr() as *mut _,
164 c"notify::name".as_ptr(),
165 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
166 notify_name_trampoline::<F> as *const (),
167 )),
168 Box_::into_raw(f),
169 )
170 }
171 }
172}
173
174impl std::fmt::Display for StyleScheme {
175 #[inline]
176 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
177 f.write_str(&self.name())
178 }
179}
180
181#[must_use = "The builder must be built to be used"]
186pub struct StyleSchemeBuilder {
187 builder: glib::object::ObjectBuilder<'static, StyleScheme>,
188}
189
190impl StyleSchemeBuilder {
191 fn new() -> Self {
192 Self {
193 builder: glib::object::Object::builder(),
194 }
195 }
196
197 pub fn id(self, id: impl Into<glib::GString>) -> Self {
198 Self {
199 builder: self.builder.property("id", id.into()),
200 }
201 }
202
203 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
206 pub fn build(self) -> StyleScheme {
207 assert_initialized_main_thread!();
208 self.builder.build()
209 }
210}