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
use bitflags::bitflags;
use crate::string::ImStr;
use crate::sys;
use crate::Ui;
bitflags!(
#[repr(transparent)]
pub struct SelectableFlags: u32 {
const DONT_CLOSE_POPUPS = sys::ImGuiSelectableFlags_DontClosePopups;
const SPAN_ALL_COLUMNS = sys::ImGuiSelectableFlags_SpanAllColumns;
const ALLOW_DOUBLE_CLICK = sys::ImGuiSelectableFlags_AllowDoubleClick;
const DISABLED = sys::ImGuiSelectableFlags_Disabled;
}
);
#[derive(Copy, Clone, Debug)]
#[must_use]
pub struct Selectable<'a> {
label: &'a ImStr,
selected: bool,
flags: SelectableFlags,
size: [f32; 2],
}
impl<'a> Selectable<'a> {
pub fn new(label: &ImStr) -> Selectable {
Selectable {
label,
selected: false,
flags: SelectableFlags::empty(),
size: [0.0, 0.0],
}
}
#[inline]
pub fn flags(mut self, flags: SelectableFlags) -> Self {
self.flags = flags;
self
}
#[inline]
pub fn selected(mut self, selected: bool) -> Self {
self.selected = selected;
self
}
#[inline]
pub fn close_popups(mut self, value: bool) -> Self {
self.flags.set(SelectableFlags::DONT_CLOSE_POPUPS, !value);
self
}
#[inline]
pub fn span_all_columns(mut self, value: bool) -> Self {
self.flags.set(SelectableFlags::SPAN_ALL_COLUMNS, value);
self
}
#[inline]
pub fn allow_double_click(mut self, value: bool) -> Self {
self.flags.set(SelectableFlags::ALLOW_DOUBLE_CLICK, value);
self
}
#[inline]
pub fn disabled(mut self, value: bool) -> Self {
self.flags.set(SelectableFlags::DISABLED, value);
self
}
#[inline]
pub fn size(mut self, size: [f32; 2]) -> Self {
self.size = size;
self
}
pub fn build(self, _: &Ui) -> bool {
unsafe {
sys::igSelectable(
self.label.as_ptr(),
self.selected,
self.flags.bits() as i32,
self.size.into(),
)
}
}
}
impl<'a> Selectable<'a> {
pub fn build_with_ref(self, ui: &Ui, selected: &mut bool) -> bool {
if self.selected(*selected).build(ui) {
*selected = true;
true
} else {
false
}
}
}