1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
use crate::image::Image;
pub use crate::prelude::*;
use fltk_sys::button::*;
use std::{
    ffi::{CStr, CString},
    mem,
    os::raw,
};

/// Creates a normal button
#[derive(WidgetExt, ButtonExt, Debug, Clone)]
pub struct Button {
    _inner: *mut Fl_Button,
}

/// Defines the button type, which can be changed dynamically using the set_type function().
#[repr(i32)]
#[derive(WidgetType, Debug, Copy, Clone, PartialEq)]
pub enum ButtonType {
    NormalButton = 0,
    ToggleButton = 1,
    RadioButton = 102,
    HiddenButton = 3,
}

/// Creates a radio button
#[derive(WidgetExt, ButtonExt, Debug, Clone)]
pub struct RadioButton {
    _inner: *mut Fl_Radio_Button,
}

impl RadioButton {
    /// Check whether a radio button is toggled
    pub fn is_toggled(&self) -> bool {
        unsafe {
            match Fl_Radio_Button_is_toggled(self._inner) {
                0 => false,
                _ => true,
            }
        }
    }
}

/// Creates a round button
#[derive(WidgetExt, ButtonExt, Debug, Clone)]
pub struct RoundButton {
    _inner: *mut Fl_Round_Button,
}

/// Creates a check button
#[derive(WidgetExt, ButtonExt, Debug, Clone)]
pub struct CheckButton {
    _inner: *mut Fl_Check_Button,
}

impl CheckButton {
    /// Check whether a check button is checked
    pub fn is_checked(&self) -> bool {
        unsafe {
            match Fl_Check_Button_is_checked(self._inner) {
                0 => false,
                _ => true,
            }
        }
    }
}

/// Creates a toggle button
#[derive(WidgetExt, ButtonExt, Debug, Clone)]
pub struct ToggleButton {
    _inner: *mut Fl_Toggle_Button,
}

impl ToggleButton {
    /// Check whether a toggle button is toggled
    pub fn is_toggled(&self) -> bool {
        unsafe {
            match Fl_Toggle_Button_is_toggled(self._inner) {
                0 => false,
                _ => true,
            }
        }
    }
}

/// Creates a light button
#[derive(WidgetExt, ButtonExt, Debug, Clone)]
pub struct LightButton {
    _inner: *mut Fl_Light_Button,
}

impl LightButton {
    /// Check whether a light button is on
    pub fn is_on(&self) -> bool {
        unsafe {
            match Fl_Light_Button_is_on(self._inner) {
                0 => false,
                _ => true,
            }
        }
    }
}

/// Creates a repeat button
#[derive(WidgetExt, ButtonExt, Debug, Clone)]
pub struct RepeatButton {
    _inner: *mut Fl_Repeat_Button,
}

/// Creates a return button
#[derive(WidgetExt, ButtonExt, Debug, Clone)]
pub struct ReturnButton {
    _inner: *mut Fl_Return_Button,
}