Skip to main content

dear_imgui_rs/widget/table/
tokens.rs

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