use crate::element::ElementId;
use bevy::prelude::{Entity, Event};
use smol_str::SmolStr;
use std::fmt::{Debug, Formatter};
use std::hash::Hash;
#[derive(Clone, Debug, Hash, PartialEq, Eq, Event)]
pub struct SpawnPage {
pub name: SmolStr,
}
#[derive(Clone, Debug, Hash, PartialEq, Eq, Event)]
pub struct DespawnPage {
pub name: SmolStr,
}
#[derive(Clone, Debug, Hash, PartialEq, Eq, Event)]
pub struct ActivatePage {
pub name: SmolStr,
}
#[derive(Clone, Debug, Hash, PartialEq, Eq, Event)]
pub struct DeactivatePage {
pub name: SmolStr,
}
#[derive(Clone, PartialEq, Eq, Debug, Hash, Event)]
pub struct ElementClick {
pub entity: Entity,
pub id: Option<ElementId>,
}
impl ElementClick {
#[inline(always)]
pub fn matches_id<Q>(&self, id: &Q) -> bool
where
Q: ?Sized,
ElementId: PartialEq<Q>,
{
self.id.as_ref().is_some_and(|i| i == id)
}
}
#[derive(Clone, PartialEq, Eq, Debug, Hash, Event)]
pub struct ElementHover {
pub entity: Entity,
pub id: Option<ElementId>,
}
impl ElementHover {
#[inline(always)]
pub fn matches_id<Q>(&self, id: &Q) -> bool
where
Q: ?Sized,
ElementId: PartialEq<Q>,
{
self.id.as_ref().is_some_and(|i| i == id)
}
}
#[derive(Clone, PartialEq, Eq, Debug, Hash, Event)]
pub struct ElementSpawn {
pub entity: Entity,
pub id: Option<ElementId>,
}
impl ElementSpawn {
#[inline(always)]
pub fn matches_id<Q>(&self, id: &Q) -> bool
where
Q: ?Sized,
ElementId: PartialEq<Q>,
{
self.id.as_ref().is_some_and(|i| i == id)
}
}
#[derive(Clone, PartialEq, Eq, Debug, Hash, Event)]
pub struct ElementToggle {
pub entity: Entity,
pub id: Option<ElementId>,
pub state: bool,
}
impl ElementToggle {
#[inline(always)]
pub fn matches_id<Q>(&self, id: &Q) -> bool
where
Q: ?Sized,
ElementId: PartialEq<Q>,
{
self.id.as_ref().is_some_and(|i| i == id)
}
}
#[derive(Event)]
pub struct ElementSet<T> {
pub entity: Entity,
pub id: Option<ElementId>,
pub value: T,
pub delta: Option<T>,
}
impl<T> ElementSet<T> {
#[inline(always)]
pub fn matches_id<Q>(&self, id: &Q) -> bool
where
Q: ?Sized,
ElementId: PartialEq<Q>,
{
self.id.as_ref().is_some_and(|i| i == id)
}
}
impl<T: Clone> Clone for ElementSet<T> {
#[inline(always)]
fn clone(&self) -> Self {
Self {
entity: self.entity,
id: self.id.clone(),
value: self.value.clone(),
delta: self.delta.clone(),
}
}
}
impl<T: Debug> Debug for ElementSet<T> {
#[inline(always)]
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ElementSet")
.field("entity", &self.entity)
.field("id", &self.id)
.field("value", &self.value)
.field("delta", &self.delta)
.finish()
}
}
impl<T: Hash> Hash for ElementSet<T> {
#[inline(always)]
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.entity.hash(state);
self.id.hash(state);
self.value.hash(state);
self.delta.hash(state);
}
}
impl<T: PartialEq> PartialEq for ElementSet<T> {
#[inline(always)]
fn eq(&self, other: &Self) -> bool {
self.entity == other.entity
&& self.id == other.id
&& self.value == other.value
&& self.delta == other.delta
}
}
impl<T: Eq> Eq for ElementSet<T> {}