Skip to content

Commit 4479c10

Browse files
committed
Implement .append for control refs (without move)
1 parent aa33151 commit 4479c10

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

ui/src/controls.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,15 @@ impl BoxControl {
273273
}
274274
}
275275

276+
#[inline]
277+
pub fn append_ref(&self, child: &Control, stretchy: bool) {
278+
ffi_utils::ensure_initialized();
279+
unsafe {
280+
assert!(child.parent().is_none());
281+
ui_sys::uiBoxAppend(self.ui_box, child.ui_control, stretchy as c_int)
282+
}
283+
}
284+
276285
/// FIXME(pcwalton): This will leak the deleted control! We have no way of actually getting it
277286
/// to decrement its reference count per `libui`'s UI as of today, unless we maintain a
278287
/// separate list of children ourselves…
@@ -997,6 +1006,16 @@ impl RustAreaHandler {
9971006

9981007
define_control!(Area, uiArea, ui_area);
9991008

1009+
impl<'a> From<&'a Area> for Control {
1010+
fn from(area: &Area) -> Control {
1011+
unsafe {
1012+
let control = Control::from_ui_control(area.ui_area as *mut uiControl);
1013+
// mem::forget(self);
1014+
control
1015+
}
1016+
}
1017+
}
1018+
10001019
impl Area {
10011020
#[inline]
10021021
pub unsafe fn from_ui_area(ui_area: *mut uiArea) -> Area {

0 commit comments

Comments
 (0)