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        unsafe {
25            sys::igEndTable();
26        }
27    }
28}
29
30/// Tracks a pushed table background draw channel.
31#[must_use = "dropping the token pops the table background draw channel immediately"]
32pub struct TableBackgroundChannelToken<'ui> {
33    _ui: &'ui Ui,
34}
35
36impl<'ui> TableBackgroundChannelToken<'ui> {
37    pub(crate) fn new(ui: &'ui Ui) -> Self {
38        Self { _ui: ui }
39    }
40
41    /// Pops the table background draw channel.
42    pub fn pop(self) {}
43
44    /// Pops the table background draw channel.
45    pub fn end(self) {}
46}
47
48impl Drop for TableBackgroundChannelToken<'_> {
49    fn drop(&mut self) {
50        unsafe {
51            sys::igTablePopBackgroundChannel();
52        }
53    }
54}
55
56/// Tracks a pushed table column draw channel.
57#[must_use = "dropping the token pops the table column draw channel immediately"]
58pub struct TableColumnChannelToken<'ui> {
59    _ui: &'ui Ui,
60}
61
62impl<'ui> TableColumnChannelToken<'ui> {
63    pub(crate) fn new(ui: &'ui Ui) -> Self {
64        Self { _ui: ui }
65    }
66
67    /// Pops the table column draw channel.
68    pub fn pop(self) {}
69
70    /// Pops the table column draw channel.
71    pub fn end(self) {}
72}
73
74impl Drop for TableColumnChannelToken<'_> {
75    fn drop(&mut self) {
76        unsafe {
77            sys::igTablePopColumnChannel();
78        }
79    }
80}