Skip to content

Commit 26af247

Browse files
committed
Run rustfmt
1 parent 4cbd767 commit 26af247

File tree

10 files changed

+71
-54
lines changed

10 files changed

+71
-54
lines changed

iui/examples/basic.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ extern crate iui;
22
use iui::prelude::*;
33

44
fn main() {
5-
// Initialize the UI library
6-
let ui = UI::init().expect("Couldn't initialize UI library");
7-
// Create a window into which controls can be placed
8-
let win = Window::new(&ui, "Test App", 200, 200, WindowType::NoMenubar);
9-
// Create a button to place in the window
10-
let btn = iui::controls::Button::new(&ui, "Button");
5+
// Initialize the UI library
6+
let ui = UI::init().expect("Couldn't initialize UI library");
7+
// Create a window into which controls can be placed
8+
let win = Window::new(&ui, "Test App", 200, 200, WindowType::NoMenubar);
9+
// Create a button to place in the window
10+
let btn = iui::controls::Button::new(&ui, "Button");
1111

12-
// Actually put the button in the window
13-
win.set_child(&ui, btn);
14-
// Show the window
15-
win.show(&ui);
16-
// Run the application
17-
ui.main();
12+
// Actually put the button in the window
13+
win.set_child(&ui, btn);
14+
// Show the window
15+
win.show(&ui);
16+
// Run the application
17+
ui.main();
1818
}

iui/src/controls/basic.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::mem;
2-
use std::ffi::{CString, CStr};
2+
use std::ffi::{CStr, CString};
33
use libc::c_void;
4-
use ui_sys::{self, uiButton, uiLabel, uiControl};
4+
use ui_sys::{self, uiButton, uiControl, uiLabel};
55
use super::Control;
66
use ui::UI;
77

@@ -22,7 +22,11 @@ impl Button {
2222

2323
/// Get a copy of the existing text on the button.
2424
pub fn text(&self, _ctx: &UI) -> String {
25-
unsafe { CStr::from_ptr(ui_sys::uiButtonText(self.uiButton)).to_string_lossy().into_owned() }
25+
unsafe {
26+
CStr::from_ptr(ui_sys::uiButtonText(self.uiButton))
27+
.to_string_lossy()
28+
.into_owned()
29+
}
2630
}
2731

2832
/// Get a reference to the existing text on the button.
@@ -64,4 +68,3 @@ define_control!{
6468
rust_type: Label,
6569
sys_type: uiLabel
6670
}
67-

iui/src/controls/create_macro.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ macro_rules! define_control {
4848
unsafe { ui_sys::uiControlShow(control.ui_control) }
4949
}
5050
/// Create an `iui` struct for this control from the raw pointer for it.
51-
///
51+
///
5252
/// # Unsafety
5353
/// The given pointer must point to a valid control or memory unsafety may result.
5454
#[allow(non_snake_case)]

iui/src/controls/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use ui::UI;
55

66
use std::ptr;
77

8-
#[macro_use] mod create_macro;
8+
#[macro_use]
9+
mod create_macro;
910
mod basic;
1011
pub use self::basic::*;
1112
mod window;
@@ -54,7 +55,6 @@ impl Control {
5455
// Don't check for initialization here since this can be run during deinitialization.
5556
ui_sys::uiControlDestroy(self.ui_control)
5657
}
57-
5858
}
5959

6060
impl UI {

iui/src/controls/window.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use controls::Control;
44
use ui::UI;
55
use libc::{c_int, c_void};
66
use std::cell::RefCell;
7-
use std::ffi::{CString, CStr};
7+
use std::ffi::{CStr, CString};
88
use std::mem;
99
use ui_sys::{self, uiControl, uiWindow};
1010

@@ -21,7 +21,7 @@ pub enum WindowType {
2121

2222
define_control!{
2323
/// Contains a single child control and displays it and its children in a window on the screen.
24-
rust_type: Window,
24+
rust_type: Window,
2525
sys_type: uiWindow
2626
}
2727

@@ -50,14 +50,20 @@ impl Window {
5050

5151
// Windows, by default, quit the application on closing.
5252
let ui = _ctx.clone();
53-
window.on_closing(_ctx, move |_|{ ui.quit(); });
53+
window.on_closing(_ctx, move |_| {
54+
ui.quit();
55+
});
5456

5557
window
5658
}
5759

5860
/// Get the current title of the window.
5961
pub fn title(&self, _ctx: &UI) -> String {
60-
unsafe { CStr::from_ptr(ui_sys::uiWindowTitle(self.uiWindow)).to_string_lossy().into_owned() }
62+
unsafe {
63+
CStr::from_ptr(ui_sys::uiWindowTitle(self.uiWindow))
64+
.to_string_lossy()
65+
.into_owned()
66+
}
6167
}
6268

6369
/// Get a reference to the current title of the window.
@@ -80,7 +86,10 @@ impl Window {
8086
/// the application when the window is closed.
8187
pub fn on_closing<F: FnMut(&Window)>(&self, _ctx: &UI, mut callback: F) {
8288
unsafe {
83-
let mut data: Box<Box<FnMut(&Window) -> bool>> = Box::new(Box::new(|window|{ callback(window); false }));
89+
let mut data: Box<Box<FnMut(&Window) -> bool>> = Box::new(Box::new(|window| {
90+
callback(window);
91+
false
92+
}));
8493
ui_sys::uiWindowOnClosing(
8594
self.uiWindow,
8695
c_callback,

iui/src/error.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
pub enum UIError {
66
/// Signifies that the underlying library was unable to properly hook into the platform's GUI APIs.
77
#[fail(display = "unable to initialize the underlying system bindings: {}", error)]
8-
FailedInitError {
9-
error: String,
10-
},
8+
FailedInitError { error: String },
119
/// Signifies that an attempt was made to initialize a new instance of the underlying library while
1210
/// one already existed.
1311
#[fail(display = "cannot initialize multiple instances of the libui toolkit")]

iui/src/ffi_tools.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ use std::sync::atomic::{AtomicBool, Ordering, ATOMIC_BOOL_INIT};
44
static INITIALIZED: AtomicBool = ATOMIC_BOOL_INIT;
55

66
/// Set the global flag stating that libUI is initialized.
7-
///
7+
///
88
/// # Unsafety
9-
/// If this is called when the library is not, in fact, initialized,
9+
/// If this is called when the library is not, in fact, initialized,
1010
/// the program will be placed in an undefined state.
11-
///
11+
///
1212
/// # Panics
1313
/// Panics if called when libUI is already marked as initialized.
1414
pub unsafe fn set_initialized() {
15-
assert!(!INITIALIZED.swap(true, Ordering::SeqCst),
15+
assert!(!INITIALIZED.swap(true, Ordering::SeqCst),
1616
"Tried to initialize libUI when it was already initialized. Aborting because this is an unsafe situation.");
1717
}
1818

1919
/// Set the global flag stating that libUI is no longer initialized.
20-
///
20+
///
2121
/// # Unsafety
2222
/// If this is called when the library is actually still initialized,
2323
/// the program could try to create a new instance, violating the library's

iui/src/lib.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
//! `iui`, the `i`mproved `u`ser `i`nterface crate, provides Rust bindings to `libui`, a wrapper library for native(ish) GUI libraries
2-
//! - Win32API on Windows, Cocoa on Mac OS X, and GTK+ on Linux and elsewhere. This library exposes a Rusty procedural interface to the
1+
//! `iui`, the `i`mproved `u`ser `i`nterface crate, provides Rust bindings to `libui`, a wrapper library for native(ish) GUI libraries
2+
//! - Win32API on Windows, Cocoa on Mac OS X, and GTK+ on Linux and elsewhere. This library exposes a Rusty procedural interface to the
33
//! "Least Common Denominator" of GUI widgets. They are all available on all supported platforms.
44
//! To use this library, import it in your `Cargo.toml`:
5-
//!
5+
//!
66
//! ```toml
77
//! iui = { git = "https://github.com/LeoTindall/libui-rs" }
88
//! ```
9-
//!
10-
//! Most of the functionality of the crate is exposed via the [UI](struct.UI.html) RAII guard, which handles all initialization and cleanup for the
9+
//!
10+
//! Most of the functionality of the crate is exposed via the [UI](struct.UI.html) RAII guard, which handles all initialization and cleanup for the
1111
//! underlying library.
1212
13-
#[macro_use] extern crate failure;
14-
#[macro_use] extern crate bitflags;
13+
#[macro_use]
14+
extern crate bitflags;
15+
#[macro_use]
16+
extern crate failure;
1517
extern crate libc;
1618
extern crate ui_sys;
1719

iui/src/ui.rs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ use controls::Window;
1212
/// RAII guard for the UI; when dropped, it uninits libUI.
1313
struct UIToken {
1414
// This PhantomData prevents UIToken from being Send and Sync
15-
_pd: PhantomData<*mut ()>
15+
_pd: PhantomData<*mut ()>,
1616
}
1717

1818
impl Drop for UIToken {
1919
fn drop(&mut self) {
20-
assert!(ffi_tools::is_initialized(), "Attempted to uninit libUI in UIToken destructor when libUI was not initialized!");
20+
assert!(
21+
ffi_tools::is_initialized(),
22+
"Attempted to uninit libUI in UIToken destructor when libUI was not initialized!"
23+
);
2124
unsafe {
2225
Window::destroy_all_windows();
2326
ui_sys::uiUninit();
@@ -29,57 +32,61 @@ impl Drop for UIToken {
2932
/// A handle to user interface functionality.
3033
#[derive(Clone)]
3134
pub struct UI {
32-
token: Rc<UIToken>
35+
token: Rc<UIToken>,
3336
}
3437

3538
impl UI {
3639
/// Initializes the underlying UI bindings, producing a [`UI`](struct.UI.html) struct which can be used
3740
/// to actually build your user interface. This is a reference counted type; clone it
3841
/// to get an additional reference that can be passed to, e.g., callbacks.
39-
///
42+
///
4043
/// Only one libUI binding can be active at once; if multiple instances are detected,
4144
/// this function will return a [`MultipleInitError`](enum.UIError.html#variant.MultipleInitError).
42-
///
45+
///
4346
/// ```
4447
/// # use iui::UI;
4548
/// {
4649
/// let ui1 = UI::init().unwrap();
47-
///
50+
///
4851
/// // This will fail because there is already an instance of UI.
4952
/// let ui2 = UI::init();
5053
/// assert!(ui2.is_err());
51-
///
54+
///
5255
/// // ui1 dropped here.
5356
/// }
5457
/// let ui3 = UI::init().unwrap();
5558
/// ```
56-
///
59+
///
5760
/// If libUI cannot initialize its hooks into the platform bindings, this function will
5861
/// return a [`FailedInitError`](enum.UIError.html#variant.FailedInitError) with the description of the problem.
5962
pub fn init() -> Result<UI, UIError> {
6063
if ffi_tools::is_initialized() {
61-
return Err(UIError::MultipleInitError{})
64+
return Err(UIError::MultipleInitError {});
6265
};
6366

6467
unsafe {
6568
// Create the magic value needed to init libUI
6669
let mut init_options = ui_sys::uiInitOptions {
6770
Size: mem::size_of::<ui_sys::uiInitOptions>(),
6871
};
69-
72+
7073
// Actually start up the library's functionality
7174
let err = ui_sys::uiInit(&mut init_options);
7275
if err.is_null() {
7376
// Success! We can safely give the user a token allowing them to do UI things.
7477
ffi_tools::set_initialized();
75-
Ok(UI {token: Rc::new(UIToken {_pd: PhantomData})})
78+
Ok(UI {
79+
token: Rc::new(UIToken { _pd: PhantomData }),
80+
})
7681
} else {
7782
// Error occurred; copy the string describing it, then free that memory.
7883
let error_string = CStr::from_ptr(err).to_string_lossy().into_owned();
7984
ui_sys::uiFreeInitError(err);
80-
Err(UIError::FailedInitError{ error: error_string })
85+
Err(UIError::FailedInitError {
86+
error: error_string,
87+
})
8188
}
82-
}
89+
}
8390
}
8491

8592
/// Hands control of this thread to the UI toolkit, allowing it to display the UI and respond to events. Does not return until the UI [quit](struct.UI.html#method.quit)s.

iui/src/util_types.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
11
//! Types describing data returned by various libUI items.
2-
3-

0 commit comments

Comments
 (0)