sourceview5/auto/
style_scheme_preview.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from
3// from gir-files (https://github.com/gtk-rs/gir-files)
4// DO NOT EDIT
5
6use crate::{ffi, StyleScheme};
7use glib::{
8    object::ObjectType as _,
9    prelude::*,
10    signal::{connect_raw, SignalHandlerId},
11    translate::*,
12};
13use std::boxed::Box as Box_;
14
15glib::wrapper! {
16    #[doc(alias = "GtkSourceStyleSchemePreview")]
17    pub struct StyleSchemePreview(Object<ffi::GtkSourceStyleSchemePreview, ffi::GtkSourceStyleSchemePreviewClass>) @extends gtk::Widget, @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Actionable;
18
19    match fn {
20        type_ => || ffi::gtk_source_style_scheme_preview_get_type(),
21    }
22}
23
24impl StyleSchemePreview {
25    #[doc(alias = "gtk_source_style_scheme_preview_new")]
26    pub fn new(scheme: &StyleScheme) -> StyleSchemePreview {
27        skip_assert_initialized!();
28        unsafe {
29            gtk::Widget::from_glib_none(ffi::gtk_source_style_scheme_preview_new(
30                scheme.to_glib_none().0,
31            ))
32            .unsafe_cast()
33        }
34    }
35
36    // rustdoc-stripper-ignore-next
37    /// Creates a new builder-pattern struct instance to construct [`StyleSchemePreview`] objects.
38    ///
39    /// This method returns an instance of [`StyleSchemePreviewBuilder`](crate::builders::StyleSchemePreviewBuilder) which can be used to create [`StyleSchemePreview`] objects.
40    pub fn builder() -> StyleSchemePreviewBuilder {
41        StyleSchemePreviewBuilder::new()
42    }
43
44    #[doc(alias = "gtk_source_style_scheme_preview_get_scheme")]
45    #[doc(alias = "get_scheme")]
46    pub fn scheme(&self) -> StyleScheme {
47        unsafe {
48            from_glib_none(ffi::gtk_source_style_scheme_preview_get_scheme(
49                self.to_glib_none().0,
50            ))
51        }
52    }
53
54    #[doc(alias = "gtk_source_style_scheme_preview_get_selected")]
55    #[doc(alias = "get_selected")]
56    #[doc(alias = "selected")]
57    pub fn is_selected(&self) -> bool {
58        unsafe {
59            from_glib(ffi::gtk_source_style_scheme_preview_get_selected(
60                self.to_glib_none().0,
61            ))
62        }
63    }
64
65    #[doc(alias = "gtk_source_style_scheme_preview_set_selected")]
66    #[doc(alias = "selected")]
67    pub fn set_selected(&self, selected: bool) {
68        unsafe {
69            ffi::gtk_source_style_scheme_preview_set_selected(
70                self.to_glib_none().0,
71                selected.into_glib(),
72            );
73        }
74    }
75
76    #[cfg(not(feature = "v5_4"))]
77    #[cfg_attr(docsrs, doc(cfg(not(feature = "v5_4"))))]
78    pub fn scheme(&self) -> Option<StyleScheme> {
79        ObjectExt::property(self, "scheme")
80    }
81
82    #[cfg(not(feature = "v5_4"))]
83    #[cfg_attr(docsrs, doc(cfg(not(feature = "v5_4"))))]
84    pub fn is_selected(&self) -> bool {
85        ObjectExt::property(self, "selected")
86    }
87
88    #[cfg(not(feature = "v5_4"))]
89    #[cfg_attr(docsrs, doc(cfg(not(feature = "v5_4"))))]
90    pub fn set_selected(&self, selected: bool) {
91        ObjectExt::set_property(self, "selected", selected)
92    }
93
94    #[doc(alias = "activate")]
95    pub fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
96        unsafe extern "C" fn activate_trampoline<F: Fn(&StyleSchemePreview) + 'static>(
97            this: *mut ffi::GtkSourceStyleSchemePreview,
98            f: glib::ffi::gpointer,
99        ) {
100            unsafe {
101                let f: &F = &*(f as *const F);
102                f(&from_glib_borrow(this))
103            }
104        }
105        unsafe {
106            let f: Box_<F> = Box_::new(f);
107            connect_raw(
108                self.as_ptr() as *mut _,
109                c"activate".as_ptr() as *const _,
110                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
111                    activate_trampoline::<F> as *const (),
112                )),
113                Box_::into_raw(f),
114            )
115        }
116    }
117
118    #[doc(alias = "selected")]
119    pub fn connect_selected_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
120        unsafe extern "C" fn notify_selected_trampoline<F: Fn(&StyleSchemePreview) + 'static>(
121            this: *mut ffi::GtkSourceStyleSchemePreview,
122            _param_spec: glib::ffi::gpointer,
123            f: glib::ffi::gpointer,
124        ) {
125            unsafe {
126                let f: &F = &*(f as *const F);
127                f(&from_glib_borrow(this))
128            }
129        }
130        unsafe {
131            let f: Box_<F> = Box_::new(f);
132            connect_raw(
133                self.as_ptr() as *mut _,
134                c"notify::selected".as_ptr() as *const _,
135                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
136                    notify_selected_trampoline::<F> as *const (),
137                )),
138                Box_::into_raw(f),
139            )
140        }
141    }
142}
143
144#[cfg(feature = "v5_4")]
145#[cfg_attr(docsrs, doc(cfg(feature = "v5_4")))]
146impl Default for StyleSchemePreview {
147    fn default() -> Self {
148        glib::object::Object::new::<Self>()
149    }
150}
151
152// rustdoc-stripper-ignore-next
153/// A [builder-pattern] type to construct [`StyleSchemePreview`] objects.
154///
155/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
156#[must_use = "The builder must be built to be used"]
157pub struct StyleSchemePreviewBuilder {
158    builder: glib::object::ObjectBuilder<'static, StyleSchemePreview>,
159}
160
161impl StyleSchemePreviewBuilder {
162    fn new() -> Self {
163        Self {
164            builder: glib::object::Object::builder(),
165        }
166    }
167
168    pub fn scheme(self, scheme: &StyleScheme) -> Self {
169        Self {
170            builder: self.builder.property("scheme", scheme.clone()),
171        }
172    }
173
174    pub fn selected(self, selected: bool) -> Self {
175        Self {
176            builder: self.builder.property("selected", selected),
177        }
178    }
179
180    pub fn can_focus(self, can_focus: bool) -> Self {
181        Self {
182            builder: self.builder.property("can-focus", can_focus),
183        }
184    }
185
186    pub fn can_target(self, can_target: bool) -> Self {
187        Self {
188            builder: self.builder.property("can-target", can_target),
189        }
190    }
191
192    pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
193        Self {
194            builder: self.builder.property("css-classes", css_classes.into()),
195        }
196    }
197
198    pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
199        Self {
200            builder: self.builder.property("css-name", css_name.into()),
201        }
202    }
203
204    pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
205        Self {
206            builder: self.builder.property("cursor", cursor.clone()),
207        }
208    }
209
210    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
211        Self {
212            builder: self.builder.property("focus-on-click", focus_on_click),
213        }
214    }
215
216    pub fn focusable(self, focusable: bool) -> Self {
217        Self {
218            builder: self.builder.property("focusable", focusable),
219        }
220    }
221
222    pub fn halign(self, halign: gtk::Align) -> Self {
223        Self {
224            builder: self.builder.property("halign", halign),
225        }
226    }
227
228    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
229        Self {
230            builder: self.builder.property("has-tooltip", has_tooltip),
231        }
232    }
233
234    pub fn height_request(self, height_request: i32) -> Self {
235        Self {
236            builder: self.builder.property("height-request", height_request),
237        }
238    }
239
240    pub fn hexpand(self, hexpand: bool) -> Self {
241        Self {
242            builder: self.builder.property("hexpand", hexpand),
243        }
244    }
245
246    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
247        Self {
248            builder: self.builder.property("hexpand-set", hexpand_set),
249        }
250    }
251
252    pub fn layout_manager(self, layout_manager: &impl IsA<gtk::LayoutManager>) -> Self {
253        Self {
254            builder: self
255                .builder
256                .property("layout-manager", layout_manager.clone().upcast()),
257        }
258    }
259
260    #[cfg(feature = "gtk_v4_18")]
261    #[cfg_attr(docsrs, doc(cfg(feature = "gtk_v4_18")))]
262    pub fn limit_events(self, limit_events: bool) -> Self {
263        Self {
264            builder: self.builder.property("limit-events", limit_events),
265        }
266    }
267
268    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
269        Self {
270            builder: self.builder.property("margin-bottom", margin_bottom),
271        }
272    }
273
274    pub fn margin_end(self, margin_end: i32) -> Self {
275        Self {
276            builder: self.builder.property("margin-end", margin_end),
277        }
278    }
279
280    pub fn margin_start(self, margin_start: i32) -> Self {
281        Self {
282            builder: self.builder.property("margin-start", margin_start),
283        }
284    }
285
286    pub fn margin_top(self, margin_top: i32) -> Self {
287        Self {
288            builder: self.builder.property("margin-top", margin_top),
289        }
290    }
291
292    pub fn name(self, name: impl Into<glib::GString>) -> Self {
293        Self {
294            builder: self.builder.property("name", name.into()),
295        }
296    }
297
298    pub fn opacity(self, opacity: f64) -> Self {
299        Self {
300            builder: self.builder.property("opacity", opacity),
301        }
302    }
303
304    pub fn overflow(self, overflow: gtk::Overflow) -> Self {
305        Self {
306            builder: self.builder.property("overflow", overflow),
307        }
308    }
309
310    pub fn receives_default(self, receives_default: bool) -> Self {
311        Self {
312            builder: self.builder.property("receives-default", receives_default),
313        }
314    }
315
316    pub fn sensitive(self, sensitive: bool) -> Self {
317        Self {
318            builder: self.builder.property("sensitive", sensitive),
319        }
320    }
321
322    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
323        Self {
324            builder: self
325                .builder
326                .property("tooltip-markup", tooltip_markup.into()),
327        }
328    }
329
330    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
331        Self {
332            builder: self.builder.property("tooltip-text", tooltip_text.into()),
333        }
334    }
335
336    pub fn valign(self, valign: gtk::Align) -> Self {
337        Self {
338            builder: self.builder.property("valign", valign),
339        }
340    }
341
342    pub fn vexpand(self, vexpand: bool) -> Self {
343        Self {
344            builder: self.builder.property("vexpand", vexpand),
345        }
346    }
347
348    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
349        Self {
350            builder: self.builder.property("vexpand-set", vexpand_set),
351        }
352    }
353
354    pub fn visible(self, visible: bool) -> Self {
355        Self {
356            builder: self.builder.property("visible", visible),
357        }
358    }
359
360    pub fn width_request(self, width_request: i32) -> Self {
361        Self {
362            builder: self.builder.property("width-request", width_request),
363        }
364    }
365
366    pub fn accessible_role(self, accessible_role: gtk::AccessibleRole) -> Self {
367        Self {
368            builder: self.builder.property("accessible-role", accessible_role),
369        }
370    }
371
372    pub fn action_name(self, action_name: impl Into<glib::GString>) -> Self {
373        Self {
374            builder: self.builder.property("action-name", action_name.into()),
375        }
376    }
377
378    pub fn action_target(self, action_target: &glib::Variant) -> Self {
379        Self {
380            builder: self
381                .builder
382                .property("action-target", action_target.clone()),
383        }
384    }
385
386    // rustdoc-stripper-ignore-next
387    /// Build the [`StyleSchemePreview`].
388    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
389    pub fn build(self) -> StyleSchemePreview {
390        assert_initialized_main_thread!();
391        self.builder.build()
392    }
393}