1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// SPDX-License-Identifier: MPL-2.0
//! A togglable button with adjacent customizable text.
use crate::prelude::*;
impl Ui {
/// Creates a new [`Checkbox`] with the given adjacent text.
pub fn create_checkbox<'ui>(
&'ui self,
text: impl Into<Vec<u8>>,
) -> Result<&'ui mut Checkbox, crate::Error> {
let text = self.make_cstring(text)?;
unsafe { call_libui_new_fn!(ui: self, fn: uiNewCheckbox(text.as_ptr()) -> Checkbox) }
}
}
/// A togglable button with adjacent customizable text.
///
/// Checkboxes are used to communicate boolean information such as true or false and yes or no. They
/// are conventionally rendered as a square that contains a checkmark when encoding a true state and
/// which is empty when false.
#[subcontrol(handle = "uiCheckbox")]
pub struct Checkbox;
impl<'ui> Checkbox<'ui> {
/// The text displayed adjacent to this checkbox.
#[bind_text(fn = "uiCheckboxText")]
pub fn text(&self) -> _;
/// Sets the text displayed adjacent to this checkbox.
///
/// This overrides the text supplied to [`Ui::create_checkbox`].
pub fn set_text(&self, text: impl Into<Vec<u8>>) -> Result<(), crate::Error> {
let text = self.ui.make_cstring(text)?;
unsafe { uiCheckboxSetText(self.as_ptr(), text.as_ptr()) };
Ok(())
}
/// Determines if this checkbox is checked.
///
/// Checkboxes are unchecked by default.
pub fn is_checked(&self) -> bool {
bool_from_libui(unsafe { uiCheckboxChecked(self.as_ptr()) })
}
/// Sets whether or not this checkbox is checked.
///
/// This overrides the state set by the user.
pub fn set_checked(&self, value: bool) {
unsafe { uiCheckboxSetChecked(self.as_ptr(), value.into()) };
}
/// Sets a callback for when the user toggles this checkbox.
///
/// This callback is unset by default. This is not activated when
/// [`set_checked`](Self::set_checked) is called.
#[bind_callback(fn = "uiCheckboxOnToggled")]
pub fn on_toggled(&self, f: fn()) {
f();
}
}