use crate::image::Image;
pub use crate::prelude::*;
use fltk_sys::button::*;
use std::{
ffi::{CStr, CString},
mem,
os::raw,
};
#[derive(WidgetExt, ButtonExt, Debug)]
pub struct Button {
_inner: *mut Fl_Button,
}
#[repr(i32)]
#[derive(WidgetType, Debug, Copy, Clone, PartialEq)]
pub enum ButtonType {
NormalButton = 0,
ToggleButton = 1,
RadioButton = 102,
HiddenButton = 3,
}
#[derive(WidgetExt, ButtonExt, Debug)]
pub struct RadioButton {
_inner: *mut Fl_Radio_Button,
}
impl RadioButton {
pub fn is_toggled(&self) -> bool {
unsafe {
match Fl_Radio_Button_is_toggled(self._inner) {
0 => false,
_ => true,
}
}
}
pub fn toggle(&mut self, val: bool) {
unsafe {
Fl_Radio_Button_toggle(self._inner, val as i32)
}
}
}
#[derive(WidgetExt, ButtonExt, Debug)]
pub struct RoundButton {
_inner: *mut Fl_Round_Button,
}
impl RoundButton {
pub fn is_toggled(&self) -> bool {
unsafe {
match Fl_Round_Button_is_toggled(self._inner) {
0 => false,
_ => true,
}
}
}
pub fn toggle(&mut self, val: bool) {
unsafe {
Fl_Round_Button_toggle(self._inner, val as i32)
}
}
}
#[derive(WidgetExt, ButtonExt, Debug)]
pub struct CheckButton {
_inner: *mut Fl_Check_Button,
}
impl CheckButton {
pub fn is_checked(&self) -> bool {
unsafe {
match Fl_Check_Button_is_checked(self._inner) {
0 => false,
_ => true,
}
}
}
pub fn set_checked(&self, checked: bool) {
unsafe {
Fl_Check_Button_set_checked(self._inner, checked as i32);
}
}
}
#[derive(WidgetExt, ButtonExt, Debug)]
pub struct ToggleButton {
_inner: *mut Fl_Toggle_Button,
}
impl ToggleButton {
pub fn is_toggled(&self) -> bool {
unsafe {
match Fl_Toggle_Button_is_toggled(self._inner) {
0 => false,
_ => true,
}
}
}
pub fn toggle(&mut self, val: bool) {
unsafe {
Fl_Toggle_Button_toggle(self._inner, val as i32)
}
}
}
#[derive(WidgetExt, ButtonExt, Debug)]
pub struct LightButton {
_inner: *mut Fl_Light_Button,
}
impl LightButton {
pub fn is_on(&self) -> bool {
unsafe {
match Fl_Light_Button_is_on(self._inner) {
0 => false,
_ => true,
}
}
}
pub fn turn_on(&mut self, on: bool) {
unsafe {
Fl_Light_Button_turn_on(self._inner, on as i32)
}
}
}
#[derive(WidgetExt, ButtonExt, Debug)]
pub struct RepeatButton {
_inner: *mut Fl_Repeat_Button,
}
#[derive(WidgetExt, ButtonExt, Debug)]
pub struct ReturnButton {
_inner: *mut Fl_Return_Button,
}
#[cfg(test)]
mod button {
use super::*;
#[test]
fn tooltip() {
let mut but = Button::new(0,0,0,0,"hello");
but.set_tooltip("tooltip");
assert!(but.tooltip().unwrap() == "tooltip");
}
}