Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions libui/src/controls/checkbox.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::ffi::{CStr, CString};
use super::Control;
use callback_helpers::{from_void_ptr, to_heap_ptr};
use std::i32;
Expand Down Expand Up @@ -48,4 +49,26 @@ impl Checkbox {
);
}
}

/// Get a copy of the existing text on the checkbox.
pub fn text(&self) -> String {
unsafe {
CStr::from_ptr(libui_ffi::uiCheckboxText(self.uiCheckbox))
.to_string_lossy()
.into_owned()
}
}

/// Get a reference to the existing text on the checkbox.
pub fn text_ref(&self) -> &CStr {
unsafe { CStr::from_ptr(libui_ffi::uiCheckboxText(self.uiCheckbox)) }
}

/// Set the text label on the checkbox
pub fn set_text(&mut self, text: &str) {
unsafe {
let c_string = CString::new(text.as_bytes().to_vec()).unwrap();
libui_ffi::uiCheckboxSetText(self.uiCheckbox, c_string.as_ptr())
}
}
}
Loading