dear_imgui_rs/columns/
index.rs1#[cfg(feature = "serde")]
2use serde::{Deserialize, Serialize};
3
4#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
9#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10pub struct OldColumnIndex(usize);
11
12impl OldColumnIndex {
13 pub const ZERO: Self = Self(0);
15
16 #[inline]
18 pub const fn new(index: usize) -> Self {
19 Self(index)
20 }
21
22 #[inline]
24 pub const fn get(self) -> usize {
25 self.0
26 }
27
28 #[inline]
29 pub(super) fn into_i32(self, caller: &str) -> i32 {
30 i32::try_from(self.0).unwrap_or_else(|_| {
31 panic!("{caller} column index exceeded Dear ImGui's i32 range");
32 })
33 }
34
35 #[inline]
36 pub(super) fn from_i32(raw: i32, caller: &str) -> Self {
37 assert!(raw >= 0, "{caller} returned a negative column index");
38 Self(usize::try_from(raw).expect("non-negative column index must fit usize"))
39 }
40}
41
42impl From<usize> for OldColumnIndex {
43 #[inline]
44 fn from(index: usize) -> Self {
45 Self::new(index)
46 }
47}
48
49impl From<OldColumnIndex> for usize {
50 #[inline]
51 fn from(index: OldColumnIndex) -> Self {
52 index.get()
53 }
54}
55
56impl PartialEq<usize> for OldColumnIndex {
57 #[inline]
58 fn eq(&self, other: &usize) -> bool {
59 self.get() == *other
60 }
61}
62
63impl PartialEq<OldColumnIndex> for usize {
64 #[inline]
65 fn eq(&self, other: &OldColumnIndex) -> bool {
66 *self == other.get()
67 }
68}
69
70#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
72#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
73pub enum OldColumnRef {
74 #[default]
76 Current,
77 Index(OldColumnIndex),
79}
80
81impl OldColumnRef {
82 pub const CURRENT: Self = Self::Current;
84
85 #[inline]
87 pub const fn index(index: OldColumnIndex) -> Self {
88 Self::Index(index)
89 }
90}
91
92impl From<OldColumnIndex> for OldColumnRef {
93 #[inline]
94 fn from(index: OldColumnIndex) -> Self {
95 Self::Index(index)
96 }
97}
98
99impl From<usize> for OldColumnRef {
100 #[inline]
101 fn from(index: usize) -> Self {
102 Self::Index(OldColumnIndex::new(index))
103 }
104}
105
106#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
112#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
113pub enum OldColumnOffsetRef {
114 #[default]
116 Current,
117 Column(OldColumnIndex),
119 Trailing,
121}
122
123impl OldColumnOffsetRef {
124 pub const CURRENT: Self = Self::Current;
126
127 pub const TRAILING: Self = Self::Trailing;
129
130 #[inline]
132 pub const fn column(index: OldColumnIndex) -> Self {
133 Self::Column(index)
134 }
135}
136
137impl From<OldColumnIndex> for OldColumnOffsetRef {
138 #[inline]
139 fn from(index: OldColumnIndex) -> Self {
140 Self::Column(index)
141 }
142}
143
144impl From<usize> for OldColumnOffsetRef {
145 #[inline]
146 fn from(index: usize) -> Self {
147 Self::Column(OldColumnIndex::new(index))
148 }
149}