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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
use super::flags::{DockNodeFlags, validate_dock_node_flags};
use super::validation::{assert_finite_vec2, assert_nonzero_id};
use super::window_class::WindowClass;
use crate::ui::Ui;
use crate::{Id, sys};
use std::ptr;
/// Docking-related functionality
impl Ui {
/// Creates a dockspace over the main viewport
///
/// This is a convenience function that creates a dockspace covering the entire main viewport.
/// It's equivalent to calling `dock_space` with the main viewport's ID and size.
///
/// # Parameters
///
/// * `dockspace_id` - The ID for the dockspace (use 0 to auto-generate)
/// * `flags` - Dock node flags
///
/// # Returns
///
/// The ID of the created dockspace
///
/// # Example
///
/// ```no_run
/// # use dear_imgui_rs::*;
/// # let mut ctx = Context::create();
/// # let ui = ctx.frame();
/// let dockspace_id = ui.dockspace_over_main_viewport_with_flags(
/// 0.into(),
/// DockNodeFlags::PASSTHRU_CENTRAL_NODE
/// );
/// ```
#[doc(alias = "DockSpaceOverViewport")]
pub fn dockspace_over_main_viewport_with_flags(
&self,
dockspace_id: Id,
flags: DockNodeFlags,
) -> Id {
validate_dock_node_flags("Ui::dockspace_over_main_viewport_with_flags()", flags);
unsafe {
Id::from(sys::igDockSpaceOverViewport(
dockspace_id.into(),
sys::igGetMainViewport(),
flags.bits(),
ptr::null(),
))
}
}
/// Creates a dockspace over the main viewport with default settings
///
/// This is a convenience function that creates a dockspace covering the entire main viewport
/// with passthrough central node enabled.
///
/// # Returns
///
/// The ID of the created dockspace
///
/// # Example
///
/// ```no_run
/// # use dear_imgui_rs::*;
/// # let mut ctx = Context::create();
/// # let ui = ctx.frame();
/// let dockspace_id = ui.dockspace_over_main_viewport();
/// ```
#[doc(alias = "DockSpaceOverViewport")]
pub fn dockspace_over_main_viewport(&self) -> Id {
self.dockspace_over_main_viewport_with_flags(
Id::from(0u32),
DockNodeFlags::PASSTHRU_CENTRAL_NODE,
)
}
/// Creates a dockspace with the specified ID, size, and flags
///
/// # Parameters
///
/// * `id` - The non-zero ID for the dockspace. Use [`Ui::get_id`] to create one.
/// * `size` - The size of the dockspace in pixels
/// * `flags` - Dock node flags
/// * `window_class` - Optional window class for docking configuration
///
/// # Returns
///
/// The ID of the created dockspace
///
/// # Example
///
/// ```no_run
/// # use dear_imgui_rs::*;
/// # let mut ctx = Context::create();
/// # let ui = ctx.frame();
/// let dockspace_id = ui.get_id("MyDockspace");
/// let dockspace_id = ui.dock_space_with_class(
/// dockspace_id,
/// [800.0, 600.0],
/// DockNodeFlags::NO_DOCKING_SPLIT,
/// Some(&WindowClass::new(Id::from(1u32)))
/// );
/// ```
#[doc(alias = "DockSpace")]
pub fn dock_space_with_class(
&self,
id: Id,
size: [f32; 2],
flags: DockNodeFlags,
window_class: Option<&WindowClass>,
) -> Id {
validate_dock_node_flags("Ui::dock_space_with_class()", flags);
assert_nonzero_id("Ui::dock_space_with_class()", "id", id);
assert_finite_vec2("Ui::dock_space_with_class()", "size", size);
unsafe {
let size_vec = sys::ImVec2 {
x: size[0],
y: size[1],
};
let imgui_window_class =
window_class.map(|class| class.to_imgui("Ui::dock_space_with_class()"));
let window_class_ptr = imgui_window_class
.as_ref()
.map_or(ptr::null(), |wc| wc as *const _);
Id::from(sys::igDockSpace(
id.into(),
size_vec,
flags.bits(),
window_class_ptr,
))
}
}
/// Creates a dockspace with the specified ID and size
///
/// # Parameters
///
/// * `id` - The non-zero ID for the dockspace
/// * `size` - The size of the dockspace in pixels
///
/// # Returns
///
/// The ID of the created dockspace
///
/// # Example
///
/// ```no_run
/// # use dear_imgui_rs::*;
/// # let mut ctx = Context::create();
/// # let ui = ctx.frame();
/// let dockspace_id = ui.get_id("MyDockspace");
/// let dockspace_id = ui.dock_space(dockspace_id, [800.0, 600.0]);
/// ```
#[doc(alias = "DockSpace")]
pub fn dock_space(&self, id: Id, size: [f32; 2]) -> Id {
self.dock_space_with_class(id, size, DockNodeFlags::NONE, None)
}
/// Sets the dock ID for the next window with condition
///
/// This function must be called before creating a window to dock it to a specific dock node.
///
/// # Parameters
///
/// * `dock_id` - The ID of the dock node to dock the next window to
/// * `cond` - Condition for when to apply the docking
///
/// # Example
///
/// ```no_run
/// # use dear_imgui_rs::*;
/// # let mut ctx = Context::create();
/// # let ui = ctx.frame();
/// let dockspace_id = ui.dockspace_over_main_viewport();
/// ui.set_next_window_dock_id_with_cond(dockspace_id, Condition::FirstUseEver);
/// ui.window("Docked Window").build(|| {
/// ui.text("This window will be docked!");
/// });
/// ```
#[doc(alias = "SetNextWindowDockID")]
pub fn set_next_window_dock_id_with_cond(&self, dock_id: Id, cond: crate::Condition) {
unsafe {
sys::igSetNextWindowDockID(dock_id.into(), cond as i32);
}
}
/// Sets the dock ID for the next window
///
/// This function must be called before creating a window to dock it to a specific dock node.
/// Uses `Condition::Always` by default.
///
/// # Parameters
///
/// * `dock_id` - The ID of the dock node to dock the next window to
///
/// # Example
///
/// ```no_run
/// # use dear_imgui_rs::*;
/// # let mut ctx = Context::create();
/// # let ui = ctx.frame();
/// let dockspace_id = ui.dockspace_over_main_viewport();
/// ui.set_next_window_dock_id(dockspace_id);
/// ui.window("Docked Window").build(|| {
/// ui.text("This window will be docked!");
/// });
/// ```
#[doc(alias = "SetNextWindowDockID")]
pub fn set_next_window_dock_id(&self, dock_id: Id) {
self.set_next_window_dock_id_with_cond(dock_id, crate::Condition::Always)
}
/// Sets the window class for the next window
///
/// This function must be called before creating a window to apply the window class configuration.
///
/// # Parameters
///
/// * `window_class` - The window class configuration
///
/// # Example
///
/// ```no_run
/// # use dear_imgui_rs::*;
/// # let mut ctx = Context::create();
/// # let ui = ctx.frame();
/// let window_class = WindowClass::new(Id::from(1u32)).docking_always_tab_bar(true);
/// ui.set_next_window_class(&window_class);
/// ui.window("Classed Window").build(|| {
/// ui.text("This window has a custom class!");
/// });
/// ```
#[doc(alias = "SetNextWindowClass")]
pub fn set_next_window_class(&self, window_class: &WindowClass) {
unsafe {
let imgui_wc = window_class.to_imgui("Ui::set_next_window_class()");
sys::igSetNextWindowClass(&imgui_wc as *const _);
}
}
/// Gets the dock ID of the current window
///
/// # Returns
///
/// The dock ID of the current window, or 0 if the window is not docked
///
/// # Example
///
/// ```no_run
/// # use dear_imgui_rs::*;
/// # let mut ctx = Context::create();
/// # let ui = ctx.frame();
/// ui.window("My Window").build(|| {
/// let dock_id = ui.get_window_dock_id();
/// if dock_id != 0.into() {
/// ui.text(format!("This window is docked with ID: {}", dock_id.raw()));
/// } else {
/// ui.text("This window is not docked");
/// }
/// });
/// ```
#[doc(alias = "GetWindowDockID")]
pub fn get_window_dock_id(&self) -> Id {
unsafe { Id::from(sys::igGetWindowDockID()) }
}
/// Checks if the current window is docked
///
/// # Returns
///
/// `true` if the current window is docked, `false` otherwise
///
/// # Example
///
/// ```no_run
/// # use dear_imgui_rs::*;
/// # let mut ctx = Context::create();
/// # let ui = ctx.frame();
/// ui.window("My Window").build(|| {
/// if ui.is_window_docked() {
/// ui.text("This window is docked!");
/// } else {
/// ui.text("This window is floating");
/// }
/// });
/// ```
#[doc(alias = "IsWindowDocked")]
pub fn is_window_docked(&self) -> bool {
unsafe { sys::igIsWindowDocked() }
}
}