gtk4/auto/
shortcut_label.rs

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