Skip to content

Commit ca7f568

Browse files
committed
chore: cargo fmt
1 parent 5c58976 commit ca7f568

File tree

15 files changed

+305
-98
lines changed

15 files changed

+305
-98
lines changed

iui/examples/basic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
extern crate iui;
2+
use iui::controls::{Button, Group, Label, VerticalBox};
23
use iui::prelude::*;
3-
use iui::controls::{Label, Button, VerticalBox, Group};
44

55
fn main() {
66
// Initialize the UI library
77
let ui = UI::init().expect("Couldn't initialize UI library");
88
// Create a window into which controls can be placed
99
let mut win = Window::new(&ui, "Test App", 200, 200, WindowType::NoMenubar);
10-
10+
1111
// Create a vertical layout to hold the controls
1212
let mut vbox = VerticalBox::new(&ui);
1313
vbox.set_padded(&ui, true);

iui/examples/canvas.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
extern crate iui;
22
extern crate ui_sys;
33

4-
use iui::controls::{
5-
Area, AreaDrawParams, AreaHandler, HorizontalBox, LayoutStrategy,
6-
};
7-
use iui::draw::{Brush, Path, SolidBrush, FillMode};
4+
use iui::controls::{Area, AreaDrawParams, AreaHandler, HorizontalBox, LayoutStrategy};
5+
use iui::draw::{Brush, FillMode, Path, SolidBrush};
86
use iui::prelude::*;
97
use std::f64::consts::PI;
108

iui/examples/files.rs

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
//! and the Window::modal_err() call to display modal dialog boxes.
33
44
extern crate iui;
5+
use iui::controls::{Button, MultilineEntry, VerticalBox};
56
use iui::prelude::*;
6-
use iui::controls::{VerticalBox, MultilineEntry, Button};
7-
use std::io::prelude::*;
87
use std::error::Error;
98
use std::fs::File;
9+
use std::io::prelude::*;
1010

1111
fn main() {
1212
// Initialize the UI
@@ -32,17 +32,38 @@ fn main() {
3232
move |_| {
3333
if let Some(path) = window.save_file(&ui) {
3434
let mut file = match File::create(&path) {
35-
Err(why) => { window.modal_err(&ui, "I/O Error", &format!("Could not open file {}: {}", path.display(), why.description())); return; }
36-
Ok(f) => f
35+
Err(why) => {
36+
window.modal_err(
37+
&ui,
38+
"I/O Error",
39+
&format!(
40+
"Could not open file {}: {}",
41+
path.display(),
42+
why.description()
43+
),
44+
);
45+
return;
46+
}
47+
Ok(f) => f,
3748
};
3849
match file.write_all(entry.value(&ui).as_bytes()) {
39-
Err(why) => { window.modal_err(&ui, "I/O Error", &format!("Could not write to file {}: {}", path.display(), why.description())); return; }
40-
Ok(_) => ()
50+
Err(why) => {
51+
window.modal_err(
52+
&ui,
53+
"I/O Error",
54+
&format!(
55+
"Could not write to file {}: {}",
56+
path.display(),
57+
why.description()
58+
),
59+
);
60+
return;
61+
}
62+
Ok(_) => (),
4163
};
42-
}
64+
}
4365
}
4466
});
4567

4668
ui.main();
47-
4869
}

iui/examples/inputs-grid.rs

Lines changed: 175 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
//! Using the UIGrid function for a prettier interface.
33
44
extern crate iui;
5+
use iui::controls::{
6+
Entry, GridAlignment, GridExpand, HorizontalSeparator, Label, LayoutGrid, MultilineEntry,
7+
PasswordEntry, ProgressBar, Slider, Spinbox,
8+
};
59
use iui::prelude::*;
6-
use iui::controls::{Label, Spinbox, Slider, PasswordEntry, Entry, MultilineEntry, LayoutGrid,
7-
GridAlignment, GridExpand, HorizontalSeparator, ProgressBar};
8-
use std::rc::Rc;
910
use std::cell::RefCell;
11+
use std::rc::Rc;
1012

1113
/// This struct will hold the values that multiple callbacks will need to access.
1214
struct State {
@@ -22,7 +24,13 @@ fn main() {
2224
let ui = UI::init().unwrap();
2325

2426
// Initialize the state of the application.
25-
let state = Rc::new(RefCell::new(State { slider_val: 1, spinner_val: 1, entry_val: "".into(), password_val: "".into(), multi_val: "".into() }));
27+
let state = Rc::new(RefCell::new(State {
28+
slider_val: 1,
29+
spinner_val: 1,
30+
entry_val: "".into(),
31+
password_val: "".into(),
32+
multi_val: "".into(),
33+
}));
2634

2735
// Create the grid which we'll use to lay out controls
2836
let mut grid = LayoutGrid::new(&ui);
@@ -41,23 +49,77 @@ fn main() {
4149
let password = PasswordEntry::new(&ui);
4250
let multi = MultilineEntry::new(&ui);
4351
// Add everything into the grid
44-
grid.append(&ui, slider.clone(),
52+
grid.append(
53+
&ui,
54+
slider.clone(),
4555
// This is position (by slot) and size, expansion, and alignment.
4656
// In this case, row 0, col 0, 1 by 1, compress as much as possible,
4757
// and align to the fill.
48-
0, 0, 1, 1, GridExpand::Neither, GridAlignment::Fill, GridAlignment::Fill);
49-
grid.append(&ui, spinner.clone(),
58+
0,
59+
0,
60+
1,
61+
1,
62+
GridExpand::Neither,
63+
GridAlignment::Fill,
64+
GridAlignment::Fill,
65+
);
66+
grid.append(
67+
&ui,
68+
spinner.clone(),
5069
// This one is at column zero, row 1.
51-
0, 1, 1, 1, GridExpand::Neither, GridAlignment::Fill, GridAlignment::Fill);
52-
grid.append(&ui, HorizontalSeparator::new(&ui),
53-
0, 3, 1, 1, GridExpand::Neither, GridAlignment::Fill, GridAlignment::Fill);
54-
grid.append(&ui, entry.clone(),
55-
0, 4, 1, 1, GridExpand::Neither, GridAlignment::Fill, GridAlignment::Fill);
56-
grid.append(&ui, password.clone(),
57-
0, 5, 1, 1, GridExpand::Neither, GridAlignment::Fill, GridAlignment::Fill);
58-
grid.append(&ui, multi.clone(),
70+
0,
71+
1,
72+
1,
73+
1,
74+
GridExpand::Neither,
75+
GridAlignment::Fill,
76+
GridAlignment::Fill,
77+
);
78+
grid.append(
79+
&ui,
80+
HorizontalSeparator::new(&ui),
81+
0,
82+
3,
83+
1,
84+
1,
85+
GridExpand::Neither,
86+
GridAlignment::Fill,
87+
GridAlignment::Fill,
88+
);
89+
grid.append(
90+
&ui,
91+
entry.clone(),
92+
0,
93+
4,
94+
1,
95+
1,
96+
GridExpand::Neither,
97+
GridAlignment::Fill,
98+
GridAlignment::Fill,
99+
);
100+
grid.append(
101+
&ui,
102+
password.clone(),
103+
0,
104+
5,
105+
1,
106+
1,
107+
GridExpand::Neither,
108+
GridAlignment::Fill,
109+
GridAlignment::Fill,
110+
);
111+
grid.append(
112+
&ui,
113+
multi.clone(),
59114
// The multiline entry is at column 0, row 1, and expands vertically.
60-
0, 6, 1, 1, GridExpand::Vertical, GridAlignment::Fill, GridAlignment::Fill);
115+
0,
116+
6,
117+
1,
118+
1,
119+
GridExpand::Vertical,
120+
GridAlignment::Fill,
121+
GridAlignment::Fill,
122+
);
61123
(slider, spinner, entry, password, multi)
62124
};
63125

@@ -70,21 +132,82 @@ fn main() {
70132
let password_label = Label::new(&ui, "");
71133
let bigtext_label = Label::new(&ui, "");
72134
let progress_bar = ProgressBar::indeterminate(&ui);
73-
grid.append(&ui, add_label.clone(),
74-
1, 0, 1, 1, GridExpand::Neither, GridAlignment::Fill, GridAlignment::Fill);
75-
grid.append(&ui, sub_label.clone(),
76-
1, 1, 1, 1, GridExpand::Neither, GridAlignment::Fill, GridAlignment::Fill);
135+
grid.append(
136+
&ui,
137+
add_label.clone(),
138+
1,
139+
0,
140+
1,
141+
1,
142+
GridExpand::Neither,
143+
GridAlignment::Fill,
144+
GridAlignment::Fill,
145+
);
146+
grid.append(
147+
&ui,
148+
sub_label.clone(),
149+
1,
150+
1,
151+
1,
152+
1,
153+
GridExpand::Neither,
154+
GridAlignment::Fill,
155+
GridAlignment::Fill,
156+
);
77157
// We skip the #2 & 3 slots so that the text labels will align with their inputs.
78158
// This is important because the big text label can expand vertically.
79-
grid.append(&ui, text_label.clone(),
80-
1, 4, 1, 1, GridExpand::Neither, GridAlignment::Fill, GridAlignment::Fill);
81-
grid.append(&ui, password_label.clone(),
82-
1, 5, 1, 1, GridExpand::Neither, GridAlignment::Fill, GridAlignment::Fill);
83-
grid.append(&ui, bigtext_label.clone(),
84-
1, 6, 1, 1, GridExpand::Neither, GridAlignment::Fill, GridAlignment::Fill);
85-
grid.append(&ui, progress_bar.clone(),
86-
0, 7, 2, 1, GridExpand::Neither, GridAlignment::Fill, GridAlignment::Fill);
87-
(add_label, sub_label, text_label, password_label, bigtext_label, progress_bar)
159+
grid.append(
160+
&ui,
161+
text_label.clone(),
162+
1,
163+
4,
164+
1,
165+
1,
166+
GridExpand::Neither,
167+
GridAlignment::Fill,
168+
GridAlignment::Fill,
169+
);
170+
grid.append(
171+
&ui,
172+
password_label.clone(),
173+
1,
174+
5,
175+
1,
176+
1,
177+
GridExpand::Neither,
178+
GridAlignment::Fill,
179+
GridAlignment::Fill,
180+
);
181+
grid.append(
182+
&ui,
183+
bigtext_label.clone(),
184+
1,
185+
6,
186+
1,
187+
1,
188+
GridExpand::Neither,
189+
GridAlignment::Fill,
190+
GridAlignment::Fill,
191+
);
192+
grid.append(
193+
&ui,
194+
progress_bar.clone(),
195+
0,
196+
7,
197+
2,
198+
1,
199+
GridExpand::Neither,
200+
GridAlignment::Fill,
201+
GridAlignment::Fill,
202+
);
203+
(
204+
add_label,
205+
sub_label,
206+
text_label,
207+
password_label,
208+
bigtext_label,
209+
progress_bar,
210+
)
88211
};
89212

90213
// The window allows all constituent components to be displayed.
@@ -97,30 +220,39 @@ fn main() {
97220

98221
slider.on_changed(&ui, {
99222
let state = state.clone();
100-
move |val| { state.borrow_mut().slider_val = val; }
223+
move |val| {
224+
state.borrow_mut().slider_val = val;
225+
}
101226
});
102227

103228
spinner.on_changed(&ui, {
104229
let state = state.clone();
105-
move |val| { state.borrow_mut().spinner_val = val; }
230+
move |val| {
231+
state.borrow_mut().spinner_val = val;
232+
}
106233
});
107234

108235
entry.on_changed(&ui, {
109236
let state = state.clone();
110-
move |val| { state.borrow_mut().entry_val = val; }
237+
move |val| {
238+
state.borrow_mut().entry_val = val;
239+
}
111240
});
112241

113242
password.on_changed(&ui, {
114243
let state = state.clone();
115-
move |val| { state.borrow_mut().password_val = val; }
244+
move |val| {
245+
state.borrow_mut().password_val = val;
246+
}
116247
});
117248

118249
multi.on_changed(&ui, {
119250
let state = state.clone();
120-
move |val| { state.borrow_mut().multi_val = val; }
251+
move |val| {
252+
state.borrow_mut().multi_val = val;
253+
}
121254
});
122255

123-
124256
// Rather than just invoking ui.run(), using EventLoop gives a lot more control
125257
// over the user interface event loop.
126258
// Here, the on_tick() callback is used to update the view against the state.
@@ -137,8 +269,14 @@ fn main() {
137269
let state = state.borrow();
138270

139271
// Update all the outputs
140-
add_label.set_text(&ui, &format!("Added: {}", state.slider_val + state.spinner_val));
141-
sub_label.set_text(&ui, &format!("Subtracted: {}", state.slider_val - state.spinner_val));
272+
add_label.set_text(
273+
&ui,
274+
&format!("Added: {}", state.slider_val + state.spinner_val),
275+
);
276+
sub_label.set_text(
277+
&ui,
278+
&format!("Subtracted: {}", state.slider_val - state.spinner_val),
279+
);
142280
text_label.set_text(&ui, &format!("Text: {}", state.entry_val));
143281
password_label.set_text(&ui, &format!("Secret Text: {}", state.password_val));
144282
bigtext_label.set_text(&ui, &format!("Multiline Text: {}", state.multi_val));

0 commit comments

Comments
 (0)