dear_imgui_rs/widget/
misc.rs1#![allow(
7 clippy::cast_possible_truncation,
8 clippy::cast_sign_loss,
9 clippy::as_conversions
10)]
11use crate::Ui;
12use crate::sys;
13
14bitflags::bitflags! {
15 #[repr(transparent)]
17 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
18 pub struct ButtonFlags: i32 {
19 const NONE = 0;
21 const MOUSE_BUTTON_LEFT = sys::ImGuiButtonFlags_MouseButtonLeft as i32;
23 const MOUSE_BUTTON_RIGHT = sys::ImGuiButtonFlags_MouseButtonRight as i32;
25 const MOUSE_BUTTON_MIDDLE = sys::ImGuiButtonFlags_MouseButtonMiddle as i32;
27 }
28}
29
30pub use crate::Direction as ArrowDirection;
32
33impl Ui {
34 #[doc(alias = "Bullet")]
36 pub fn bullet(&self) {
37 unsafe {
38 sys::igBullet();
39 }
40 }
41
42 #[doc(alias = "BulletText")]
44 pub fn bullet_text(&self, text: impl AsRef<str>) {
45 let text_ptr = self.scratch_txt(text);
46 unsafe {
47 const FMT: &[u8; 3] = b"%s\0";
49 sys::igBulletText(FMT.as_ptr() as *const std::os::raw::c_char, text_ptr);
50 }
51 }
52}
53
54impl Ui {
55 #[doc(alias = "SmallButton")]
57 pub fn small_button(&self, label: impl AsRef<str>) -> bool {
58 let label_ptr = self.scratch_txt(label);
59 unsafe { sys::igSmallButton(label_ptr) }
60 }
61
62 #[doc(alias = "InvisibleButton")]
64 pub fn invisible_button(&self, str_id: impl AsRef<str>, size: impl Into<[f32; 2]>) -> bool {
65 self.invisible_button_flags(str_id, size, crate::widget::ButtonFlags::NONE)
66 }
67
68 #[doc(alias = "InvisibleButton")]
70 pub fn invisible_button_flags(
71 &self,
72 str_id: impl AsRef<str>,
73 size: impl Into<[f32; 2]>,
74 flags: crate::widget::ButtonFlags,
75 ) -> bool {
76 let id_ptr = self.scratch_txt(str_id);
77 let size_vec: sys::ImVec2 = size.into().into();
78 unsafe { sys::igInvisibleButton(id_ptr, size_vec, flags.bits()) }
79 }
80
81 #[doc(alias = "ArrowButton")]
83 pub fn arrow_button(&self, str_id: impl AsRef<str>, dir: crate::Direction) -> bool {
84 let id_ptr = self.scratch_txt(str_id);
85 unsafe { sys::igArrowButton(id_ptr, dir as i32) }
86 }
87}
88
89#[must_use]
95pub struct DisabledToken<'ui> {
96 _ui: &'ui Ui,
97}
98
99impl<'ui> DisabledToken<'ui> {
100 fn new(ui: &'ui Ui) -> Self {
101 DisabledToken { _ui: ui }
102 }
103
104 pub fn end(self) {
106 }
108}
109
110impl<'ui> Drop for DisabledToken<'ui> {
111 fn drop(&mut self) {
112 unsafe { sys::igEndDisabled() }
113 }
114}
115
116impl Ui {
117 #[doc(alias = "BeginDisabled")]
122 pub fn begin_disabled(&self) -> DisabledToken<'_> {
123 unsafe { sys::igBeginDisabled(true) }
124 DisabledToken::new(self)
125 }
126
127 #[doc(alias = "BeginDisabled")]
132 pub fn begin_disabled_with_cond(&self, disabled: bool) -> DisabledToken<'_> {
133 unsafe { sys::igBeginDisabled(disabled) }
134 DisabledToken::new(self)
135 }
136}
137
138impl Ui {
143 #[doc(alias = "PushButtonRepeat")]
147 pub fn push_button_repeat(&self, repeat: bool) {
148 unsafe { sys::igPushItemFlag(sys::ImGuiItemFlags_ButtonRepeat as i32, repeat) }
149 }
150
151 #[doc(alias = "PopButtonRepeat")]
153 pub fn pop_button_repeat(&self) {
154 unsafe { sys::igPopItemFlag() }
155 }
156}
157
158impl Ui {
163 #[doc(alias = "SetItemKeyOwner")]
165 pub fn set_item_key_owner(&self, key: crate::input::Key) {
166 let k: sys::ImGuiKey = key as sys::ImGuiKey;
167 unsafe { sys::igSetItemKeyOwner_Nil(k) }
168 }
169
170 #[doc(alias = "SetItemKeyOwner")]
173 pub fn set_item_key_owner_with_flags(
174 &self,
175 key: crate::input::Key,
176 flags: sys::ImGuiInputFlags,
177 ) {
178 let k: sys::ImGuiKey = key as sys::ImGuiKey;
179 unsafe { sys::igSetItemKeyOwner_InputFlags(k, flags) }
180 }
181}