1
1
//! User input mechanisms: numbers, colors, and text in various forms.
2
2
3
3
use super :: Control ;
4
- use std:: os:: raw:: c_void;
5
4
use std:: ffi:: { CStr , CString } ;
6
5
use std:: i32;
7
6
use std:: mem;
7
+ use std:: os:: raw:: c_void;
8
8
use ui:: UI ;
9
9
use ui_sys:: {
10
- self , uiCheckbox, uiCombobox, uiControl, uiEntry, uiMultilineEntry, uiSlider, uiSpinbox,
10
+ self , uiCheckbox, uiCombobox, uiControl, uiEntry, uiMultilineEntry, uiRadioButtons, uiSlider,
11
+ uiSpinbox,
11
12
} ;
12
13
13
14
pub trait NumericEntry {
@@ -22,15 +23,15 @@ pub trait TextEntry {
22
23
fn on_changed < ' ctx , F : FnMut ( String ) + ' ctx > ( & mut self , ctx : & ' ctx UI , callback : F ) ;
23
24
}
24
25
25
- define_control ! {
26
+ define_control ! {
26
27
/// Numerical entry control which allows users to set any value in a range by typing or incrementing/decrementing.
27
- rust_type: Spinbox ,
28
+ rust_type: Spinbox ,
28
29
sys_type: uiSpinbox
29
30
}
30
31
31
- define_control ! {
32
+ define_control ! {
32
33
/// Numerical entry which allows users to select a value by picking a location along a line.
33
- rust_type: Slider ,
34
+ rust_type: Slider ,
34
35
sys_type: uiSlider
35
36
}
36
37
@@ -291,3 +292,46 @@ impl Checkbox {
291
292
}
292
293
}
293
294
}
295
+
296
+ define_control ! {
297
+ rust_type: RadioButtons ,
298
+ sys_type: uiRadioButtons
299
+ }
300
+
301
+ impl RadioButtons {
302
+ pub fn new ( _ctx : & UI ) -> Self {
303
+ unsafe { RadioButtons :: from_raw ( ui_sys:: uiNewRadioButtons ( ) ) }
304
+ }
305
+
306
+ pub fn append ( & self , _ctx : & UI , name : & str ) {
307
+ let c_string = CString :: new ( name. as_bytes ( ) . to_vec ( ) ) . unwrap ( ) ;
308
+ unsafe { ui_sys:: uiRadioButtonsAppend ( self . uiRadioButtons , c_string. as_ptr ( ) ) ; }
309
+ }
310
+
311
+ pub fn selected ( & self , _ctx : & UI ) -> i32 {
312
+ unsafe { ui_sys:: uiRadioButtonsSelected ( self . uiRadioButtons ) }
313
+ }
314
+
315
+ pub fn set_selected ( & mut self , _ctx : & UI , idx : i32 ) {
316
+ unsafe { ui_sys:: uiRadioButtonsSetSelected ( self . uiRadioButtons , idx) ; }
317
+ }
318
+
319
+ pub fn on_selected < ' ctx , F : FnMut ( i32 ) + ' ctx > ( & self , _ctx : & ' ctx UI , callback : F ) {
320
+ unsafe {
321
+ let mut data: Box < Box < FnMut ( i32 ) > > = Box :: new ( Box :: new ( callback) ) ;
322
+ ui_sys:: uiRadioButtonsOnSelected (
323
+ self . uiRadioButtons ,
324
+ Some ( c_callback) ,
325
+ & mut * data as * mut Box < FnMut ( i32 ) > as * mut c_void ,
326
+ ) ;
327
+ mem:: forget ( data) ;
328
+ }
329
+
330
+ extern "C" fn c_callback ( radio_buttons : * mut uiRadioButtons , data : * mut c_void ) {
331
+ unsafe {
332
+ let val = ui_sys:: uiRadioButtonsSelected ( radio_buttons) ;
333
+ mem:: transmute :: < * mut c_void , & mut Box < FnMut ( i32 ) > > ( data) ( val) ;
334
+ }
335
+ }
336
+ }
337
+ }
0 commit comments