dear_imgui_rs/widget/table/
setup.rs1use super::{TableColumnFlags, TableColumnIndent, TableColumnWidth};
2
3#[repr(transparent)]
8#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
9pub struct TableColumnUserData(u32);
10
11impl TableColumnUserData {
12 #[inline]
14 pub const fn new(value: u32) -> Self {
15 Self(value)
16 }
17
18 #[inline]
20 pub const fn get(self) -> u32 {
21 self.0
22 }
23}
24
25impl From<u32> for TableColumnUserData {
26 #[inline]
27 fn from(value: u32) -> Self {
28 Self::new(value)
29 }
30}
31
32impl From<TableColumnUserData> for u32 {
33 #[inline]
34 fn from(value: TableColumnUserData) -> Self {
35 value.get()
36 }
37}
38
39#[derive(Clone, Debug)]
41pub struct TableColumnSetup<Name> {
42 pub name: Name,
43 pub flags: TableColumnFlags,
44 pub width: Option<TableColumnWidth>,
45 pub indent: Option<TableColumnIndent>,
46 pub user_data: TableColumnUserData,
47}
48
49impl<Name> TableColumnSetup<Name> {
50 pub fn new(name: Name) -> Self {
52 Self {
53 name,
54 flags: TableColumnFlags::NONE,
55 width: None,
56 indent: None,
57 user_data: TableColumnUserData::default(),
58 }
59 }
60
61 pub fn flags(mut self, flags: TableColumnFlags) -> Self {
63 self.flags = flags;
64 self
65 }
66
67 pub fn fixed_width(mut self, width: f32) -> Self {
69 self.width = Some(TableColumnWidth::Fixed(width));
70 self
71 }
72
73 pub fn stretch_weight(mut self, weight: f32) -> Self {
75 self.width = Some(TableColumnWidth::Stretch(weight));
76 self
77 }
78
79 pub fn indent(mut self, indent: TableColumnIndent) -> Self {
81 self.indent = Some(indent);
82 self
83 }
84
85 pub fn indent_enabled(mut self, enabled: bool) -> Self {
87 self.indent = Some(if enabled {
88 TableColumnIndent::Enable
89 } else {
90 TableColumnIndent::Disable
91 });
92 self
93 }
94
95 pub fn user_data(mut self, user_data: impl Into<TableColumnUserData>) -> Self {
108 self.user_data = user_data.into();
109 self
110 }
111
112 pub(crate) fn map_name<M>(self, map: impl FnOnce(Name) -> M) -> TableColumnSetup<M> {
113 TableColumnSetup {
114 name: map(self.name),
115 flags: self.flags,
116 width: self.width,
117 indent: self.indent,
118 user_data: self.user_data,
119 }
120 }
121}