Skip to content

Commit 5a68a47

Browse files
committed
Merge branch 'grid-api-improve'
2 parents 193d779 + e9c1d54 commit 5a68a47

File tree

2 files changed

+32
-13
lines changed

2 files changed

+32
-13
lines changed

iui/examples/inputs-grid.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
extern crate iui;
55
use iui::prelude::*;
66
use iui::controls::{Label, Spinbox, Slider, Entry, MultilineEntry, LayoutGrid,
7-
GridAlignment, HorizontalSeparator};
7+
GridAlignment, GridExpand, HorizontalSeparator};
88
use std::rc::Rc;
99
use std::cell::RefCell;
1010

@@ -43,17 +43,17 @@ fn main() {
4343
// This is position (by slot) and size, expansion, and alignment.
4444
// In this case, row 0, col 0, 1 by 1, compress as much as possible,
4545
// and align to the fill.
46-
0, 0, 1, 1, false, false, GridAlignment::Fill, GridAlignment::Fill);
46+
0, 0, 1, 1, GridExpand::Neither, GridAlignment::Fill, GridAlignment::Fill);
4747
grid.append(&ui, spinner.clone(),
4848
// This one is at column zero, row 1.
49-
0, 1, 1, 1, false, false, GridAlignment::Fill, GridAlignment::Fill);
49+
0, 1, 1, 1, GridExpand::Neither, GridAlignment::Fill, GridAlignment::Fill);
5050
grid.append(&ui, HorizontalSeparator::new(&ui),
51-
0, 3, 1, 1, false, false, GridAlignment::Fill, GridAlignment::Fill);
51+
0, 3, 1, 1, GridExpand::Neither, GridAlignment::Fill, GridAlignment::Fill);
5252
grid.append(&ui, entry.clone(),
53-
0, 4, 1, 1, false, false, GridAlignment::Fill, GridAlignment::Fill);
53+
0, 4, 1, 1, GridExpand::Neither, GridAlignment::Fill, GridAlignment::Fill);
5454
grid.append(&ui, multi.clone(),
5555
// The multiline entry is at column 0, row 1, and expands vertically.
56-
0, 5, 1, 1, false, true, GridAlignment::Fill, GridAlignment::Fill);
56+
0, 5, 1, 1, GridExpand::Vertical, GridAlignment::Fill, GridAlignment::Fill);
5757
(slider, spinner, entry, multi)
5858
};
5959

@@ -65,13 +65,15 @@ fn main() {
6565
let text_label = Label::new(&ui, "");
6666
let bigtext_label = Label::new(&ui, "");
6767
grid.append(&ui, add_label.clone(),
68-
1, 0, 1, 1, false, false, GridAlignment::Fill, GridAlignment::Fill);
68+
1, 0, 1, 1, GridExpand::Neither, GridAlignment::Fill, GridAlignment::Fill);
6969
grid.append(&ui, sub_label.clone(),
70-
1, 1, 1, 1, false, false, GridAlignment::Fill, GridAlignment::Fill);
70+
1, 1, 1, 1, GridExpand::Neither, GridAlignment::Fill, GridAlignment::Fill);
71+
// We skip the #2 & 3 slots so that the text labels will align with their inputs.
72+
// This is important because the big text label can expand vertically.
7173
grid.append(&ui, text_label.clone(),
72-
1, 2, 1, 1, false, false, GridAlignment::Fill, GridAlignment::Fill);
74+
1, 4, 1, 1, GridExpand::Neither, GridAlignment::Fill, GridAlignment::Fill);
7375
grid.append(&ui, bigtext_label.clone(),
74-
1, 3, 1, 1, false, false, GridAlignment::Fill, GridAlignment::Fill);
76+
1, 5, 1, 1, GridExpand::Neither, GridAlignment::Fill, GridAlignment::Fill);
7577
(add_label, sub_label, text_label, bigtext_label)
7678
};
7779

iui/src/controls/layout.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,19 @@ impl Spacer {
251251
}
252252
}
253253

254+
/// Informs a `LayoutGrid` about how a control should use available space
255+
/// in one or both dimensions.
256+
pub enum GridExpand {
257+
/// This control should not use extra space
258+
Neither,
259+
/// This control should use extra space horizontally
260+
Horizontal,
261+
/// This control should use extra space vertically
262+
Vertical,
263+
/// This control should use all available space in both dimensions
264+
Both
265+
}
266+
254267
/// Informs a `LayoutGrid` how to align a control.
255268
#[derive(Clone, Copy, PartialEq)]
256269
pub enum GridAlignment {
@@ -334,10 +347,14 @@ impl LayoutGrid {
334347
pub fn append<T: Into<Control>>(&mut self, _ctx: &UI, control: T,
335348
left: i32, height: i32,
336349
xspan: i32, yspan: i32,
337-
hexpand: bool, vexpand: bool,
350+
expand: GridExpand,
338351
halign: GridAlignment, valign: GridAlignment) {
339-
let hexpand = if hexpand { 1 } else { 0 };
340-
let vexpand = if vexpand { 1 } else { 0 };
352+
let (hexpand, vexpand) = match expand {
353+
GridExpand::Neither => (0, 0),
354+
GridExpand::Horizontal => (1, 0),
355+
GridExpand::Vertical => (0, 1),
356+
GridExpand::Both => (1, 1),
357+
};
341358
unsafe {
342359
ui_sys::uiGridAppend(
343360
self.uiGrid, control.into().ui_control, left, height, xspan, yspan,

0 commit comments

Comments
 (0)