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