Skip to main content

dear_imgui_rs/widget/table/
setup.rs

1use crate::Id;
2
3use super::{TableColumnFlags, TableColumnIndent, TableColumnWidth, assert_explicit_user_id};
4
5/// Table column setup information
6#[derive(Clone, Debug)]
7pub struct TableColumnSetup<Name> {
8    pub name: Name,
9    pub flags: TableColumnFlags,
10    pub width: Option<TableColumnWidth>,
11    pub indent: Option<TableColumnIndent>,
12    pub user_id: Option<Id>,
13}
14
15impl<Name> TableColumnSetup<Name> {
16    /// Creates a new table column setup
17    pub fn new(name: Name) -> Self {
18        Self {
19            name,
20            flags: TableColumnFlags::NONE,
21            width: None,
22            indent: None,
23            user_id: None,
24        }
25    }
26
27    /// Sets the column flags
28    pub fn flags(mut self, flags: TableColumnFlags) -> Self {
29        self.flags = flags;
30        self
31    }
32
33    /// Sets a fixed initial column width in pixels.
34    pub fn fixed_width(mut self, width: f32) -> Self {
35        self.width = Some(TableColumnWidth::Fixed(width));
36        self
37    }
38
39    /// Sets an initial stretch weight for this column.
40    pub fn stretch_weight(mut self, weight: f32) -> Self {
41        self.width = Some(TableColumnWidth::Stretch(weight));
42        self
43    }
44
45    /// Sets this column's indentation policy.
46    pub fn indent(mut self, indent: TableColumnIndent) -> Self {
47        self.indent = Some(indent);
48        self
49    }
50
51    /// Enables or disables indentation for this column.
52    pub fn indent_enabled(mut self, enabled: bool) -> Self {
53        self.indent = Some(if enabled {
54            TableColumnIndent::Enable
55        } else {
56            TableColumnIndent::Disable
57        });
58        self
59    }
60
61    /// Sets the user ID
62    pub fn user_id(mut self, id: Id) -> Self {
63        self.user_id = Some(assert_explicit_user_id(id, "TableColumnSetup::user_id()"));
64        self
65    }
66}