diff --git a/src/input.rs b/src/input.rs index a0fa03e..e784398 100644 --- a/src/input.rs +++ b/src/input.rs @@ -152,10 +152,8 @@ impl<'ui, 'p> InputText<'ui, 'p> { pub fn build(self) -> bool { unsafe { imgui_sys::igInputText(self.label.as_ptr(), - // TODO: this is evil. - // Perhaps something else than &mut str is better self.buf.as_ptr() as *mut i8, - self.buf.capacity() + 1, + self.buf.capacity_with_nul(), self.flags, None, ptr::null_mut()) diff --git a/src/string.rs b/src/string.rs index 1af1c5b..8cc1dd0 100644 --- a/src/string.rs +++ b/src/string.rs @@ -35,6 +35,7 @@ impl ImString { self.0.push(b'\0'); } pub fn capacity(&self) -> usize { self.0.capacity() - 1 } + pub fn capacity_with_nul(&self) -> usize { self.0.capacity() } pub fn reserve(&mut self, additional: usize) { self.0.reserve(additional); }