gtk/
stack_switcher.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use crate::Align;
4use crate::BaselinePosition;
5use crate::Container;
6use crate::IconSize;
7use crate::Orientation;
8use crate::ResizeMode;
9use crate::Stack;
10use crate::StackSwitcher;
11use crate::Widget;
12use glib::object::IsA;
13use glib::object::ObjectExt;
14use glib::signal::{connect_raw, SignalHandlerId};
15use glib::translate::*;
16use glib::Cast;
17use std::boxed::Box as Box_;
18use std::mem::transmute;
19
20mod sealed {
21    pub trait Sealed {}
22    impl<T: glib::IsA<crate::StackSwitcher>> Sealed for T {}
23}
24
25pub trait StackSwitcherExtManual: IsA<StackSwitcher> + sealed::Sealed + 'static {
26    #[doc(alias = "icon-size")]
27    fn icon_size(&self) -> IconSize {
28        unsafe { from_glib(self.as_ref().property::<i32>("icon-size")) }
29    }
30
31    #[doc(alias = "icon-size")]
32    fn set_icon_size(&self, icon_size: IconSize) {
33        self.as_ref()
34            .set_property("icon-size", icon_size.into_glib());
35    }
36
37    #[doc(alias = "icon-size")]
38    fn connect_icon_size_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
39        unsafe extern "C" fn notify_icon_size_trampoline<
40            P: IsA<StackSwitcher>,
41            F: Fn(&P) + 'static,
42        >(
43            this: *mut ffi::GtkStackSwitcher,
44            _param_spec: glib::ffi::gpointer,
45            f: glib::ffi::gpointer,
46        ) {
47            let f: &F = &*(f as *const F);
48            f(StackSwitcher::from_glib_borrow(this).unsafe_cast_ref())
49        }
50        unsafe {
51            let f: Box_<F> = Box_::new(f);
52            connect_raw(
53                self.as_ptr() as *mut _,
54                b"notify::icon-size\0".as_ptr() as *const _,
55                Some(transmute::<_, unsafe extern "C" fn()>(
56                    notify_icon_size_trampoline::<Self, F> as *const (),
57                )),
58                Box_::into_raw(f),
59            )
60        }
61    }
62}
63
64impl<O: IsA<StackSwitcher>> StackSwitcherExtManual for O {}
65
66impl StackSwitcher {
67    // rustdoc-stripper-ignore-next
68    /// Creates a new builder-style object to construct a [`StackSwitcher`].
69    ///
70    /// This method returns an instance of [`StackSwitcherBuilder`] which can be used to create a [`StackSwitcher`].
71    pub fn builder() -> StackSwitcherBuilder {
72        StackSwitcherBuilder::new()
73    }
74}
75
76// rustdoc-stripper-ignore-next
77/// A builder for generating a [`StackSwitcher`].
78#[must_use = "The builder must be built to be used"]
79pub struct StackSwitcherBuilder {
80    builder: glib::object::ObjectBuilder<'static, StackSwitcher>,
81}
82
83impl StackSwitcherBuilder {
84    // rustdoc-stripper-ignore-next
85    /// Create a new [`StackSwitcherBuilder`].
86    pub fn new() -> Self {
87        Self {
88            builder: glib::object::Object::builder(),
89        }
90    }
91
92    pub fn icon_size(self, icon_size: IconSize) -> Self {
93        Self {
94            builder: self.builder.property("icon-size", icon_size),
95        }
96    }
97
98    pub fn stack<P: IsA<Stack>>(self, stack: &P) -> Self {
99        Self {
100            builder: self.builder.property("stack", stack),
101        }
102    }
103
104    pub fn baseline_position(self, baseline_position: BaselinePosition) -> Self {
105        Self {
106            builder: self
107                .builder
108                .property("baseline-position", baseline_position),
109        }
110    }
111
112    pub fn homogeneous(self, homogeneous: bool) -> Self {
113        Self {
114            builder: self.builder.property("homogeneous", homogeneous),
115        }
116    }
117
118    pub fn spacing(self, spacing: i32) -> Self {
119        Self {
120            builder: self.builder.property("spacing", spacing),
121        }
122    }
123
124    pub fn border_width(self, border_width: u32) -> Self {
125        Self {
126            builder: self.builder.property("border-width", border_width),
127        }
128    }
129
130    pub fn child<P: IsA<Widget>>(self, child: &P) -> Self {
131        Self {
132            builder: self.builder.property("child", child),
133        }
134    }
135
136    pub fn resize_mode(self, resize_mode: ResizeMode) -> Self {
137        Self {
138            builder: self.builder.property("resize-mode", resize_mode),
139        }
140    }
141
142    pub fn app_paintable(self, app_paintable: bool) -> Self {
143        Self {
144            builder: self.builder.property("app-paintable", app_paintable),
145        }
146    }
147
148    pub fn can_default(self, can_default: bool) -> Self {
149        Self {
150            builder: self.builder.property("can-default", can_default),
151        }
152    }
153
154    pub fn can_focus(self, can_focus: bool) -> Self {
155        Self {
156            builder: self.builder.property("can-focus", can_focus),
157        }
158    }
159
160    pub fn events(self, events: gdk::EventMask) -> Self {
161        Self {
162            builder: self.builder.property("events", events),
163        }
164    }
165
166    pub fn expand(self, expand: bool) -> Self {
167        Self {
168            builder: self.builder.property("expand", expand),
169        }
170    }
171
172    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
173        Self {
174            builder: self.builder.property("focus-on-click", focus_on_click),
175        }
176    }
177
178    pub fn halign(self, halign: Align) -> Self {
179        Self {
180            builder: self.builder.property("halign", halign),
181        }
182    }
183
184    pub fn has_default(self, has_default: bool) -> Self {
185        Self {
186            builder: self.builder.property("has-default", has_default),
187        }
188    }
189
190    pub fn has_focus(self, has_focus: bool) -> Self {
191        Self {
192            builder: self.builder.property("has-focus", has_focus),
193        }
194    }
195
196    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
197        Self {
198            builder: self.builder.property("has-tooltip", has_tooltip),
199        }
200    }
201
202    pub fn height_request(self, height_request: i32) -> Self {
203        Self {
204            builder: self.builder.property("height-request", height_request),
205        }
206    }
207
208    pub fn hexpand(self, hexpand: bool) -> Self {
209        Self {
210            builder: self.builder.property("hexpand", hexpand),
211        }
212    }
213
214    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
215        Self {
216            builder: self.builder.property("hexpand-set", hexpand_set),
217        }
218    }
219
220    #[allow(clippy::wrong_self_convention)]
221    pub fn is_focus(self, is_focus: bool) -> Self {
222        Self {
223            builder: self.builder.property("is-focus", is_focus),
224        }
225    }
226
227    pub fn margin(self, margin: i32) -> Self {
228        Self {
229            builder: self.builder.property("margin", margin),
230        }
231    }
232
233    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
234        Self {
235            builder: self.builder.property("margin-bottom", margin_bottom),
236        }
237    }
238
239    pub fn margin_end(self, margin_end: i32) -> Self {
240        Self {
241            builder: self.builder.property("margin-end", margin_end),
242        }
243    }
244
245    pub fn margin_start(self, margin_start: i32) -> Self {
246        Self {
247            builder: self.builder.property("margin-start", margin_start),
248        }
249    }
250
251    pub fn margin_top(self, margin_top: i32) -> Self {
252        Self {
253            builder: self.builder.property("margin-top", margin_top),
254        }
255    }
256
257    pub fn name(self, name: &str) -> Self {
258        Self {
259            builder: self.builder.property("name", name),
260        }
261    }
262
263    pub fn no_show_all(self, no_show_all: bool) -> Self {
264        Self {
265            builder: self.builder.property("no-show-all", no_show_all),
266        }
267    }
268
269    pub fn opacity(self, opacity: f64) -> Self {
270        Self {
271            builder: self.builder.property("opacity", opacity),
272        }
273    }
274
275    pub fn parent<P: IsA<Container>>(self, parent: &P) -> Self {
276        Self {
277            builder: self.builder.property("parent", parent),
278        }
279    }
280
281    pub fn receives_default(self, receives_default: bool) -> Self {
282        Self {
283            builder: self.builder.property("receives-default", receives_default),
284        }
285    }
286
287    pub fn sensitive(self, sensitive: bool) -> Self {
288        Self {
289            builder: self.builder.property("sensitive", sensitive),
290        }
291    }
292
293    pub fn tooltip_markup(self, tooltip_markup: &str) -> Self {
294        Self {
295            builder: self.builder.property("tooltip-markup", tooltip_markup),
296        }
297    }
298
299    pub fn tooltip_text(self, tooltip_text: &str) -> Self {
300        Self {
301            builder: self.builder.property("tooltip-text", tooltip_text),
302        }
303    }
304
305    pub fn valign(self, valign: Align) -> Self {
306        Self {
307            builder: self.builder.property("valign", valign),
308        }
309    }
310
311    pub fn vexpand(self, vexpand: bool) -> Self {
312        Self {
313            builder: self.builder.property("vexpand", vexpand),
314        }
315    }
316
317    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
318        Self {
319            builder: self.builder.property("vexpand*set", vexpand_set),
320        }
321    }
322
323    pub fn visible(self, visible: bool) -> Self {
324        Self {
325            builder: self.builder.property("visible", visible),
326        }
327    }
328
329    pub fn width_request(self, width_request: i32) -> Self {
330        Self {
331            builder: self.builder.property("width-request", width_request),
332        }
333    }
334
335    pub fn orientation(self, orientation: Orientation) -> Self {
336        Self {
337            builder: self.builder.property("orientation", orientation),
338        }
339    }
340
341    // rustdoc-stripper-ignore-next
342    /// Build the [`StackSwitcher`].
343    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
344    pub fn build(self) -> StackSwitcher {
345        self.builder.build()
346    }
347}