1#![allow(
18 clippy::cast_possible_truncation,
19 clippy::cast_sign_loss,
20 clippy::as_conversions
21)]
22use crate::Ui;
23use crate::sys;
24
25create_token!(
26 pub struct GroupToken<'ui>;
28
29 drop { unsafe { sys::igEndGroup() } }
32);
33
34create_token!(
35 pub struct ClipRectToken<'ui>;
37
38 drop { unsafe { sys::igPopClipRect() } }
40);
41
42impl Ui {
44 #[doc(alias = "Separator")]
48 pub fn separator(&self) {
49 unsafe { sys::igSeparator() }
50 }
51
52 #[doc(alias = "SeparatorText")]
54 pub fn separator_with_text(&self, text: impl AsRef<str>) {
55 unsafe { sys::igSeparatorText(self.scratch_txt(text)) }
56 }
57
58 #[doc(alias = "SeparatorEx")]
60 pub fn separator_vertical(&self) {
61 unsafe { sys::igSeparatorEx(sys::ImGuiSeparatorFlags_Vertical as i32, 1.0) }
62 }
63
64 #[doc(alias = "SeparatorEx")]
66 pub fn separator_horizontal(&self) {
67 unsafe { sys::igSeparatorEx(sys::ImGuiSeparatorFlags_Horizontal as i32, 1.0) }
68 }
69
70 #[doc(alias = "SameLine")]
77 pub fn same_line(&self) {
78 self.same_line_with_pos(0.0);
79 }
80
81 #[doc(alias = "SameLine")]
88 pub fn same_line_with_pos(&self, pos_x: f32) {
89 self.same_line_with_spacing(pos_x, -1.0)
90 }
91
92 #[doc(alias = "SameLine")]
96 pub fn same_line_with_spacing(&self, pos_x: f32, spacing_w: f32) {
97 unsafe { sys::igSameLine(pos_x, spacing_w) }
98 }
99
100 #[doc(alias = "NewLine")]
102 pub fn new_line(&self) {
103 unsafe { sys::igNewLine() }
104 }
105
106 #[doc(alias = "Spacing")]
108 pub fn spacing(&self) {
109 unsafe { sys::igSpacing() }
110 }
111
112 #[doc(alias = "Dummy")]
116 pub fn dummy(&self, size: impl Into<[f32; 2]>) {
117 let size_vec: sys::ImVec2 = size.into().into();
118 unsafe { sys::igDummy(size_vec) }
119 }
120
121 #[doc(alias = "Indent")]
126 pub fn indent(&self) {
127 self.indent_by(0.0)
128 }
129
130 #[doc(alias = "Indent")]
132 pub fn indent_by(&self, width: f32) {
133 unsafe { sys::igIndent(width) };
134 }
135
136 #[doc(alias = "Unindent")]
141 pub fn unindent(&self) {
142 self.unindent_by(0.0)
143 }
144
145 #[doc(alias = "Unindent")]
147 pub fn unindent_by(&self, width: f32) {
148 unsafe { sys::igUnindent(width) };
149 }
150
151 #[doc(alias = "BeginGroup")]
155 pub fn begin_group(&self) -> GroupToken<'_> {
156 unsafe { sys::igBeginGroup() };
157 GroupToken::new(self)
158 }
159
160 #[doc(alias = "BeginGroup")]
164 pub fn group<R, F: FnOnce() -> R>(&self, f: F) -> R {
165 let group = self.begin_group();
166 let result = f();
167 group.end();
168 result
169 }
170
171 #[doc(alias = "GetCursorPos")]
173 pub fn cursor_pos(&self) -> [f32; 2] {
174 unsafe {
175 let mut pos = sys::ImVec2 { x: 0.0, y: 0.0 };
176 sys::igGetCursorPos(&mut pos);
177 [pos.x, pos.y]
178 }
179 }
180
181 #[doc(alias = "GetCursorScreenPos")]
183 pub fn cursor_screen_pos(&self) -> [f32; 2] {
184 unsafe {
185 let mut pos = sys::ImVec2 { x: 0.0, y: 0.0 };
186 sys::igGetCursorScreenPos(&mut pos);
187 [pos.x, pos.y]
188 }
189 }
190
191 #[doc(alias = "SetCursorPos")]
193 pub fn set_cursor_pos(&self, pos: impl Into<[f32; 2]>) {
194 let pos_array = pos.into();
195 let pos_vec = sys::ImVec2 {
196 x: pos_array[0],
197 y: pos_array[1],
198 };
199 unsafe { sys::igSetCursorPos(pos_vec) };
200 }
201
202 #[doc(alias = "SetCursorScreenPos")]
204 pub fn set_cursor_screen_pos(&self, pos: impl Into<[f32; 2]>) {
205 let pos_array = pos.into();
206 let pos_vec = sys::ImVec2 {
207 x: pos_array[0],
208 y: pos_array[1],
209 };
210 unsafe { sys::igSetCursorScreenPos(pos_vec) };
211 }
212
213 #[doc(alias = "GetCursorPosX")]
215 pub fn cursor_pos_x(&self) -> f32 {
216 unsafe { sys::igGetCursorPosX() }
217 }
218
219 #[doc(alias = "GetCursorPosY")]
221 pub fn cursor_pos_y(&self) -> f32 {
222 unsafe { sys::igGetCursorPosY() }
223 }
224
225 #[doc(alias = "SetCursorPosX")]
227 pub fn set_cursor_pos_x(&self, x: f32) {
228 unsafe { sys::igSetCursorPosX(x) };
229 }
230
231 #[doc(alias = "SetCursorPosY")]
233 pub fn set_cursor_pos_y(&self, y: f32) {
234 unsafe { sys::igSetCursorPosY(y) };
235 }
236
237 #[doc(alias = "GetCursorStartPos")]
239 pub fn cursor_start_pos(&self) -> [f32; 2] {
240 unsafe {
241 let mut pos = sys::ImVec2 { x: 0.0, y: 0.0 };
242 sys::igGetCursorStartPos(&mut pos);
243 [pos.x, pos.y]
244 }
245 }
246}
247
248impl Ui {
253 #[doc(alias = "GetTextLineHeight")]
255 pub fn text_line_height(&self) -> f32 {
256 unsafe { sys::igGetTextLineHeight() }
257 }
258
259 #[doc(alias = "GetTextLineHeightWithSpacing")]
261 pub fn text_line_height_with_spacing(&self) -> f32 {
262 unsafe { sys::igGetTextLineHeightWithSpacing() }
263 }
264
265 #[doc(alias = "GetFrameHeight")]
267 pub fn frame_height(&self) -> f32 {
268 unsafe { sys::igGetFrameHeight() }
269 }
270
271 #[doc(alias = "GetFrameHeightWithSpacing")]
273 pub fn frame_height_with_spacing(&self) -> f32 {
274 unsafe { sys::igGetFrameHeightWithSpacing() }
275 }
276
277 #[doc(alias = "PushClipRect")]
279 pub fn push_clip_rect(
280 &self,
281 min: impl Into<[f32; 2]>,
282 max: impl Into<[f32; 2]>,
283 intersect_with_current: bool,
284 ) {
285 let min = min.into();
286 let max = max.into();
287 let min_v = sys::ImVec2 {
288 x: min[0],
289 y: min[1],
290 };
291 let max_v = sys::ImVec2 {
292 x: max[0],
293 y: max[1],
294 };
295 unsafe { sys::igPushClipRect(min_v, max_v, intersect_with_current) }
296 }
297
298 #[doc(alias = "PopClipRect")]
300 pub fn pop_clip_rect(&self) {
301 unsafe { sys::igPopClipRect() }
302 }
303
304 pub fn with_clip_rect<R>(
306 &self,
307 min: impl Into<[f32; 2]>,
308 max: impl Into<[f32; 2]>,
309 intersect_with_current: bool,
310 f: impl FnOnce() -> R,
311 ) -> R {
312 self.push_clip_rect(min, max, intersect_with_current);
313 let _t = ClipRectToken::new(self);
314 f()
315 }
316
317 #[doc(alias = "IsRectVisible")]
319 pub fn is_rect_visible_min_max(
320 &self,
321 rect_min: impl Into<[f32; 2]>,
322 rect_max: impl Into<[f32; 2]>,
323 ) -> bool {
324 let mn = rect_min.into();
325 let mx = rect_max.into();
326 let mn_v = sys::ImVec2 { x: mn[0], y: mn[1] };
327 let mx_v = sys::ImVec2 { x: mx[0], y: mx[1] };
328 unsafe { sys::igIsRectVisible_Vec2(mn_v, mx_v) }
329 }
330
331 #[doc(alias = "IsRectVisible")]
333 pub fn is_rect_visible_with_size(&self, size: impl Into<[f32; 2]>) -> bool {
334 let s = size.into();
335 let v = sys::ImVec2 { x: s[0], y: s[1] };
336 unsafe { sys::igIsRectVisible_Nil(v) }
337 }
338
339 #[doc(alias = "AlignTextToFramePadding")]
341 pub fn align_text_to_frame_padding(&self) {
342 unsafe { sys::igAlignTextToFramePadding() }
343 }
344}