dear_imgui/widget/
misc.rs1#![allow(
2 clippy::cast_possible_truncation,
3 clippy::cast_sign_loss,
4 clippy::as_conversions
5)]
6use crate::Ui;
7use crate::sys;
8
9bitflags::bitflags! {
10 #[repr(transparent)]
12 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
13 pub struct ButtonFlags: i32 {
14 const NONE = 0;
16 const MOUSE_BUTTON_LEFT = sys::ImGuiButtonFlags_MouseButtonLeft as i32;
18 const MOUSE_BUTTON_RIGHT = sys::ImGuiButtonFlags_MouseButtonRight as i32;
20 const MOUSE_BUTTON_MIDDLE = sys::ImGuiButtonFlags_MouseButtonMiddle as i32;
22 }
23}
24
25pub use crate::Direction as ArrowDirection;
27
28impl Ui {
29 #[doc(alias = "Bullet")]
31 pub fn bullet(&self) {
32 unsafe {
33 sys::igBullet();
34 }
35 }
36
37 #[doc(alias = "BulletText")]
39 pub fn bullet_text(&self, text: impl AsRef<str>) {
40 let text_ptr = self.scratch_txt(text);
41 unsafe {
42 sys::igBulletText(text_ptr);
43 }
44 }
45}
46
47impl Ui {
48 #[doc(alias = "SmallButton")]
50 pub fn small_button(&self, label: impl AsRef<str>) -> bool {
51 let label_ptr = self.scratch_txt(label);
52 unsafe { sys::igSmallButton(label_ptr) }
53 }
54
55 #[doc(alias = "InvisibleButton")]
57 pub fn invisible_button(&self, str_id: impl AsRef<str>, size: impl Into<[f32; 2]>) -> bool {
58 self.invisible_button_flags(str_id, size, crate::widget::ButtonFlags::NONE)
59 }
60
61 #[doc(alias = "InvisibleButton")]
63 pub fn invisible_button_flags(
64 &self,
65 str_id: impl AsRef<str>,
66 size: impl Into<[f32; 2]>,
67 flags: crate::widget::ButtonFlags,
68 ) -> bool {
69 let id_ptr = self.scratch_txt(str_id);
70 let size_vec: sys::ImVec2 = size.into().into();
71 unsafe { sys::igInvisibleButton(id_ptr, size_vec, flags.bits()) }
72 }
73
74 #[doc(alias = "ArrowButton")]
76 pub fn arrow_button(&self, str_id: impl AsRef<str>, dir: crate::Direction) -> bool {
77 let id_ptr = self.scratch_txt(str_id);
78 unsafe { sys::igArrowButton(id_ptr, dir as i32) }
79 }
80}
81
82#[must_use]
88pub struct DisabledToken<'ui> {
89 _ui: &'ui Ui,
90}
91
92impl<'ui> DisabledToken<'ui> {
93 fn new(ui: &'ui Ui) -> Self {
94 DisabledToken { _ui: ui }
95 }
96
97 pub fn end(self) {
99 }
101}
102
103impl<'ui> Drop for DisabledToken<'ui> {
104 fn drop(&mut self) {
105 unsafe { sys::igEndDisabled() }
106 }
107}
108
109impl Ui {
110 #[doc(alias = "BeginDisabled")]
115 pub fn begin_disabled(&self) -> DisabledToken<'_> {
116 unsafe { sys::igBeginDisabled(true) }
117 DisabledToken::new(self)
118 }
119
120 #[doc(alias = "BeginDisabled")]
125 pub fn begin_disabled_with_cond(&self, disabled: bool) -> DisabledToken<'_> {
126 unsafe { sys::igBeginDisabled(disabled) }
127 DisabledToken::new(self)
128 }
129}
130
131impl Ui {
136 #[doc(alias = "PushButtonRepeat")]
140 pub fn push_button_repeat(&self, repeat: bool) {
141 unsafe { sys::igPushItemFlag(sys::ImGuiItemFlags_ButtonRepeat as i32, repeat) }
142 }
143
144 #[doc(alias = "PopButtonRepeat")]
146 pub fn pop_button_repeat(&self) {
147 unsafe { sys::igPopItemFlag() }
148 }
149}
150
151impl Ui {
156 #[doc(alias = "SetItemKeyOwner")]
158 pub fn set_item_key_owner(&self, key: crate::input::Key) {
159 let k: sys::ImGuiKey = key as sys::ImGuiKey;
160 unsafe { sys::igSetItemKeyOwner_Nil(k) }
161 }
162
163 #[doc(alias = "SetItemKeyOwner")]
166 pub fn set_item_key_owner_with_flags(
167 &self,
168 key: crate::input::Key,
169 flags: sys::ImGuiInputFlags,
170 ) {
171 let k: sys::ImGuiKey = key as sys::ImGuiKey;
172 unsafe { sys::igSetItemKeyOwner_InputFlags(k, flags) }
173 }
174}