Skip to content

Commit 3fdff64

Browse files
authored
Merge pull request #29 from LeoTindall/bindgen
Transition to bindgen bindings.
2 parents 17449db + 27312b4 commit 3fdff64

28 files changed

+118
-1895
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,18 @@ No additional API surface.
1212

1313
### Changed
1414

15+
* `ui-sys` is now built with Bindgen. This means it can track libui more closely.
1516
* README.md now links to libui, and is more explanatory
17+
* `LayoutGrid::insert_at` no longer takes `left` and `height` arguments
18+
* Many APIs which took `u64` or `i64` arguments now take `i32` for wider compatibility
1619

1720
### Deprecated
1821

1922
No deprecations.
2023

2124
### Removed
2225

23-
Nothing was removed.
26+
* `Transform` no longer implements `PartialEq` as the existing implementation was broken.
2427

2528
### Fixed
2629

Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[workspace]
2+
3+
members = [
4+
"iui",
5+
"ui-sys",
6+
]
7+

iui/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@ maintenance = { status = "actively-developed" }
4141
bitflags = "1.0"
4242
libc = "0.2"
4343
failure = "0.1.1"
44-
ui-sys = "0.1.3"
44+
ui-sys = { path = "../ui-sys", version = "0.2.0" }
4545

iui/examples/inputs-grid.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use std::cell::RefCell;
1010

1111
/// This struct will hold the values that multiple callbacks will need to access.
1212
struct State {
13-
slider_val: i64,
14-
spinner_val: i64,
13+
slider_val: i32,
14+
spinner_val: i32,
1515
entry_val: String,
1616
multi_val: String,
1717
}

iui/examples/inputs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use std::cell::RefCell;
88

99
/// This struct will hold the values that multiple callbacks will need to access.
1010
struct State {
11-
slider_val: i64,
12-
spinner_val: i64,
11+
slider_val: i32,
12+
spinner_val: i32,
1313
entry_val: String,
1414
multi_val: String,
1515
}

iui/src/controls/area.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use controls::Control;
44
use draw;
5-
use libc::c_int;
5+
use std::os::raw::c_int;
66
use std::mem;
77
use ui::UI;
88
pub use ui_sys::uiExtKey as ExtKey;

iui/src/controls/basic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::Control;
2-
use libc::c_void;
2+
use std::os::raw::c_void;
33
use std::ffi::{CStr, CString};
44
use std::mem;
55
use ui::UI;
@@ -54,7 +54,7 @@ impl Button {
5454
let mut data: Box<Box<FnMut(&mut Button)>> = Box::new(Box::new(callback));
5555
ui_sys::uiButtonOnClicked(
5656
self.uiButton,
57-
c_callback,
57+
Some(c_callback),
5858
&mut *data as *mut Box<FnMut(&mut Button)> as *mut c_void,
5959
);
6060
mem::forget(data);

iui/src/controls/entry.rs

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
//! User input mechanisms: numbers, colors, and text in various forms.
22
33
use super::Control;
4-
use libc::c_void;
4+
use std::os::raw::c_void;
55
use std::ffi::{CStr, CString};
6-
use std::i64;
6+
use std::i32;
77
use std::mem;
88
use ui::UI;
99
use ui_sys::{
1010
self, uiCheckbox, uiCombobox, uiControl, uiEntry, uiMultilineEntry, uiSlider, uiSpinbox,
1111
};
1212

1313
pub trait NumericEntry {
14-
fn value(&self, ctx: &UI) -> i64;
15-
fn set_value(&mut self, ctx: &UI, value: i64);
16-
fn on_changed<F: FnMut(i64)>(&mut self, ctx: &UI, callback: F);
14+
fn value(&self, ctx: &UI) -> i32;
15+
fn set_value(&mut self, ctx: &UI, value: i32);
16+
fn on_changed<F: FnMut(i32)>(&mut self, ctx: &UI, callback: F);
1717
}
1818

1919
pub trait TextEntry {
@@ -36,76 +36,76 @@ define_control!{
3636

3737
impl Spinbox {
3838
// Create a new Spinbox which can produce values from `min` to `max`.
39-
pub fn new(_ctx: &UI, min: i64, max: i64) -> Self {
39+
pub fn new(_ctx: &UI, min: i32, max: i32) -> Self {
4040
unsafe { Spinbox::from_raw(ui_sys::uiNewSpinbox(min, max)) }
4141
}
4242

4343
// Create a new Spinbox with the maximum possible range.
4444
pub fn new_unlimited(_ctx: &UI) -> Self {
45-
Self::new(_ctx, i64::MIN, i64::MAX)
45+
Self::new(_ctx, i32::MIN, i32::MAX)
4646
}
4747
}
4848

4949
impl Slider {
5050
// Create a new Spinbox which can produce values from `min` to `max`.
51-
pub fn new(_ctx: &UI, min: i64, max: i64) -> Self {
51+
pub fn new(_ctx: &UI, min: i32, max: i32) -> Self {
5252
unsafe { Slider::from_raw(ui_sys::uiNewSlider(min, max)) }
5353
}
5454
}
5555

5656
impl NumericEntry for Spinbox {
57-
fn value(&self, _ctx: &UI) -> i64 {
57+
fn value(&self, _ctx: &UI) -> i32 {
5858
unsafe { ui_sys::uiSpinboxValue(self.uiSpinbox) }
5959
}
6060

61-
fn set_value(&mut self, _ctx: &UI, value: i64) {
61+
fn set_value(&mut self, _ctx: &UI, value: i32) {
6262
unsafe { ui_sys::uiSpinboxSetValue(self.uiSpinbox, value) }
6363
}
6464

65-
fn on_changed<F: FnMut(i64)>(&mut self, _ctx: &UI, callback: F) {
65+
fn on_changed<F: FnMut(i32)>(&mut self, _ctx: &UI, callback: F) {
6666
unsafe {
67-
let mut data: Box<Box<FnMut(i64)>> = Box::new(Box::new(callback));
67+
let mut data: Box<Box<FnMut(i32)>> = Box::new(Box::new(callback));
6868
ui_sys::uiSpinboxOnChanged(
6969
self.uiSpinbox,
70-
c_callback,
71-
&mut *data as *mut Box<FnMut(i64)> as *mut c_void,
70+
Some(c_callback),
71+
&mut *data as *mut Box<FnMut(i32)> as *mut c_void,
7272
);
7373
mem::forget(data);
7474
}
7575

7676
extern "C" fn c_callback(spinbox: *mut uiSpinbox, data: *mut c_void) {
7777
unsafe {
7878
let val = ui_sys::uiSpinboxValue(spinbox);
79-
mem::transmute::<*mut c_void, &mut Box<FnMut(i64)>>(data)(val);
79+
mem::transmute::<*mut c_void, &mut Box<FnMut(i32)>>(data)(val);
8080
}
8181
}
8282
}
8383
}
8484

8585
impl NumericEntry for Slider {
86-
fn value(&self, _ctx: &UI) -> i64 {
86+
fn value(&self, _ctx: &UI) -> i32 {
8787
unsafe { ui_sys::uiSliderValue(self.uiSlider) }
8888
}
8989

90-
fn set_value(&mut self, _ctx: &UI, value: i64) {
90+
fn set_value(&mut self, _ctx: &UI, value: i32) {
9191
unsafe { ui_sys::uiSliderSetValue(self.uiSlider, value) }
9292
}
9393

94-
fn on_changed<F: FnMut(i64)>(&mut self, _ctx: &UI, callback: F) {
94+
fn on_changed<F: FnMut(i32)>(&mut self, _ctx: &UI, callback: F) {
9595
unsafe {
96-
let mut data: Box<Box<FnMut(i64)>> = Box::new(Box::new(callback));
96+
let mut data: Box<Box<FnMut(i32)>> = Box::new(Box::new(callback));
9797
ui_sys::uiSliderOnChanged(
9898
self.uiSlider,
99-
c_callback,
100-
&mut *data as *mut Box<FnMut(i64)> as *mut c_void,
99+
Some(c_callback),
100+
&mut *data as *mut Box<FnMut(i32)> as *mut c_void,
101101
);
102102
mem::forget(data);
103103
}
104104

105105
extern "C" fn c_callback(slider: *mut uiSlider, data: *mut c_void) {
106106
unsafe {
107107
let val = ui_sys::uiSliderValue(slider);
108-
mem::transmute::<*mut c_void, &mut Box<FnMut(i64)>>(data)(val);
108+
mem::transmute::<*mut c_void, &mut Box<FnMut(i32)>>(data)(val);
109109
}
110110
}
111111
}
@@ -153,7 +153,7 @@ impl TextEntry for Entry {
153153
let mut data: Box<Box<FnMut(String)>> = Box::new(Box::new(callback));
154154
ui_sys::uiEntryOnChanged(
155155
self.uiEntry,
156-
c_callback,
156+
Some(c_callback),
157157
&mut *data as *mut Box<FnMut(String)> as *mut c_void,
158158
);
159159
mem::forget(data);
@@ -189,7 +189,7 @@ impl TextEntry for MultilineEntry {
189189
let mut data: Box<Box<FnMut(String)>> = Box::new(Box::new(callback));
190190
ui_sys::uiMultilineEntryOnChanged(
191191
self.uiMultilineEntry,
192-
c_callback,
192+
Some(c_callback),
193193
&mut *data as *mut Box<FnMut(String)> as *mut c_void,
194194
);
195195
mem::forget(data);
@@ -227,27 +227,25 @@ impl Combobox {
227227
}
228228
}
229229

230-
pub fn set_selected(&mut self, _ctx: &UI, value: i64) {
230+
pub fn set_selected(&mut self, _ctx: &UI, value: i32) {
231231
unsafe { ui_sys::uiComboboxSetSelected(self.uiCombobox, value) }
232232
}
233233

234-
pub fn on_selected<F: FnMut(i64)>(&mut self, _ctx: &UI, callback: F) {
234+
pub fn on_selected<F: FnMut(i32)>(&mut self, _ctx: &UI, callback: F) {
235235
unsafe {
236-
let mut data: Box<Box<FnMut(i64)>> = Box::new(Box::new(callback));
236+
let mut data: Box<Box<FnMut(i32)>> = Box::new(Box::new(callback));
237237
ui_sys::uiComboboxOnSelected(
238238
self.uiCombobox,
239-
c_callback,
240-
&mut *data as *mut Box<FnMut(i64)> as *mut c_void,
239+
Some(c_callback),
240+
&mut *data as *mut Box<FnMut(i32)> as *mut c_void,
241241
);
242242
mem::forget(data);
243243
}
244244

245245
extern "C" fn c_callback(combobox: *mut uiCombobox, data: *mut c_void) {
246246
unsafe {
247247
let val = ui_sys::uiComboboxSelected(combobox);
248-
// let combobox = Combobox::from_ui_control(combobox);
249-
mem::transmute::<*mut c_void, &mut Box<FnMut(i64)>>(data)(val);
250-
// mem::forget(combobox);
248+
mem::transmute::<*mut c_void, &mut Box<FnMut(i32)>>(data)(val);
251249
}
252250
}
253251
}
@@ -279,7 +277,7 @@ impl Checkbox {
279277
let mut data: Box<Box<FnMut(bool)>> = Box::new(Box::new(callback));
280278
ui_sys::uiCheckboxOnToggled(
281279
self.uiCheckbox,
282-
c_callback,
280+
Some(c_callback),
283281
&mut *data as *mut Box<FnMut(bool)> as *mut c_void,
284282
);
285283
mem::forget(data);

iui/src/controls/layout.rs

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::Control;
22
use error::UIError;
3-
use libc::c_int;
3+
use std::os::raw::c_int;
44
use std::ffi::{CStr, CString};
55
use std::mem;
66
use ui::UI;
@@ -168,12 +168,12 @@ impl TabGroup {
168168
/// Add the given control as a new tab in the tab group with the given name.
169169
///
170170
/// Returns the number of tabs in the group after adding the new tab.
171-
pub fn append<T: Into<Control>>(&mut self, _ctx: &UI, name: &str, control: T) -> u64 {
171+
pub fn append<T: Into<Control>>(&mut self, _ctx: &UI, name: &str, control: T) -> i32 {
172172
let control = control.into();
173173
unsafe {
174174
let c_string = CString::new(name.as_bytes().to_vec()).unwrap();
175175
ui_sys::uiTabAppend(self.uiTab, c_string.as_ptr(), control.ui_control);
176-
ui_sys::uiTabNumPages(self.uiTab) as u64
176+
ui_sys::uiTabNumPages(self.uiTab) as i32
177177
}
178178
}
179179

@@ -184,9 +184,9 @@ impl TabGroup {
184184
&mut self,
185185
_ctx: &UI,
186186
name: &str,
187-
before: u64,
187+
before: i32,
188188
control: T,
189-
) -> u64 {
189+
) -> i32 {
190190
unsafe {
191191
let c_string = CString::new(name.as_bytes().to_vec()).unwrap();
192192
ui_sys::uiTabInsertAt(
@@ -195,7 +195,7 @@ impl TabGroup {
195195
before,
196196
control.into().ui_control,
197197
);
198-
ui_sys::uiTabNumPages(self.uiTab) as u64
198+
ui_sys::uiTabNumPages(self.uiTab) as i32
199199
}
200200
}
201201

@@ -206,8 +206,8 @@ impl TabGroup {
206206
/// NOTE: This will leak the deleted control! We have no way of actually getting it
207207
/// to decrement its reference count per `libui`'s UI as of today, unless we maintain a
208208
/// separate list of children ourselves…
209-
pub fn delete(&mut self, _ctx: &UI, index: u64) -> Result<u64, UIError> {
210-
let n = unsafe { ui_sys::uiTabNumPages(self.uiTab) as u64 };
209+
pub fn delete(&mut self, _ctx: &UI, index: i32) -> Result<i32, UIError> {
210+
let n = unsafe { ui_sys::uiTabNumPages(self.uiTab) as i32};
211211
if index < n {
212212
unsafe { ui_sys::uiTabDelete(self.uiTab, index) };
213213
Ok(n)
@@ -217,12 +217,12 @@ impl TabGroup {
217217
}
218218

219219
/// Determine whether or not the tab group provides margins around its children.
220-
pub fn margined(&self, _ctx: &UI, page: u64) -> bool {
220+
pub fn margined(&self, _ctx: &UI, page: i32) -> bool {
221221
unsafe { ui_sys::uiTabMargined(self.uiTab, page) != 0 }
222222
}
223223

224224
/// Set whether or not the tab group provides margins around its children.
225-
pub fn set_margined(&mut self, _ctx: &UI, page: u64, margined: bool) {
225+
pub fn set_margined(&mut self, _ctx: &UI, page: i32, margined: bool) {
226226
unsafe { ui_sys::uiTabSetMargined(self.uiTab, page, margined as c_int) }
227227
}
228228
}
@@ -280,13 +280,12 @@ pub enum GridAlignment {
280280
impl GridAlignment {
281281
fn into_ui_align(self) -> uiAlign {
282282
use self::GridAlignment::*;
283-
use self::uiAlign::*;
284-
match self {
285-
Fill => uiAlignFill,
286-
Start => uiAlignStart,
287-
Center => uiAlignCenter,
288-
End => uiAlignEnd
289-
}
283+
return match self {
284+
Fill => ui_sys::uiAlignFill,
285+
Start => ui_sys::uiAlignStart,
286+
Center => ui_sys::uiAlignCenter,
287+
End => ui_sys::uiAlignEnd
288+
} as uiAlign;
290289
}
291290
}
292291

@@ -306,13 +305,12 @@ pub enum GridInsertionStrategy {
306305
impl GridInsertionStrategy {
307306
fn into_ui_at(self) -> uiAt {
308307
use self::GridInsertionStrategy::*;
309-
use self::uiAt::*;
310-
match self {
311-
Leading => uiAtLeading,
312-
Top => uiAtTop,
313-
Trailing => uiAtTrailing,
314-
Bottom => uiAtBottom
315-
}
308+
return match self {
309+
Leading => ui_sys::uiAtLeading,
310+
Top => ui_sys::uiAtTop,
311+
Trailing => ui_sys::uiAtTrailing,
312+
Bottom => ui_sys::uiAtBottom
313+
} as uiAlign;
316314
}
317315
}
318316

@@ -370,7 +368,6 @@ impl LayoutGrid {
370368
/// Inserts a control in to the `LayoutGrid` relative to an existing control.
371369
pub fn insert_at<T: Into<Control>, U: Into<Control>>(&mut self, _ctx: &UI,
372370
control: T, existing:U, at: GridInsertionStrategy,
373-
left: i32, height: i32,
374371
xspan: i32, yspan: i32,
375372
expand: GridExpand,
376373
halign: GridAlignment, valign: GridAlignment){
@@ -384,7 +381,7 @@ impl LayoutGrid {
384381
unsafe {
385382
ui_sys::uiGridInsertAt(
386383
self.uiGrid, control.into().ui_control, existing.into().ui_control,
387-
at.into_ui_at(), left, height, xspan, yspan,
384+
at.into_ui_at(), xspan, yspan,
388385
hexpand, halign.into_ui_align(), vexpand, valign.into_ui_align()
389386
);
390387
}

0 commit comments

Comments
 (0)