Skip to main content

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