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 let pos = unsafe { sys::igGetCursorPos() };
175 [pos.x, pos.y]
176 }
177
178 #[doc(alias = "GetCursorScreenPos")]
180 pub fn cursor_screen_pos(&self) -> [f32; 2] {
181 let pos = unsafe { sys::igGetCursorScreenPos() };
182 [pos.x, pos.y]
183 }
184
185 #[doc(alias = "SetCursorPos")]
187 pub fn set_cursor_pos(&self, pos: impl Into<[f32; 2]>) {
188 let pos_array = pos.into();
189 let pos_vec = sys::ImVec2 {
190 x: pos_array[0],
191 y: pos_array[1],
192 };
193 unsafe { sys::igSetCursorPos(pos_vec) };
194 }
195
196 #[doc(alias = "SetCursorScreenPos")]
198 pub fn set_cursor_screen_pos(&self, pos: impl Into<[f32; 2]>) {
199 let pos_array = pos.into();
200 let pos_vec = sys::ImVec2 {
201 x: pos_array[0],
202 y: pos_array[1],
203 };
204 unsafe { sys::igSetCursorScreenPos(pos_vec) };
205 }
206
207 #[doc(alias = "GetCursorPosX")]
209 pub fn cursor_pos_x(&self) -> f32 {
210 unsafe { sys::igGetCursorPosX() }
211 }
212
213 #[doc(alias = "GetCursorPosY")]
215 pub fn cursor_pos_y(&self) -> f32 {
216 unsafe { sys::igGetCursorPosY() }
217 }
218
219 #[doc(alias = "SetCursorPosX")]
221 pub fn set_cursor_pos_x(&self, x: f32) {
222 unsafe { sys::igSetCursorPosX(x) };
223 }
224
225 #[doc(alias = "SetCursorPosY")]
227 pub fn set_cursor_pos_y(&self, y: f32) {
228 unsafe { sys::igSetCursorPosY(y) };
229 }
230
231 #[doc(alias = "GetCursorStartPos")]
233 pub fn cursor_start_pos(&self) -> [f32; 2] {
234 let pos = unsafe { sys::igGetCursorStartPos() };
235 [pos.x, pos.y]
236 }
237}
238
239impl Ui {
244 #[doc(alias = "GetTextLineHeight")]
246 pub fn text_line_height(&self) -> f32 {
247 unsafe { sys::igGetTextLineHeight() }
248 }
249
250 #[doc(alias = "GetTextLineHeightWithSpacing")]
252 pub fn text_line_height_with_spacing(&self) -> f32 {
253 unsafe { sys::igGetTextLineHeightWithSpacing() }
254 }
255
256 #[doc(alias = "GetFrameHeight")]
258 pub fn frame_height(&self) -> f32 {
259 unsafe { sys::igGetFrameHeight() }
260 }
261
262 #[doc(alias = "GetFrameHeightWithSpacing")]
264 pub fn frame_height_with_spacing(&self) -> f32 {
265 unsafe { sys::igGetFrameHeightWithSpacing() }
266 }
267
268 #[doc(alias = "PushClipRect")]
270 pub fn push_clip_rect(
271 &self,
272 min: impl Into<[f32; 2]>,
273 max: impl Into<[f32; 2]>,
274 intersect_with_current: bool,
275 ) {
276 let min = min.into();
277 let max = max.into();
278 let min_v = sys::ImVec2 {
279 x: min[0],
280 y: min[1],
281 };
282 let max_v = sys::ImVec2 {
283 x: max[0],
284 y: max[1],
285 };
286 unsafe { sys::igPushClipRect(min_v, max_v, intersect_with_current) }
287 }
288
289 #[doc(alias = "PopClipRect")]
291 pub fn pop_clip_rect(&self) {
292 unsafe { sys::igPopClipRect() }
293 }
294
295 pub fn with_clip_rect<R>(
297 &self,
298 min: impl Into<[f32; 2]>,
299 max: impl Into<[f32; 2]>,
300 intersect_with_current: bool,
301 f: impl FnOnce() -> R,
302 ) -> R {
303 self.push_clip_rect(min, max, intersect_with_current);
304 let _t = ClipRectToken::new(self);
305 f()
306 }
307
308 #[doc(alias = "IsRectVisible")]
310 pub fn is_rect_visible_min_max(
311 &self,
312 rect_min: impl Into<[f32; 2]>,
313 rect_max: impl Into<[f32; 2]>,
314 ) -> bool {
315 let mn = rect_min.into();
316 let mx = rect_max.into();
317 let mn_v = sys::ImVec2 { x: mn[0], y: mn[1] };
318 let mx_v = sys::ImVec2 { x: mx[0], y: mx[1] };
319 unsafe { sys::igIsRectVisible_Vec2(mn_v, mx_v) }
320 }
321
322 #[doc(alias = "IsRectVisible")]
324 pub fn is_rect_visible_with_size(&self, size: impl Into<[f32; 2]>) -> bool {
325 let s = size.into();
326 let v = sys::ImVec2 { x: s[0], y: s[1] };
327 unsafe { sys::igIsRectVisible_Nil(v) }
328 }
329
330 #[doc(alias = "AlignTextToFramePadding")]
332 pub fn align_text_to_frame_padding(&self) {
333 unsafe { sys::igAlignTextToFramePadding() }
334 }
335}