use crate::prelude::*;
impl Ui {
pub fn create_tab<'ui>(&'ui self) -> Result<&'ui mut Tab, crate::Error> {
unsafe { call_libui_new_fn!(ui: self, fn: uiNewTab() -> Tab) }
}
}
#[subcontrol(handle = "uiTab")]
#[derive(Container)]
#[container(
child_count = "uiTabNumPages",
remove_child = "uiTabDelete",
)]
pub struct Tab;
impl<'ui> Tab<'ui> {
pub fn push_page(
&self,
control: &'ui impl DerefMut<Target = Control>,
name: impl Into<Vec<u8>>,
) -> Result<NonNegativeInt, crate::Error> {
let index = self.child_count();
let name = self.ui.make_cstring(name)?;
control.make_child();
unsafe { uiTabAppend(self.as_ptr(), name.as_ptr(), control.as_ptr()) };
Ok(index)
}
pub fn insert_item(
&self,
before: impl Into<NonNegativeInt>,
control: &'ui impl DerefMut<Target = Control>,
name: impl Into<Vec<u8>>,
) -> Result<NonNegativeInt, crate::Error> {
let before = before.into();
assert!(self.contains_child(before));
let name = self.ui.make_cstring(name)?;
control.make_child();
unsafe { uiTabInsertAt(self.as_ptr(), name.as_ptr(), before.to_libui(), control.as_ptr()) };
Ok(before)
}
pub fn is_page_margined(&self, index: impl Into<NonNegativeInt>) -> bool {
let index = index.into();
assert!(self.contains_child(index));
bool_from_libui(unsafe { uiTabMargined(self.as_ptr(), index.to_libui()) })
}
pub fn set_page_margined(&self, index: impl Into<NonNegativeInt>, value: bool) {
let index = index.into();
assert!(self.contains_child(index));
unsafe { uiTabSetMargined(self.as_ptr(), index.to_libui(), value.into()) };
}
}