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