Skip to content

Commit e2d6891

Browse files
author
Peter Voorhees
committed
Add .insert_at() to LayoutGrid
Closes LeoTindall/libui-rs/issues#13
1 parent a3c1950 commit e2d6891

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

iui/src/controls/layout.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,13 @@ impl GridAlignment {
293293
/// Informs a `LayoutGrid` as to position a control.
294294
#[derive(Clone, Copy, PartialEq)]
295295
pub enum GridInsertionStrategy {
296+
/// Place control to left of existing control, align tops
296297
Leading,
298+
/// Place control above existing control, align left edges
297299
Top,
300+
/// Place control to right of existing control, align tops
298301
Trailing,
302+
/// Place control below existing control, align left edges
299303
Bottom
300304
}
301305

@@ -362,5 +366,27 @@ impl LayoutGrid {
362366
);
363367
}
364368
}
365-
}
366369

370+
/// Inserts a control in to the `LayoutGrid` relative to an existing control.
371+
pub fn insert_at<T: Into<Control>, U: Into<Control>>(&mut self, _ctx: &UI,
372+
control: T, existing:U, at: GridInsertionStrategy,
373+
left: i32, height: i32,
374+
xspan: i32, yspan: i32,
375+
expand: GridExpand,
376+
halign: GridAlignment, valign: GridAlignment){
377+
378+
let (hexpand, vexpand) = match expand {
379+
GridExpand::Neither => (0, 0),
380+
GridExpand::Horizontal => (1, 0),
381+
GridExpand::Vertical => (0, 1),
382+
GridExpand::Both => (1, 1),
383+
};
384+
unsafe {
385+
ui_sys::uiGridInsertAt(
386+
self.uiGrid, control.into().ui_control, existing.into().ui_control,
387+
at.into_ui_at(), left, height, xspan, yspan,
388+
hexpand, halign.into_ui_align(), vexpand, valign.into_ui_align()
389+
);
390+
}
391+
}
392+
}

0 commit comments

Comments
 (0)