Skip to main content

gtk/
stack_switcher.rs

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