init effort

This commit is contained in:
Jack Spira 2021-09-06 23:15:46 -07:00 committed by Jack Mac
parent 04af6ab69a
commit 52e08bd09a
3 changed files with 20 additions and 4 deletions

View File

@ -527,6 +527,7 @@ impl Context {
Ui {
ctx: self,
font_atlas,
buffer: RefCell::new(Vec::new()),
}
}
}

View File

@ -120,6 +120,7 @@ impl Context {
pub struct Ui<'ui> {
ctx: &'ui Context,
font_atlas: Option<cell::RefMut<'ui, SharedFontAtlas>>,
buffer: cell::RefCell<Vec<u8>>,
}
impl<'ui> Ui<'ui> {

View File

@ -38,13 +38,27 @@ impl<'ui> Ui<'ui> {
}
/// Renders text wrapped to the end of window (or column)
#[doc(alias = "TextWrapperd")]
pub fn text_wrapped(&self, text: &ImStr) {
unsafe { sys::igTextWrapped(fmt_ptr(), text.as_ptr()) }
pub fn text_wrapped(&self, text: impl AsRef<str>) {
let mut handle = self.buffer.borrow_mut();
handle.clear();
handle.extend(text.as_ref().as_bytes());
handle.push(b'\0');
unsafe { sys::igTextWrapped(fmt_ptr(), handle.as_ptr()) }
}
/// Render a text + label combination aligned the same way as value+label widgets
#[doc(alias = "LabelText")]
pub fn label_text(&self, label: &ImStr, text: &ImStr) {
unsafe { sys::igLabelText(label.as_ptr(), fmt_ptr(), text.as_ptr()) }
pub fn label_text(&self, label: impl AsRef<str>, text: impl AsRef<str>) {
let mut handle = self.buffer.borrow_mut();
handle.clear();
handle.extend(label.as_ref().as_bytes());
handle.push(b'\0');
handle.extend(text.as_ref().as_bytes());
handle.push(b'\0');
let ptr_one = handle.as_ptr();
let ptr_two = unsafe { ptr_one.add(text.as_ref().len() + 1) };
unsafe { sys::igLabelText(ptr_one as *const _, fmt_ptr(), ptr_two as *const _) }
}
/// Renders text with a little bullet aligned to the typical tree node
#[doc(alias = "BulletText")]