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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
use bitflags::bitflags;
use std::ops::{BitAnd, BitAndAssign, BitOrAssign, Not};
use crate::math::MintVec2;
use crate::sys;
use crate::{Direction, Ui};
bitflags!(
#[repr(transparent)]
pub struct ButtonFlags: u32 {
const MOUSE_BUTTON_LEFT = sys::ImGuiButtonFlags_MouseButtonLeft;
const MOUSE_BUTTON_RIGHT = sys::ImGuiButtonFlags_MouseButtonRight;
const MOUSE_BUTTON_MIDDLE = sys::ImGuiButtonFlags_MouseButtonMiddle;
}
);
impl Ui {
#[doc(alias = "Button")]
pub fn button(&self, label: impl AsRef<str>) -> bool {
self.button_with_size(label, [0.0, 0.0])
}
#[doc(alias = "Button")]
pub fn button_with_size(&self, label: impl AsRef<str>, size: impl Into<MintVec2>) -> bool {
unsafe { sys::igButton(self.scratch_txt(label), size.into().into()) }
}
#[doc(alias = "SmallButton")]
pub fn small_button(&self, label: impl AsRef<str>) -> bool {
unsafe { sys::igSmallButton(self.scratch_txt(label)) }
}
#[doc(alias = "InvisibleButton")]
pub fn invisible_button(&self, id: impl AsRef<str>, size: impl Into<MintVec2>) -> bool {
unsafe { sys::igInvisibleButton(self.scratch_txt(id), size.into().into(), 0) }
}
#[doc(alias = "InvisibleButton")]
pub fn invisible_button_flags(
&self,
id: impl AsRef<str>,
size: impl Into<MintVec2>,
flags: ButtonFlags,
) -> bool {
unsafe {
sys::igInvisibleButton(
self.scratch_txt(id),
size.into().into(),
flags.bits() as i32,
)
}
}
#[doc(alias = "ArrowButton")]
pub fn arrow_button(&self, id: impl AsRef<str>, direction: Direction) -> bool {
unsafe { sys::igArrowButton(self.scratch_txt(id), direction as i32) }
}
#[doc(alias = "Checkbox")]
pub fn checkbox(&self, label: impl AsRef<str>, value: &mut bool) -> bool {
unsafe { sys::igCheckbox(self.scratch_txt(label), value as *mut bool) }
}
pub fn checkbox_flags<T>(&self, label: impl AsRef<str>, flags: &mut T, mask: T) -> bool
where
T: Copy + PartialEq + BitOrAssign + BitAndAssign + BitAnd<Output = T> + Not<Output = T>,
{
let mut value = *flags & mask == mask;
let pressed = self.checkbox(label, &mut value);
if pressed {
if value {
*flags |= mask;
} else {
*flags &= !mask;
}
}
pressed
}
#[doc(alias = "RadioButtonBool")]
pub fn radio_button_bool(&self, label: impl AsRef<str>, active: bool) -> bool {
unsafe { sys::igRadioButton_Bool(self.scratch_txt(label), active) }
}
#[doc(alias = "RadioButtonBool")]
pub fn radio_button<T>(&self, label: impl AsRef<str>, value: &mut T, button_value: T) -> bool
where
T: Copy + PartialEq,
{
let pressed = self.radio_button_bool(label, *value == button_value);
if pressed {
*value = button_value;
}
pressed
}
#[doc(alias = "Bullet")]
pub fn bullet(&self) {
unsafe { sys::igBullet() };
}
}