#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct OldColumnIndex(usize);
impl OldColumnIndex {
pub const ZERO: Self = Self(0);
#[inline]
pub const fn new(index: usize) -> Self {
Self(index)
}
#[inline]
pub const fn get(self) -> usize {
self.0
}
#[inline]
pub(super) fn into_i32(self, caller: &str) -> i32 {
i32::try_from(self.0).unwrap_or_else(|_| {
panic!("{caller} column index exceeded Dear ImGui's i32 range");
})
}
#[inline]
pub(super) fn from_i32(raw: i32, caller: &str) -> Self {
assert!(raw >= 0, "{caller} returned a negative column index");
Self(usize::try_from(raw).expect("non-negative column index must fit usize"))
}
}
impl From<usize> for OldColumnIndex {
#[inline]
fn from(index: usize) -> Self {
Self::new(index)
}
}
impl From<OldColumnIndex> for usize {
#[inline]
fn from(index: OldColumnIndex) -> Self {
index.get()
}
}
impl PartialEq<usize> for OldColumnIndex {
#[inline]
fn eq(&self, other: &usize) -> bool {
self.get() == *other
}
}
impl PartialEq<OldColumnIndex> for usize {
#[inline]
fn eq(&self, other: &OldColumnIndex) -> bool {
*self == other.get()
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum OldColumnRef {
#[default]
Current,
Index(OldColumnIndex),
}
impl OldColumnRef {
pub const CURRENT: Self = Self::Current;
#[inline]
pub const fn index(index: OldColumnIndex) -> Self {
Self::Index(index)
}
}
impl From<OldColumnIndex> for OldColumnRef {
#[inline]
fn from(index: OldColumnIndex) -> Self {
Self::Index(index)
}
}
impl From<usize> for OldColumnRef {
#[inline]
fn from(index: usize) -> Self {
Self::Index(OldColumnIndex::new(index))
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum OldColumnOffsetRef {
#[default]
Current,
Column(OldColumnIndex),
Trailing,
}
impl OldColumnOffsetRef {
pub const CURRENT: Self = Self::Current;
pub const TRAILING: Self = Self::Trailing;
#[inline]
pub const fn column(index: OldColumnIndex) -> Self {
Self::Column(index)
}
}
impl From<OldColumnIndex> for OldColumnOffsetRef {
#[inline]
fn from(index: OldColumnIndex) -> Self {
Self::Column(index)
}
}
impl From<usize> for OldColumnOffsetRef {
#[inline]
fn from(index: usize) -> Self {
Self::Column(OldColumnIndex::new(index))
}
}