arcdps_imgui\widget/
misc.rs
1use bitflags::bitflags;
2use std::ops::{BitAnd, BitAndAssign, BitOrAssign, Not};
3
4use crate::sys;
5use crate::{Direction, Ui};
6
7bitflags!(
8 #[repr(transparent)]
10 pub struct ButtonFlags: u32 {
11 const MOUSE_BUTTON_LEFT = sys::ImGuiButtonFlags_MouseButtonLeft;
13 const MOUSE_BUTTON_RIGHT = sys::ImGuiButtonFlags_MouseButtonRight;
15 const MOUSE_BUTTON_MIDDLE = sys::ImGuiButtonFlags_MouseButtonMiddle;
17 }
18);
19
20impl<'ui> Ui<'ui> {
22 #[doc(alias = "Button")]
31 pub fn button(&self, label: impl AsRef<str>) -> bool {
32 self.button_with_size(label, [0.0, 0.0])
33 }
34
35 #[doc(alias = "Button")]
42 pub fn button_with_size(&self, label: impl AsRef<str>, size: [f32; 2]) -> bool {
43 unsafe { sys::igButton(self.scratch_txt(label), size.into()) }
44 }
45 #[doc(alias = "SmallButton")]
49 pub fn small_button(&self, label: impl AsRef<str>) -> bool {
50 unsafe { sys::igSmallButton(self.scratch_txt(label)) }
51 }
52 #[doc(alias = "InvisibleButton")]
56 pub fn invisible_button(&self, id: impl AsRef<str>, size: [f32; 2]) -> bool {
57 unsafe { sys::igInvisibleButton(self.scratch_txt(id), size.into(), 0) }
58 }
59 #[doc(alias = "InvisibleButton")]
63 pub fn invisible_button_flags(
64 &self,
65 id: impl AsRef<str>,
66 size: [f32; 2],
67 flags: ButtonFlags,
68 ) -> bool {
69 unsafe { sys::igInvisibleButton(self.scratch_txt(id), size.into(), flags.bits() as i32) }
70 }
71 #[doc(alias = "ArrowButton")]
75 pub fn arrow_button(&self, id: impl AsRef<str>, direction: Direction) -> bool {
76 unsafe { sys::igArrowButton(self.scratch_txt(id), direction as i32) }
77 }
78 #[doc(alias = "Checkbox")]
82 pub fn checkbox(&self, label: impl AsRef<str>, value: &mut bool) -> bool {
83 unsafe { sys::igCheckbox(self.scratch_txt(label), value as *mut bool) }
84 }
85 pub fn checkbox_flags<T>(&self, label: impl AsRef<str>, flags: &mut T, mask: T) -> bool
89 where
90 T: Copy + PartialEq + BitOrAssign + BitAndAssign + BitAnd<Output = T> + Not<Output = T>,
91 {
92 let mut value = *flags & mask == mask;
93 let pressed = self.checkbox(label, &mut value);
94 if pressed {
95 if value {
96 *flags |= mask;
97 } else {
98 *flags &= !mask;
99 }
100 }
101 pressed
102 }
103 #[doc(alias = "RadioButtonBool")]
107 pub fn radio_button_bool(&self, label: impl AsRef<str>, active: bool) -> bool {
108 unsafe { sys::igRadioButton_Bool(self.scratch_txt(label), active) }
109 }
110 #[doc(alias = "RadioButtonBool")]
114 pub fn radio_button<T>(&self, label: impl AsRef<str>, value: &mut T, button_value: T) -> bool
115 where
116 T: Copy + PartialEq,
117 {
118 let pressed = self.radio_button_bool(label, *value == button_value);
119 if pressed {
120 *value = button_value;
121 }
122 pressed
123 }
124 #[doc(alias = "Bullet")]
126 pub fn bullet(&self) {
127 unsafe { sys::igBullet() };
128 }
129}