1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
use std::ptr;
use std::thread;
use crate::context::Context;
use crate::sys;
use crate::Ui;
#[must_use]
pub struct GroupToken {
ctx: *const Context,
}
impl GroupToken {
pub fn end(mut self, _: &Ui) {
self.ctx = ptr::null();
unsafe { sys::igEndGroup() };
}
}
impl Drop for GroupToken {
fn drop(&mut self) {
if !self.ctx.is_null() && !thread::panicking() {
panic!("A GroupToken was leaked. Did you call .end()?");
}
}
}
impl<'ui> Ui<'ui> {
pub fn separator(&self) {
unsafe { sys::igSeparator() }
}
pub fn same_line(&self, pos_x: f32) {
unsafe { sys::igSameLine(pos_x, -1.0f32) }
}
pub fn same_line_with_spacing(&self, pos_x: f32, spacing_w: f32) {
unsafe { sys::igSameLine(pos_x, spacing_w) }
}
pub fn new_line(&self) {
unsafe { sys::igNewLine() }
}
pub fn spacing(&self) {
unsafe { sys::igSpacing() }
}
pub fn dummy(&self, size: [f32; 2]) {
unsafe { sys::igDummy(size.into()) }
}
pub fn indent(&self) {
unsafe { sys::igIndent(0.0) };
}
pub fn indent_by(&self, width: f32) {
unsafe { sys::igIndent(width) };
}
pub fn unindent(&self) {
unsafe { sys::igUnindent(0.0) };
}
pub fn unindent_by(&self, width: f32) {
unsafe { sys::igUnindent(width) };
}
#[must_use]
pub fn begin_group(&self) -> GroupToken {
unsafe { sys::igBeginGroup() };
GroupToken { ctx: self.ctx }
}
pub fn group<R, F: FnOnce() -> R>(&self, f: F) -> R {
let group = self.begin_group();
let result = f();
group.end(self);
result
}
pub fn cursor_pos(&self) -> [f32; 2] {
unsafe { sys::igGetCursorPos_nonUDT2().into() }
}
pub fn set_cursor_pos(&self, pos: [f32; 2]) {
unsafe { sys::igSetCursorPos(pos.into()) };
}
pub fn cursor_start_pos(&self) -> [f32; 2] {
unsafe { sys::igGetCursorStartPos_nonUDT2().into() }
}
pub fn cursor_screen_pos(&self) -> [f32; 2] {
unsafe { sys::igGetCursorScreenPos_nonUDT2().into() }
}
pub fn set_cursor_screen_pos(&self, pos: [f32; 2]) {
unsafe { sys::igSetCursorScreenPos(pos.into()) }
}
pub fn align_text_to_frame_padding(&self) {
unsafe { sys::igAlignTextToFramePadding() };
}
pub fn text_line_height(&self) -> f32 {
unsafe { sys::igGetTextLineHeight() }
}
pub fn text_line_height_with_spacing(&self) -> f32 {
unsafe { sys::igGetTextLineHeightWithSpacing() }
}
pub fn frame_height(&self) -> f32 {
unsafe { sys::igGetFrameHeight() }
}
pub fn frame_height_with_spacing(&self) -> f32 {
unsafe { sys::igGetFrameHeightWithSpacing() }
}
}