Skip to main content

gtk/auto/
check_button.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
5use crate::{
6    Actionable, Align, Bin, Buildable, Button, Container, PositionType, ReliefStyle, ResizeMode,
7    ToggleButton, Widget, ffi,
8};
9use glib::{prelude::*, translate::*};
10
11glib::wrapper! {
12    /// A [`CheckButton`][crate::CheckButton] places a discrete [`ToggleButton`][crate::ToggleButton] next to a widget,
13    /// (usually a [`Label`][crate::Label]). See the section on [`ToggleButton`][crate::ToggleButton] widgets for
14    /// more information about toggle/check buttons.
15    ///
16    /// The important signal ( [`toggled`][struct@crate::ToggleButton#toggled] ) is also inherited from
17    /// [`ToggleButton`][crate::ToggleButton].
18    ///
19    /// # CSS nodes
20    ///
21    ///
22    ///
23    /// **⚠️ The following code is in plain ⚠️**
24    ///
25    /// ```plain
26    /// checkbutton
27    /// ├── check
28    /// ╰── <child>
29    /// ```
30    ///
31    /// A GtkCheckButton with indicator (see [`ToggleButtonExt::set_mode()`][crate::prelude::ToggleButtonExt::set_mode()]) has a
32    /// main CSS node with name checkbutton and a subnode with name check.
33    ///
34    ///
35    ///
36    /// **⚠️ The following code is in plain ⚠️**
37    ///
38    /// ```plain
39    /// button.check
40    /// ├── check
41    /// ╰── <child>
42    /// ```
43    ///
44    /// A GtkCheckButton without indicator changes the name of its main node
45    /// to button and adds a .check style class to it. The subnode is invisible
46    /// in this case.
47    ///
48    /// # Implements
49    ///
50    /// [`ToggleButtonExt`][trait@crate::prelude::ToggleButtonExt], [`ButtonExt`][trait@crate::prelude::ButtonExt], [`BinExt`][trait@crate::prelude::BinExt], [`ContainerExt`][trait@crate::prelude::ContainerExt], [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ActionableExt`][trait@crate::prelude::ActionableExt], [`ContainerExtManual`][trait@crate::prelude::ContainerExtManual], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`BuildableExtManual`][trait@crate::prelude::BuildableExtManual]
51    #[doc(alias = "GtkCheckButton")]
52    pub struct CheckButton(Object<ffi::GtkCheckButton, ffi::GtkCheckButtonClass>) @extends ToggleButton, Button, Bin, Container, Widget, @implements Buildable, Actionable;
53
54    match fn {
55        type_ => || ffi::gtk_check_button_get_type(),
56    }
57}
58
59impl CheckButton {
60    pub const NONE: Option<&'static CheckButton> = None;
61
62    /// Creates a new [`CheckButton`][crate::CheckButton].
63    ///
64    /// # Returns
65    ///
66    /// a [`Widget`][crate::Widget].
67    #[doc(alias = "gtk_check_button_new")]
68    pub fn new() -> CheckButton {
69        assert_initialized_main_thread!();
70        unsafe { Widget::from_glib_none(ffi::gtk_check_button_new()).unsafe_cast() }
71    }
72
73    /// Creates a new [`CheckButton`][crate::CheckButton] with a [`Label`][crate::Label] to the right of it.
74    /// ## `label`
75    /// the text for the check button.
76    ///
77    /// # Returns
78    ///
79    /// a [`Widget`][crate::Widget].
80    #[doc(alias = "gtk_check_button_new_with_label")]
81    #[doc(alias = "new_with_label")]
82    pub fn with_label(label: &str) -> CheckButton {
83        assert_initialized_main_thread!();
84        unsafe {
85            Widget::from_glib_none(ffi::gtk_check_button_new_with_label(label.to_glib_none().0))
86                .unsafe_cast()
87        }
88    }
89
90    /// Creates a new [`CheckButton`][crate::CheckButton] containing a label. The label
91    /// will be created using [`Label::with_mnemonic()`][crate::Label::with_mnemonic()], so underscores
92    /// in `label` indicate the mnemonic for the check button.
93    /// ## `label`
94    /// The text of the button, with an underscore in front of the
95    ///  mnemonic character
96    ///
97    /// # Returns
98    ///
99    /// a new [`CheckButton`][crate::CheckButton]
100    #[doc(alias = "gtk_check_button_new_with_mnemonic")]
101    #[doc(alias = "new_with_mnemonic")]
102    pub fn with_mnemonic(label: &str) -> CheckButton {
103        assert_initialized_main_thread!();
104        unsafe {
105            Widget::from_glib_none(ffi::gtk_check_button_new_with_mnemonic(
106                label.to_glib_none().0,
107            ))
108            .unsafe_cast()
109        }
110    }
111
112    // rustdoc-stripper-ignore-next
113    /// Creates a new builder-pattern struct instance to construct [`CheckButton`] objects.
114    ///
115    /// This method returns an instance of [`CheckButtonBuilder`](crate::builders::CheckButtonBuilder) which can be used to create [`CheckButton`] objects.
116    pub fn builder() -> CheckButtonBuilder {
117        CheckButtonBuilder::new()
118    }
119}
120
121impl Default for CheckButton {
122    fn default() -> Self {
123        Self::new()
124    }
125}
126
127// rustdoc-stripper-ignore-next
128/// A [builder-pattern] type to construct [`CheckButton`] objects.
129///
130/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
131#[must_use = "The builder must be built to be used"]
132pub struct CheckButtonBuilder {
133    builder: glib::object::ObjectBuilder<'static, CheckButton>,
134}
135
136impl CheckButtonBuilder {
137    fn new() -> Self {
138        Self {
139            builder: glib::object::Object::builder(),
140        }
141    }
142
143    pub fn active(self, active: bool) -> Self {
144        Self {
145            builder: self.builder.property("active", active),
146        }
147    }
148
149    pub fn draw_indicator(self, draw_indicator: bool) -> Self {
150        Self {
151            builder: self.builder.property("draw-indicator", draw_indicator),
152        }
153    }
154
155    pub fn inconsistent(self, inconsistent: bool) -> Self {
156        Self {
157            builder: self.builder.property("inconsistent", inconsistent),
158        }
159    }
160
161    /// If [`true`], the button will ignore the [`gtk-button-images`][struct@crate::Settings#gtk-button-images]
162    /// setting and always show the image, if available.
163    ///
164    /// Use this property if the button would be useless or hard to use
165    /// without the image.
166    pub fn always_show_image(self, always_show_image: bool) -> Self {
167        Self {
168            builder: self
169                .builder
170                .property("always-show-image", always_show_image),
171        }
172    }
173
174    /// The child widget to appear next to the button text.
175    pub fn image(self, image: &impl IsA<Widget>) -> Self {
176        Self {
177            builder: self.builder.property("image", image.clone().upcast()),
178        }
179    }
180
181    /// The position of the image relative to the text inside the button.
182    pub fn image_position(self, image_position: PositionType) -> Self {
183        Self {
184            builder: self.builder.property("image-position", image_position),
185        }
186    }
187
188    pub fn label(self, label: impl Into<glib::GString>) -> Self {
189        Self {
190            builder: self.builder.property("label", label.into()),
191        }
192    }
193
194    pub fn relief(self, relief: ReliefStyle) -> Self {
195        Self {
196            builder: self.builder.property("relief", relief),
197        }
198    }
199
200    pub fn use_underline(self, use_underline: bool) -> Self {
201        Self {
202            builder: self.builder.property("use-underline", use_underline),
203        }
204    }
205
206    pub fn border_width(self, border_width: u32) -> Self {
207        Self {
208            builder: self.builder.property("border-width", border_width),
209        }
210    }
211
212    pub fn child(self, child: &impl IsA<Widget>) -> Self {
213        Self {
214            builder: self.builder.property("child", child.clone().upcast()),
215        }
216    }
217
218    pub fn resize_mode(self, resize_mode: ResizeMode) -> Self {
219        Self {
220            builder: self.builder.property("resize-mode", resize_mode),
221        }
222    }
223
224    pub fn app_paintable(self, app_paintable: bool) -> Self {
225        Self {
226            builder: self.builder.property("app-paintable", app_paintable),
227        }
228    }
229
230    pub fn can_default(self, can_default: bool) -> Self {
231        Self {
232            builder: self.builder.property("can-default", can_default),
233        }
234    }
235
236    pub fn can_focus(self, can_focus: bool) -> Self {
237        Self {
238            builder: self.builder.property("can-focus", can_focus),
239        }
240    }
241
242    pub fn events(self, events: gdk::EventMask) -> Self {
243        Self {
244            builder: self.builder.property("events", events),
245        }
246    }
247
248    /// Whether to expand in both directions. Setting this sets both [`hexpand`][struct@crate::Widget#hexpand] and [`vexpand`][struct@crate::Widget#vexpand]
249    pub fn expand(self, expand: bool) -> Self {
250        Self {
251            builder: self.builder.property("expand", expand),
252        }
253    }
254
255    /// Whether the widget should grab focus when it is clicked with the mouse.
256    ///
257    /// This property is only relevant for widgets that can take focus.
258    ///
259    /// Before 3.20, several widgets (GtkButton, GtkFileChooserButton,
260    /// GtkComboBox) implemented this property individually.
261    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
262        Self {
263            builder: self.builder.property("focus-on-click", focus_on_click),
264        }
265    }
266
267    /// How to distribute horizontal space if widget gets extra space, see [`Align`][crate::Align]
268    pub fn halign(self, halign: Align) -> Self {
269        Self {
270            builder: self.builder.property("halign", halign),
271        }
272    }
273
274    pub fn has_default(self, has_default: bool) -> Self {
275        Self {
276            builder: self.builder.property("has-default", has_default),
277        }
278    }
279
280    pub fn has_focus(self, has_focus: bool) -> Self {
281        Self {
282            builder: self.builder.property("has-focus", has_focus),
283        }
284    }
285
286    /// Enables or disables the emission of [`query-tooltip`][struct@crate::Widget#query-tooltip] on `widget`.
287    /// A value of [`true`] indicates that `widget` can have a tooltip, in this case
288    /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to determine
289    /// whether it will provide a tooltip or not.
290    ///
291    /// Note that setting this property to [`true`] for the first time will change
292    /// the event masks of the GdkWindows of this widget to include leave-notify
293    /// and motion-notify events. This cannot and will not be undone when the
294    /// property is set to [`false`] again.
295    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
296        Self {
297            builder: self.builder.property("has-tooltip", has_tooltip),
298        }
299    }
300
301    pub fn height_request(self, height_request: i32) -> Self {
302        Self {
303            builder: self.builder.property("height-request", height_request),
304        }
305    }
306
307    /// Whether to expand horizontally. See [`WidgetExt::set_hexpand()`][crate::prelude::WidgetExt::set_hexpand()].
308    pub fn hexpand(self, hexpand: bool) -> Self {
309        Self {
310            builder: self.builder.property("hexpand", hexpand),
311        }
312    }
313
314    /// Whether to use the [`hexpand`][struct@crate::Widget#hexpand] property. See [`WidgetExt::is_hexpand_set()`][crate::prelude::WidgetExt::is_hexpand_set()].
315    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
316        Self {
317            builder: self.builder.property("hexpand-set", hexpand_set),
318        }
319    }
320
321    pub fn is_focus(self, is_focus: bool) -> Self {
322        Self {
323            builder: self.builder.property("is-focus", is_focus),
324        }
325    }
326
327    /// Sets all four sides' margin at once. If read, returns max
328    /// margin on any side.
329    pub fn margin(self, margin: i32) -> Self {
330        Self {
331            builder: self.builder.property("margin", margin),
332        }
333    }
334
335    /// Margin on bottom side of widget.
336    ///
337    /// This property adds margin outside of the widget's normal size
338    /// request, the margin will be added in addition to the size from
339    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
340    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
341        Self {
342            builder: self.builder.property("margin-bottom", margin_bottom),
343        }
344    }
345
346    /// Margin on end of widget, horizontally. This property supports
347    /// left-to-right and right-to-left text directions.
348    ///
349    /// This property adds margin outside of the widget's normal size
350    /// request, the margin will be added in addition to the size from
351    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
352    pub fn margin_end(self, margin_end: i32) -> Self {
353        Self {
354            builder: self.builder.property("margin-end", margin_end),
355        }
356    }
357
358    /// Margin on start of widget, horizontally. This property supports
359    /// left-to-right and right-to-left text directions.
360    ///
361    /// This property adds margin outside of the widget's normal size
362    /// request, the margin will be added in addition to the size from
363    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
364    pub fn margin_start(self, margin_start: i32) -> Self {
365        Self {
366            builder: self.builder.property("margin-start", margin_start),
367        }
368    }
369
370    /// Margin on top side of widget.
371    ///
372    /// This property adds margin outside of the widget's normal size
373    /// request, the margin will be added in addition to the size from
374    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
375    pub fn margin_top(self, margin_top: i32) -> Self {
376        Self {
377            builder: self.builder.property("margin-top", margin_top),
378        }
379    }
380
381    pub fn name(self, name: impl Into<glib::GString>) -> Self {
382        Self {
383            builder: self.builder.property("name", name.into()),
384        }
385    }
386
387    pub fn no_show_all(self, no_show_all: bool) -> Self {
388        Self {
389            builder: self.builder.property("no-show-all", no_show_all),
390        }
391    }
392
393    /// The requested opacity of the widget. See [`WidgetExt::set_opacity()`][crate::prelude::WidgetExt::set_opacity()] for
394    /// more details about window opacity.
395    ///
396    /// Before 3.8 this was only available in GtkWindow
397    pub fn opacity(self, opacity: f64) -> Self {
398        Self {
399            builder: self.builder.property("opacity", opacity),
400        }
401    }
402
403    pub fn parent(self, parent: &impl IsA<Container>) -> Self {
404        Self {
405            builder: self.builder.property("parent", parent.clone().upcast()),
406        }
407    }
408
409    pub fn receives_default(self, receives_default: bool) -> Self {
410        Self {
411            builder: self.builder.property("receives-default", receives_default),
412        }
413    }
414
415    pub fn sensitive(self, sensitive: bool) -> Self {
416        Self {
417            builder: self.builder.property("sensitive", sensitive),
418        }
419    }
420
421    /// Sets the text of tooltip to be the given string, which is marked up
422    /// with the [Pango text markup language][PangoMarkupFormat].
423    /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
424    ///
425    /// This is a convenience property which will take care of getting the
426    /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
427    /// will automatically be set to [`true`] and there will be taken care of
428    /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
429    ///
430    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
431    /// are set, the last one wins.
432    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
433        Self {
434            builder: self
435                .builder
436                .property("tooltip-markup", tooltip_markup.into()),
437        }
438    }
439
440    /// Sets the text of tooltip to be the given string.
441    ///
442    /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
443    ///
444    /// This is a convenience property which will take care of getting the
445    /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
446    /// will automatically be set to [`true`] and there will be taken care of
447    /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
448    ///
449    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
450    /// are set, the last one wins.
451    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
452        Self {
453            builder: self.builder.property("tooltip-text", tooltip_text.into()),
454        }
455    }
456
457    /// How to distribute vertical space if widget gets extra space, see [`Align`][crate::Align]
458    pub fn valign(self, valign: Align) -> Self {
459        Self {
460            builder: self.builder.property("valign", valign),
461        }
462    }
463
464    /// Whether to expand vertically. See [`WidgetExt::set_vexpand()`][crate::prelude::WidgetExt::set_vexpand()].
465    pub fn vexpand(self, vexpand: bool) -> Self {
466        Self {
467            builder: self.builder.property("vexpand", vexpand),
468        }
469    }
470
471    /// Whether to use the [`vexpand`][struct@crate::Widget#vexpand] property. See [`WidgetExt::is_vexpand_set()`][crate::prelude::WidgetExt::is_vexpand_set()].
472    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
473        Self {
474            builder: self.builder.property("vexpand-set", vexpand_set),
475        }
476    }
477
478    pub fn visible(self, visible: bool) -> Self {
479        Self {
480            builder: self.builder.property("visible", visible),
481        }
482    }
483
484    pub fn width_request(self, width_request: i32) -> Self {
485        Self {
486            builder: self.builder.property("width-request", width_request),
487        }
488    }
489
490    pub fn action_name(self, action_name: impl Into<glib::GString>) -> Self {
491        Self {
492            builder: self.builder.property("action-name", action_name.into()),
493        }
494    }
495
496    pub fn action_target(self, action_target: &glib::Variant) -> Self {
497        Self {
498            builder: self
499                .builder
500                .property("action-target", action_target.clone()),
501        }
502    }
503
504    // rustdoc-stripper-ignore-next
505    /// Build the [`CheckButton`].
506    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
507    pub fn build(self) -> CheckButton {
508        assert_initialized_main_thread!();
509        self.builder.build()
510    }
511}