use crate::{Container, ContainerKind};
#[derive(Clone, Copy, Hash, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct TileId(pub u64);
impl TileId {
#[inline]
pub fn from_u64(n: u64) -> Self {
Self(n)
}
pub fn egui_id(&self, tree_id: egui::Id) -> egui::Id {
tree_id.with(("tile", self))
}
}
impl std::fmt::Debug for TileId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "#{}", self.0)
}
}
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub enum Tile<Pane> {
Pane(Pane),
Container(Container),
}
impl<T> From<Container> for Tile<T> {
#[inline]
fn from(container: Container) -> Self {
Self::Container(container)
}
}
impl<Pane> Tile<Pane> {
#[inline]
pub fn kind(&self) -> Option<ContainerKind> {
match self {
Tile::Pane(_) => None,
Tile::Container(container) => Some(container.kind()),
}
}
#[inline]
pub fn is_pane(&self) -> bool {
matches!(self, Self::Pane(_))
}
#[inline]
pub fn is_container(&self) -> bool {
matches!(self, Self::Container(_))
}
#[inline]
pub fn container_kind(&self) -> Option<ContainerKind> {
match self {
Self::Pane(_) => None,
Self::Container(container) => Some(container.kind()),
}
}
}