Skip to main content

dear_imgui_rs/widget/menu/
tokens.rs

1use crate::sys;
2use crate::ui::Ui;
3
4/// Tracks a main menu bar that can be ended by calling `.end()` or by dropping
5#[must_use]
6pub struct MainMenuBarToken<'ui> {
7    _ui: &'ui Ui,
8}
9
10impl<'ui> MainMenuBarToken<'ui> {
11    /// Creates a new main menu bar token
12    pub(super) fn new(ui: &'ui Ui) -> Self {
13        MainMenuBarToken { _ui: ui }
14    }
15
16    /// Ends the main menu bar
17    pub fn end(self) {
18        // The drop implementation will handle the actual ending
19    }
20}
21
22impl Drop for MainMenuBarToken<'_> {
23    fn drop(&mut self) {
24        self._ui
25            .run_with_bound_context(|| unsafe { sys::igEndMainMenuBar() });
26    }
27}
28
29/// Tracks a menu bar that can be ended by calling `.end()` or by dropping
30#[must_use]
31pub struct MenuBarToken<'ui> {
32    _ui: &'ui Ui,
33}
34
35impl<'ui> MenuBarToken<'ui> {
36    /// Creates a new menu bar token
37    pub(super) fn new(ui: &'ui Ui) -> Self {
38        MenuBarToken { _ui: ui }
39    }
40
41    /// Ends the menu bar
42    pub fn end(self) {
43        // The drop implementation will handle the actual ending
44    }
45}
46
47impl Drop for MenuBarToken<'_> {
48    fn drop(&mut self) {
49        self._ui
50            .run_with_bound_context(|| unsafe { sys::igEndMenuBar() });
51    }
52}
53
54/// Tracks a menu that can be ended by calling `.end()` or by dropping
55#[must_use]
56pub struct MenuToken<'ui> {
57    _ui: &'ui Ui,
58}
59
60impl<'ui> MenuToken<'ui> {
61    /// Creates a new menu token
62    pub(super) fn new(ui: &'ui Ui) -> Self {
63        MenuToken { _ui: ui }
64    }
65
66    /// Ends the menu
67    pub fn end(self) {
68        // The drop implementation will handle the actual ending
69    }
70}
71
72impl Drop for MenuToken<'_> {
73    fn drop(&mut self) {
74        self._ui
75            .run_with_bound_context(|| unsafe { sys::igEndMenu() });
76    }
77}