gtk/auto/
radio_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 gdk;
6use glib::object::Cast;
7use glib::object::IsA;
8use glib::signal::connect_raw;
9use glib::signal::SignalHandlerId;
10use glib::translate::*;
11use glib::StaticType;
12use glib::ToValue;
13use glib_sys;
14use gtk_sys;
15use std::boxed::Box as Box_;
16use std::fmt;
17use std::mem::transmute;
18use Actionable;
19use Align;
20use Bin;
21use Buildable;
22use Button;
23use CheckButton;
24use Container;
25use PositionType;
26use ReliefStyle;
27use ResizeMode;
28use ToggleButton;
29use Widget;
30
31glib_wrapper! {
32    pub struct RadioButton(Object<gtk_sys::GtkRadioButton, gtk_sys::GtkRadioButtonClass, RadioButtonClass>) @extends CheckButton, ToggleButton, Button, Bin, Container, Widget, @implements Buildable, Actionable;
33
34    match fn {
35        get_type => || gtk_sys::gtk_radio_button_get_type(),
36    }
37}
38
39impl RadioButton {
40    pub fn new_from_widget<P: IsA<RadioButton>>(radio_group_member: &P) -> RadioButton {
41        skip_assert_initialized!();
42        unsafe {
43            Widget::from_glib_none(gtk_sys::gtk_radio_button_new_from_widget(
44                radio_group_member.as_ref().to_glib_none().0,
45            ))
46            .unsafe_cast()
47        }
48    }
49
50    pub fn new_with_label_from_widget<P: IsA<RadioButton>>(
51        radio_group_member: &P,
52        label: &str,
53    ) -> RadioButton {
54        skip_assert_initialized!();
55        unsafe {
56            Widget::from_glib_none(gtk_sys::gtk_radio_button_new_with_label_from_widget(
57                radio_group_member.as_ref().to_glib_none().0,
58                label.to_glib_none().0,
59            ))
60            .unsafe_cast()
61        }
62    }
63
64    pub fn new_with_mnemonic_from_widget<P: IsA<RadioButton>>(
65        radio_group_member: &P,
66        label: &str,
67    ) -> RadioButton {
68        skip_assert_initialized!();
69        unsafe {
70            Widget::from_glib_none(gtk_sys::gtk_radio_button_new_with_mnemonic_from_widget(
71                radio_group_member.as_ref().to_glib_none().0,
72                label.to_glib_none().0,
73            ))
74            .unsafe_cast()
75        }
76    }
77}
78
79pub struct RadioButtonBuilder {
80    active: Option<bool>,
81    draw_indicator: Option<bool>,
82    inconsistent: Option<bool>,
83    always_show_image: Option<bool>,
84    image: Option<Widget>,
85    image_position: Option<PositionType>,
86    label: Option<String>,
87    relief: Option<ReliefStyle>,
88    use_underline: Option<bool>,
89    border_width: Option<u32>,
90    child: Option<Widget>,
91    resize_mode: Option<ResizeMode>,
92    app_paintable: Option<bool>,
93    can_default: Option<bool>,
94    can_focus: Option<bool>,
95    events: Option<gdk::EventMask>,
96    expand: Option<bool>,
97    #[cfg(any(feature = "v3_20", feature = "dox"))]
98    focus_on_click: Option<bool>,
99    halign: Option<Align>,
100    has_default: Option<bool>,
101    has_focus: Option<bool>,
102    has_tooltip: Option<bool>,
103    height_request: Option<i32>,
104    hexpand: Option<bool>,
105    hexpand_set: Option<bool>,
106    is_focus: Option<bool>,
107    margin: Option<i32>,
108    margin_bottom: Option<i32>,
109    margin_end: Option<i32>,
110    margin_start: Option<i32>,
111    margin_top: Option<i32>,
112    name: Option<String>,
113    no_show_all: Option<bool>,
114    opacity: Option<f64>,
115    parent: Option<Container>,
116    receives_default: Option<bool>,
117    sensitive: Option<bool>,
118    //style: /*Unknown type*/,
119    tooltip_markup: Option<String>,
120    tooltip_text: Option<String>,
121    valign: Option<Align>,
122    vexpand: Option<bool>,
123    vexpand_set: Option<bool>,
124    visible: Option<bool>,
125    width_request: Option<i32>,
126}
127
128impl RadioButtonBuilder {
129    pub fn new() -> Self {
130        Self {
131            active: None,
132            draw_indicator: None,
133            inconsistent: None,
134            always_show_image: None,
135            image: None,
136            image_position: None,
137            label: None,
138            relief: None,
139            use_underline: None,
140            border_width: None,
141            child: None,
142            resize_mode: None,
143            app_paintable: None,
144            can_default: None,
145            can_focus: None,
146            events: None,
147            expand: None,
148            #[cfg(any(feature = "v3_20", feature = "dox"))]
149            focus_on_click: None,
150            halign: None,
151            has_default: None,
152            has_focus: None,
153            has_tooltip: None,
154            height_request: None,
155            hexpand: None,
156            hexpand_set: None,
157            is_focus: None,
158            margin: None,
159            margin_bottom: None,
160            margin_end: None,
161            margin_start: None,
162            margin_top: None,
163            name: None,
164            no_show_all: None,
165            opacity: None,
166            parent: None,
167            receives_default: None,
168            sensitive: None,
169            tooltip_markup: None,
170            tooltip_text: None,
171            valign: None,
172            vexpand: None,
173            vexpand_set: None,
174            visible: None,
175            width_request: None,
176        }
177    }
178
179    pub fn build(self) -> RadioButton {
180        let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
181        if let Some(ref active) = self.active {
182            properties.push(("active", active));
183        }
184        if let Some(ref draw_indicator) = self.draw_indicator {
185            properties.push(("draw-indicator", draw_indicator));
186        }
187        if let Some(ref inconsistent) = self.inconsistent {
188            properties.push(("inconsistent", inconsistent));
189        }
190        if let Some(ref always_show_image) = self.always_show_image {
191            properties.push(("always-show-image", always_show_image));
192        }
193        if let Some(ref image) = self.image {
194            properties.push(("image", image));
195        }
196        if let Some(ref image_position) = self.image_position {
197            properties.push(("image-position", image_position));
198        }
199        if let Some(ref label) = self.label {
200            properties.push(("label", label));
201        }
202        if let Some(ref relief) = self.relief {
203            properties.push(("relief", relief));
204        }
205        if let Some(ref use_underline) = self.use_underline {
206            properties.push(("use-underline", use_underline));
207        }
208        if let Some(ref border_width) = self.border_width {
209            properties.push(("border-width", border_width));
210        }
211        if let Some(ref child) = self.child {
212            properties.push(("child", child));
213        }
214        if let Some(ref resize_mode) = self.resize_mode {
215            properties.push(("resize-mode", resize_mode));
216        }
217        if let Some(ref app_paintable) = self.app_paintable {
218            properties.push(("app-paintable", app_paintable));
219        }
220        if let Some(ref can_default) = self.can_default {
221            properties.push(("can-default", can_default));
222        }
223        if let Some(ref can_focus) = self.can_focus {
224            properties.push(("can-focus", can_focus));
225        }
226        if let Some(ref events) = self.events {
227            properties.push(("events", events));
228        }
229        if let Some(ref expand) = self.expand {
230            properties.push(("expand", expand));
231        }
232        #[cfg(any(feature = "v3_20", feature = "dox"))]
233        {
234            if let Some(ref focus_on_click) = self.focus_on_click {
235                properties.push(("focus-on-click", focus_on_click));
236            }
237        }
238        if let Some(ref halign) = self.halign {
239            properties.push(("halign", halign));
240        }
241        if let Some(ref has_default) = self.has_default {
242            properties.push(("has-default", has_default));
243        }
244        if let Some(ref has_focus) = self.has_focus {
245            properties.push(("has-focus", has_focus));
246        }
247        if let Some(ref has_tooltip) = self.has_tooltip {
248            properties.push(("has-tooltip", has_tooltip));
249        }
250        if let Some(ref height_request) = self.height_request {
251            properties.push(("height-request", height_request));
252        }
253        if let Some(ref hexpand) = self.hexpand {
254            properties.push(("hexpand", hexpand));
255        }
256        if let Some(ref hexpand_set) = self.hexpand_set {
257            properties.push(("hexpand-set", hexpand_set));
258        }
259        if let Some(ref is_focus) = self.is_focus {
260            properties.push(("is-focus", is_focus));
261        }
262        if let Some(ref margin) = self.margin {
263            properties.push(("margin", margin));
264        }
265        if let Some(ref margin_bottom) = self.margin_bottom {
266            properties.push(("margin-bottom", margin_bottom));
267        }
268        if let Some(ref margin_end) = self.margin_end {
269            properties.push(("margin-end", margin_end));
270        }
271        if let Some(ref margin_start) = self.margin_start {
272            properties.push(("margin-start", margin_start));
273        }
274        if let Some(ref margin_top) = self.margin_top {
275            properties.push(("margin-top", margin_top));
276        }
277        if let Some(ref name) = self.name {
278            properties.push(("name", name));
279        }
280        if let Some(ref no_show_all) = self.no_show_all {
281            properties.push(("no-show-all", no_show_all));
282        }
283        if let Some(ref opacity) = self.opacity {
284            properties.push(("opacity", opacity));
285        }
286        if let Some(ref parent) = self.parent {
287            properties.push(("parent", parent));
288        }
289        if let Some(ref receives_default) = self.receives_default {
290            properties.push(("receives-default", receives_default));
291        }
292        if let Some(ref sensitive) = self.sensitive {
293            properties.push(("sensitive", sensitive));
294        }
295        if let Some(ref tooltip_markup) = self.tooltip_markup {
296            properties.push(("tooltip-markup", tooltip_markup));
297        }
298        if let Some(ref tooltip_text) = self.tooltip_text {
299            properties.push(("tooltip-text", tooltip_text));
300        }
301        if let Some(ref valign) = self.valign {
302            properties.push(("valign", valign));
303        }
304        if let Some(ref vexpand) = self.vexpand {
305            properties.push(("vexpand", vexpand));
306        }
307        if let Some(ref vexpand_set) = self.vexpand_set {
308            properties.push(("vexpand-set", vexpand_set));
309        }
310        if let Some(ref visible) = self.visible {
311            properties.push(("visible", visible));
312        }
313        if let Some(ref width_request) = self.width_request {
314            properties.push(("width-request", width_request));
315        }
316        glib::Object::new(RadioButton::static_type(), &properties)
317            .expect("object new")
318            .downcast()
319            .expect("downcast")
320    }
321
322    pub fn active(mut self, active: bool) -> Self {
323        self.active = Some(active);
324        self
325    }
326
327    pub fn draw_indicator(mut self, draw_indicator: bool) -> Self {
328        self.draw_indicator = Some(draw_indicator);
329        self
330    }
331
332    pub fn inconsistent(mut self, inconsistent: bool) -> Self {
333        self.inconsistent = Some(inconsistent);
334        self
335    }
336
337    pub fn always_show_image(mut self, always_show_image: bool) -> Self {
338        self.always_show_image = Some(always_show_image);
339        self
340    }
341
342    pub fn image(mut self, image: &Widget) -> Self {
343        self.image = Some(image.clone());
344        self
345    }
346
347    pub fn image_position(mut self, image_position: PositionType) -> Self {
348        self.image_position = Some(image_position);
349        self
350    }
351
352    pub fn label(mut self, label: &str) -> Self {
353        self.label = Some(label.to_string());
354        self
355    }
356
357    pub fn relief(mut self, relief: ReliefStyle) -> Self {
358        self.relief = Some(relief);
359        self
360    }
361
362    pub fn use_underline(mut self, use_underline: bool) -> Self {
363        self.use_underline = Some(use_underline);
364        self
365    }
366
367    pub fn border_width(mut self, border_width: u32) -> Self {
368        self.border_width = Some(border_width);
369        self
370    }
371
372    pub fn child(mut self, child: &Widget) -> Self {
373        self.child = Some(child.clone());
374        self
375    }
376
377    pub fn resize_mode(mut self, resize_mode: ResizeMode) -> Self {
378        self.resize_mode = Some(resize_mode);
379        self
380    }
381
382    pub fn app_paintable(mut self, app_paintable: bool) -> Self {
383        self.app_paintable = Some(app_paintable);
384        self
385    }
386
387    pub fn can_default(mut self, can_default: bool) -> Self {
388        self.can_default = Some(can_default);
389        self
390    }
391
392    pub fn can_focus(mut self, can_focus: bool) -> Self {
393        self.can_focus = Some(can_focus);
394        self
395    }
396
397    pub fn events(mut self, events: gdk::EventMask) -> Self {
398        self.events = Some(events);
399        self
400    }
401
402    pub fn expand(mut self, expand: bool) -> Self {
403        self.expand = Some(expand);
404        self
405    }
406
407    #[cfg(any(feature = "v3_20", feature = "dox"))]
408    pub fn focus_on_click(mut self, focus_on_click: bool) -> Self {
409        self.focus_on_click = Some(focus_on_click);
410        self
411    }
412
413    pub fn halign(mut self, halign: Align) -> Self {
414        self.halign = Some(halign);
415        self
416    }
417
418    pub fn has_default(mut self, has_default: bool) -> Self {
419        self.has_default = Some(has_default);
420        self
421    }
422
423    pub fn has_focus(mut self, has_focus: bool) -> Self {
424        self.has_focus = Some(has_focus);
425        self
426    }
427
428    pub fn has_tooltip(mut self, has_tooltip: bool) -> Self {
429        self.has_tooltip = Some(has_tooltip);
430        self
431    }
432
433    pub fn height_request(mut self, height_request: i32) -> Self {
434        self.height_request = Some(height_request);
435        self
436    }
437
438    pub fn hexpand(mut self, hexpand: bool) -> Self {
439        self.hexpand = Some(hexpand);
440        self
441    }
442
443    pub fn hexpand_set(mut self, hexpand_set: bool) -> Self {
444        self.hexpand_set = Some(hexpand_set);
445        self
446    }
447
448    pub fn is_focus(mut self, is_focus: bool) -> Self {
449        self.is_focus = Some(is_focus);
450        self
451    }
452
453    pub fn margin(mut self, margin: i32) -> Self {
454        self.margin = Some(margin);
455        self
456    }
457
458    pub fn margin_bottom(mut self, margin_bottom: i32) -> Self {
459        self.margin_bottom = Some(margin_bottom);
460        self
461    }
462
463    pub fn margin_end(mut self, margin_end: i32) -> Self {
464        self.margin_end = Some(margin_end);
465        self
466    }
467
468    pub fn margin_start(mut self, margin_start: i32) -> Self {
469        self.margin_start = Some(margin_start);
470        self
471    }
472
473    pub fn margin_top(mut self, margin_top: i32) -> Self {
474        self.margin_top = Some(margin_top);
475        self
476    }
477
478    pub fn name(mut self, name: &str) -> Self {
479        self.name = Some(name.to_string());
480        self
481    }
482
483    pub fn no_show_all(mut self, no_show_all: bool) -> Self {
484        self.no_show_all = Some(no_show_all);
485        self
486    }
487
488    pub fn opacity(mut self, opacity: f64) -> Self {
489        self.opacity = Some(opacity);
490        self
491    }
492
493    pub fn parent(mut self, parent: &Container) -> Self {
494        self.parent = Some(parent.clone());
495        self
496    }
497
498    pub fn receives_default(mut self, receives_default: bool) -> Self {
499        self.receives_default = Some(receives_default);
500        self
501    }
502
503    pub fn sensitive(mut self, sensitive: bool) -> Self {
504        self.sensitive = Some(sensitive);
505        self
506    }
507
508    pub fn tooltip_markup(mut self, tooltip_markup: &str) -> Self {
509        self.tooltip_markup = Some(tooltip_markup.to_string());
510        self
511    }
512
513    pub fn tooltip_text(mut self, tooltip_text: &str) -> Self {
514        self.tooltip_text = Some(tooltip_text.to_string());
515        self
516    }
517
518    pub fn valign(mut self, valign: Align) -> Self {
519        self.valign = Some(valign);
520        self
521    }
522
523    pub fn vexpand(mut self, vexpand: bool) -> Self {
524        self.vexpand = Some(vexpand);
525        self
526    }
527
528    pub fn vexpand_set(mut self, vexpand_set: bool) -> Self {
529        self.vexpand_set = Some(vexpand_set);
530        self
531    }
532
533    pub fn visible(mut self, visible: bool) -> Self {
534        self.visible = Some(visible);
535        self
536    }
537
538    pub fn width_request(mut self, width_request: i32) -> Self {
539        self.width_request = Some(width_request);
540        self
541    }
542}
543
544pub const NONE_RADIO_BUTTON: Option<&RadioButton> = None;
545
546pub trait RadioButtonExt: 'static {
547    fn get_group(&self) -> Vec<RadioButton>;
548
549    fn join_group<P: IsA<RadioButton>>(&self, group_source: Option<&P>);
550
551    fn connect_group_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
552}
553
554impl<O: IsA<RadioButton>> RadioButtonExt for O {
555    fn get_group(&self) -> Vec<RadioButton> {
556        unsafe {
557            FromGlibPtrContainer::from_glib_none(gtk_sys::gtk_radio_button_get_group(
558                self.as_ref().to_glib_none().0,
559            ))
560        }
561    }
562
563    fn join_group<P: IsA<RadioButton>>(&self, group_source: Option<&P>) {
564        unsafe {
565            gtk_sys::gtk_radio_button_join_group(
566                self.as_ref().to_glib_none().0,
567                group_source.map(|p| p.as_ref()).to_glib_none().0,
568            );
569        }
570    }
571
572    fn connect_group_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
573        unsafe extern "C" fn group_changed_trampoline<P, F: Fn(&P) + 'static>(
574            this: *mut gtk_sys::GtkRadioButton,
575            f: glib_sys::gpointer,
576        ) where
577            P: IsA<RadioButton>,
578        {
579            let f: &F = &*(f as *const F);
580            f(&RadioButton::from_glib_borrow(this).unsafe_cast())
581        }
582        unsafe {
583            let f: Box_<F> = Box_::new(f);
584            connect_raw(
585                self.as_ptr() as *mut _,
586                b"group-changed\0".as_ptr() as *const _,
587                Some(transmute(group_changed_trampoline::<Self, F> as usize)),
588                Box_::into_raw(f),
589            )
590        }
591    }
592}
593
594impl fmt::Display for RadioButton {
595    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
596        write!(f, "RadioButton")
597    }
598}