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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
use crate::image::Image;
pub use crate::prelude::*;
use crate::widget::Widget;
use crate::window::Window;
use fltk_sys::misc::*;
use std::{
    ffi::{CStr, CString},
    mem,
    os::raw,
};

/// Creates a spinner widget
#[derive(WidgetExt, Debug, Clone)]
pub struct Spinner {
    _inner: *mut Fl_Spinner,
}

impl Spinner {
    /// Returns the minimum value of the spinner widget
    pub fn minimum(&self) -> f64 {
        unsafe { Fl_Spinner_minimum(self._inner) }
    }
    /// Sets the minimu value of the spinner widget
    pub fn set_minimum(&mut self, a: f64) {
        unsafe { Fl_Spinner_set_minimum(self._inner, a) }
    }
    /// Returns the maximum value of the spinner widget
    pub fn maximum(&self) -> f64 {
        unsafe { Fl_Spinner_maximum(self._inner) }
    }
    /// Sets the minimum value of the spinner widget
    pub fn set_maximum(&mut self, a: f64) {
        unsafe { Fl_Spinner_set_maximum(self._inner, a) }
    }
    /// Sets the range of the spinner widget
    pub fn set_range(&mut self, a: f64, b: f64) {
        unsafe { Fl_Spinner_set_range(self._inner, a, b) }
    }
    /// Sets the step of the spinner widget
    pub fn set_step(&mut self, a: f64) {
        unsafe { Fl_Spinner_set_step(self._inner, a) }
    }
    /// Gets the range of the spinner widget
    pub fn step(&self) -> f64 {
        unsafe { Fl_Spinner_step(self._inner) }
    }
    /// Returns the maximum size supported by the spinner widget
    pub fn maximum_size(&self) -> u32 {
        unsafe { Fl_Spinner_maxsize(self._inner) as u32 }
    }
    /// Sets the maximum size supported by the spinner widget
    pub fn set_maximum_size(&mut self, s: u32) {
        unsafe { Fl_Spinner_set_maxsize(self._inner, s as i32) }
    }
    /// Gets the text font
    pub fn text_font(&self) -> Font {
        unsafe { std::mem::transmute(Fl_Spinner_text_font(self._inner)) }
    }
    /// Sets the text font
    pub fn set_text_font(&mut self, f: Font) {
        unsafe { Fl_Spinner_set_text_font(self._inner, f as i32) }
    }
    /// Gets the text size
    pub fn text_size(&self) -> u32 {
        unsafe { Fl_Spinner_text_size(self._inner) as u32 }
    }
    /// Sets the text size
    pub fn set_text_size(&mut self, s: u32) {
        unsafe { Fl_Spinner_set_textsize(self._inner, s as i32) }
    }
    /// Gets the text's color
    pub fn text_color(&self) -> Color {
        unsafe { std::mem::transmute(Fl_Spinner_text_color(self._inner)) }
    }
    /// Sets the text's color
    pub fn set_text_color(&mut self, color: Color) {
        unsafe { Fl_Spinner_set_text_color(self._inner, color as u32) }
    }
}

/// Creates a clock widget
#[derive(WidgetExt, Debug, Clone)]
pub struct Clock {
    _inner: *mut Fl_Clock,
}

/// Creates a chart widget
#[derive(WidgetExt, Debug, Clone)]
pub struct Chart {
    _inner: *mut Fl_Chart,
}

impl Chart {
    /// Clears the chart
    pub fn clear(&mut self) {
        unsafe { Fl_Chart_clear(self._inner) }
    }
    /// Adds an entry
    pub fn add(&mut self, val: f64, txt: &str, col: u32) {
        let txt = std::ffi::CString::new(txt).unwrap();
        unsafe { Fl_Chart_add(self._inner, val, txt.into_raw() as *const raw::c_char, col) }
    }
    /// Inserts an entry at an index
    pub fn insert(&mut self, idx: u32, val: f64, txt: &str, col: u32) {
        let txt = std::ffi::CString::new(txt).unwrap();
        unsafe {
            Fl_Chart_insert(
                self._inner,
                idx as i32,
                val,
                txt.into_raw() as *const raw::c_char,
                col,
            )
        }
    }
    /// Replaces an entry at an index
    pub fn replace(&mut self, idx: u32, val: f64, txt: &str, col: u32) {
        let txt = std::ffi::CString::new(txt).unwrap();
        unsafe {
            Fl_Chart_replace(
                self._inner,
                idx as i32,
                val,
                txt.into_raw() as *const raw::c_char,
                col,
            )
        }
    }
    /// Sets the bounds of the chart
    pub fn set_bounds(&mut self, a: f64, b: f64) {
        unsafe { Fl_Chart_set_bounds(self._inner, a, b) }
    }
    /// Returns the size of the chart
    pub fn size(&self) -> u32 {
        unsafe { Fl_Chart_size(self._inner) as u32 }
    }
    /// Sets the size of the chart
    pub fn set_size(&mut self, w: u32, h: u32) {
        unsafe { Fl_Chart_set_size(self._inner, w as i32, h as i32) }
    }
    /// Gets the maximum supported size of the chart
    pub fn maximum_size(&self) -> u32 {
        unsafe { Fl_Chart_maxsize(self._inner) as u32 }
    }
    /// Sets the maximum supported size of the chart
    pub fn set_maximum_size(&mut self, s: u32) {
        unsafe { Fl_Chart_set_maxsize(self._inner, s as i32) }
    }
    /// Gets the text font
    pub fn text_font(&self) -> Font {
        unsafe { std::mem::transmute(Fl_Chart_text_font(self._inner)) }
    }
    /// Sets the text font
    pub fn set_text_font(&mut self, f: Font) {
        unsafe { Fl_Chart_set_text_font(self._inner, f as i32) }
    }
    /// Gets the text size
    pub fn text_size(&self) -> u32 {
        unsafe { Fl_Chart_text_size(self._inner) as u32 }
    }
    /// Sets the text size
    pub fn set_text_size(&mut self, s: u32) {
        unsafe { Fl_Chart_set_textsize(self._inner, s as i32) }
    }
    /// Gets the text's color
    pub fn text_color(&self) -> Color {
        unsafe { std::mem::transmute(Fl_Chart_text_color(self._inner)) }
    }
    /// Sets the text's color
    pub fn set_text_color(&mut self, color: Color) {
        unsafe { Fl_Chart_set_text_color(self._inner, color as u32) }
    }
    /// Returns wheter the chart is autosizable
    pub fn is_autosize(&self) -> bool {
        unsafe {
            match Fl_Chart_is_autosize(self._inner) {
                0 => false,
                _ => true,
            }
        }
    }
    /// Sets the ability of the chart to be autosizable
    pub fn make_autosize(&mut self, val: bool) {
        unsafe { Fl_Chart_make_autosize(self._inner, val as i32) }
    }
}

/// Creates a progress bar
#[derive(WidgetExt, Debug, Clone)]
pub struct Progress {
    _inner: *mut Fl_Progress,
}

impl Progress {
    /// Returns the minimum value of the progress bar
    pub fn minimum(&self) -> f64 {
        unsafe { Fl_Progress_minimum(self._inner) }
    }
    /// Sets the minimu value of the progress bar
    pub fn set_minimum(&mut self, a: f64) {
        unsafe { Fl_Progress_set_minimum(self._inner, a) }
    }
    /// Returns the maximum value of the progress bar
    pub fn maximum(&self) -> f64 {
        unsafe { Fl_Progress_maximum(self._inner) }
    }
    /// Sets the minimum value of the progress bar
    pub fn set_maximum(&mut self, a: f64) {
        unsafe { Fl_Progress_set_maximum(self._inner, a) }
    }
    /// Returns the value of the progress bar
    pub fn value(&self) -> f64 {
        unsafe { Fl_Progress_value(self._inner) }
    }
    /// Sets the value of the progress bar
    pub fn set_value(&mut self, arg2: f64) {
        unsafe {
            Fl_Progress_set_value(self._inner, arg2);
        }
    }
}

#[derive(Clone, Debug)]
pub struct Tooltip {}

impl Tooltip {
    pub fn delay() -> f32 {
        unsafe { Fl_Tooltip_delay() }
    }

    pub fn set_delay(f: f32) {
        unsafe { Fl_Tooltip_set_delay(f) }
    }

    pub fn hidedelay() -> f32 {
        unsafe { Fl_Tooltip_hidedelay() }
    }

    pub fn set_hidedelay(f: f32) {
        unsafe { Fl_Tooltip_set_hidedelay(f) }
    }

    pub fn hoverdelay() -> f32 {
        unsafe { Fl_Tooltip_hoverdelay() }
    }

    pub fn set_hoverdelay(f: f32) {
        unsafe { Fl_Tooltip_set_hoverdelay(f) }
    }

    pub fn enabled() -> bool {
        unsafe {
            match Fl_Tooltip_enabled() {
                0 => false,
                _ => true,
            }
        }
    }

    pub fn enable(b: bool) {
        unsafe { Fl_Tooltip_enable(b as i32) }
    }

    pub fn disable() {
        unsafe { Fl_Tooltip_disable() }
    }

    pub fn enter_area<W: WidgetExt>(widget: W, x: i32, y: i32, w: i32, h: i32, tip: &str) {
        let tip = CString::new(tip).unwrap();
        unsafe {
            Fl_Tooltip_enter_area(
                widget.as_widget_ptr() as *mut Fl_Widget,
                x,
                y,
                w,
                h,
                tip.into_raw() as *const raw::c_char,
            )
        }
    }

    pub fn current_widget() -> Widget {
        unsafe {
            let widget_ptr = Fl_Tooltip_current_widget();
            assert!(!widget_ptr.is_null());
            Widget::from_raw(widget_ptr as *mut fltk_sys::widget::Fl_Widget)
        }
    }

    pub fn current<W: WidgetExt>(w: W) {
        unsafe { Fl_Tooltip_current(w.as_widget_ptr() as *mut Fl_Widget) }
    }

    pub fn font() -> Font {
        unsafe { mem::transmute(Fl_Tooltip_font()) }
    }

    pub fn set_font(font: Font) {
        unsafe { Fl_Tooltip_set_font(font as i32) }
    }

    pub fn font_size() -> u32 {
        unsafe { Fl_Tooltip_font_size() as u32 }
    }

    pub fn set_font_size(s: u32) {
        unsafe { Fl_Tooltip_set_font_size(s as i32) }
    }

    pub fn color() -> Color {
        unsafe { mem::transmute(Fl_Tooltip_color()) }
    }

    pub fn set_color(c: Color) {
        unsafe { Fl_Tooltip_set_color(c as u32) }
    }

    pub fn text_color() -> Color {
        unsafe { mem::transmute(Fl_Tooltip_text_color()) }
    }

    pub fn set_text_color(c: Color) {
        unsafe { Fl_Tooltip_set_text_color(c as u32) }
    }

    pub fn margin_width() -> u32 {
        unsafe { Fl_Tooltip_margin_width() as u32 }
    }

    pub fn set_margin_width(v: u32) {
        unsafe { Fl_Tooltip_set_margin_width(v as i32) }
    }

    pub fn margin_height() -> u32 {
        unsafe { Fl_Tooltip_margin_height() as u32 }
    }

    pub fn set_margin_height(v: u32) {
        unsafe { Fl_Tooltip_set_margin_height(v as i32) }
    }

    pub fn wrap_width() -> u32 {
        unsafe { Fl_Tooltip_wrap_width() as u32 }
    }

    pub fn set_wrap_width(v: u32) {
        unsafe { Fl_Tooltip_set_wrap_width(v as i32) }
    }

    pub fn current_window<W: WindowExt>() -> Window {
        unsafe {
            let wind = Fl_Tooltip_current_window();
            assert!(!wind.is_null());
            Window::from_widget_ptr(wind as *mut fltk_sys::widget::Fl_Widget)
        }
    }
}