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
// SPDX-License-Identifier: MPL-2.0
//! A clickable button containing customizable text.
use crate::prelude::*;
impl Ui {
/// Creates a new [`Pushbutton`].
pub fn create_pushbutton<'ui>(
&'ui self,
text: impl Into<Vec<u8>>,
) -> Result<&'ui mut Pushbutton, crate::Error> {
let text = self.make_cstring(text)?;
unsafe { call_libui_new_fn!(ui: self, fn: uiNewButton(text.as_ptr()) -> Pushbutton) }
}
}
/// A clickable button containing customizable text.
#[subcontrol(handle = "uiButton")]
pub struct Pushbutton;
impl<'ui> Pushbutton<'ui> {
/// The text displayed within this pushbutton.
#[bind_text(fn = "uiButtonText")]
pub fn text(&self) -> _;
/// Sets the text displayed within this pushbutton.
///
/// This overrides the text supplied to [`Ui::create_pushbutton`].
pub fn set_text(&self, text: impl Into<Vec<u8>>) -> Result<(), crate::Error> {
let text = self.ui.make_cstring(text)?;
unsafe { uiButtonSetText(self.as_ptr(), text.as_ptr()) };
Ok(())
}
/// Sets a callback for when the user clicks this pushbutton.
///
/// This callback is unset by default.
#[bind_callback(fn = "uiButtonOnClicked")]
pub fn on_clicked(&self, f: fn()) {
f();
}
}