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 sys::igBulletText(text_ptr);
48 }
49 }
50}
51
52impl Ui {
53 #[doc(alias = "SmallButton")]
55 pub fn small_button(&self, label: impl AsRef<str>) -> bool {
56 let label_ptr = self.scratch_txt(label);
57 unsafe { sys::igSmallButton(label_ptr) }
58 }
59
60 #[doc(alias = "InvisibleButton")]
62 pub fn invisible_button(&self, str_id: impl AsRef<str>, size: impl Into<[f32; 2]>) -> bool {
63 self.invisible_button_flags(str_id, size, crate::widget::ButtonFlags::NONE)
64 }
65
66 #[doc(alias = "InvisibleButton")]
68 pub fn invisible_button_flags(
69 &self,
70 str_id: impl AsRef<str>,
71 size: impl Into<[f32; 2]>,
72 flags: crate::widget::ButtonFlags,
73 ) -> bool {
74 let id_ptr = self.scratch_txt(str_id);
75 let size_vec: sys::ImVec2 = size.into().into();
76 unsafe { sys::igInvisibleButton(id_ptr, size_vec, flags.bits()) }
77 }
78
79 #[doc(alias = "ArrowButton")]
81 pub fn arrow_button(&self, str_id: impl AsRef<str>, dir: crate::Direction) -> bool {
82 let id_ptr = self.scratch_txt(str_id);
83 unsafe { sys::igArrowButton(id_ptr, dir as i32) }
84 }
85}
86
87#[must_use]
93pub struct DisabledToken<'ui> {
94 _ui: &'ui Ui,
95}
96
97impl<'ui> DisabledToken<'ui> {
98 fn new(ui: &'ui Ui) -> Self {
99 DisabledToken { _ui: ui }
100 }
101
102 pub fn end(self) {
104 }
106}
107
108impl<'ui> Drop for DisabledToken<'ui> {
109 fn drop(&mut self) {
110 unsafe { sys::igEndDisabled() }
111 }
112}
113
114impl Ui {
115 #[doc(alias = "BeginDisabled")]
120 pub fn begin_disabled(&self) -> DisabledToken<'_> {
121 unsafe { sys::igBeginDisabled(true) }
122 DisabledToken::new(self)
123 }
124
125 #[doc(alias = "BeginDisabled")]
130 pub fn begin_disabled_with_cond(&self, disabled: bool) -> DisabledToken<'_> {
131 unsafe { sys::igBeginDisabled(disabled) }
132 DisabledToken::new(self)
133 }
134}
135
136impl Ui {
141 #[doc(alias = "PushButtonRepeat")]
145 pub fn push_button_repeat(&self, repeat: bool) {
146 unsafe { sys::igPushItemFlag(sys::ImGuiItemFlags_ButtonRepeat as i32, repeat) }
147 }
148
149 #[doc(alias = "PopButtonRepeat")]
151 pub fn pop_button_repeat(&self) {
152 unsafe { sys::igPopItemFlag() }
153 }
154}
155
156impl Ui {
161 #[doc(alias = "SetItemKeyOwner")]
163 pub fn set_item_key_owner(&self, key: crate::input::Key) {
164 let k: sys::ImGuiKey = key as sys::ImGuiKey;
165 unsafe { sys::igSetItemKeyOwner_Nil(k) }
166 }
167
168 #[doc(alias = "SetItemKeyOwner")]
171 pub fn set_item_key_owner_with_flags(
172 &self,
173 key: crate::input::Key,
174 flags: sys::ImGuiInputFlags,
175 ) {
176 let k: sys::ImGuiKey = key as sys::ImGuiKey;
177 unsafe { sys::igSetItemKeyOwner_InputFlags(k, flags) }
178 }
179}