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