dear_imgui_rs/layout/group.rs
1use crate::Ui;
2use crate::sys;
3
4create_token!(
5 /// Tracks a layout group that can be ended with `end` or by dropping.
6 #[doc(alias = "EndGroup")]
7 pub struct GroupToken<'ui>;
8
9 /// Drops the layout group manually. You can also just allow this token
10 /// to drop on its own.
11 drop { unsafe { sys::igEndGroup() } }
12);
13
14impl Ui {
15 /// Creates a layout group and starts appending to it.
16 ///
17 /// Returns a `GroupToken` that must be ended by calling `.end()`.
18 #[doc(alias = "BeginGroup")]
19 pub fn begin_group(&self) -> GroupToken<'_> {
20 self.run_with_bound_context(|| unsafe { sys::igBeginGroup() });
21 GroupToken::new(self)
22 }
23
24 /// Creates a layout group and runs a closure to construct the contents.
25 ///
26 /// May be useful to handle the same mouse event on a group of items, for example.
27 #[doc(alias = "BeginGroup")]
28 pub fn group<R, F: FnOnce() -> R>(&self, f: F) -> R {
29 let group = self.begin_group();
30 let result = f();
31 group.end();
32 result
33 }
34}