diff --git a/imgui/src/context.rs b/imgui/src/context.rs index 433dc41..601d1f2 100644 --- a/imgui/src/context.rs +++ b/imgui/src/context.rs @@ -527,6 +527,7 @@ impl Context { Ui { ctx: self, font_atlas, + buffer: RefCell::new(Vec::new()), } } } diff --git a/imgui/src/lib.rs b/imgui/src/lib.rs index 8bfe9bf..65077ea 100644 --- a/imgui/src/lib.rs +++ b/imgui/src/lib.rs @@ -120,6 +120,7 @@ impl Context { pub struct Ui<'ui> { ctx: &'ui Context, font_atlas: Option>, + buffer: cell::RefCell>, } impl<'ui> Ui<'ui> { diff --git a/imgui/src/widget/text.rs b/imgui/src/widget/text.rs index 53fab53..f64d4ae 100644 --- a/imgui/src/widget/text.rs +++ b/imgui/src/widget/text.rs @@ -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) { + 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, text: impl AsRef) { + 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")]