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