use egui::{Context, Id, LayerId, Order, Rect};
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ParticleLayer {
Background,
Foreground,
Top,
}
impl ParticleLayer {
pub fn to_str(&self) -> &str {
match self {
ParticleLayer::Background => "Background",
ParticleLayer::Foreground => "Foreground",
ParticleLayer::Top => "Top",
}
}
}
pub(crate) fn resolve_target(
ctx: &Context,
id: Id,
order: Order,
custom_layer: Option<LayerId>,
custom_area: Option<Rect>,
) -> Option<(LayerId, Rect)> {
let area = custom_area.unwrap_or_else(|| ctx.content_rect());
if area.width() <= 0.0 || area.height() <= 0.0 {
return None;
}
let layer_id = custom_layer.unwrap_or_else(|| LayerId::new(order, id));
Some((layer_id, area))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn particle_layer_to_str() {
assert_eq!(ParticleLayer::Background.to_str(), "Background");
assert_eq!(ParticleLayer::Foreground.to_str(), "Foreground");
assert_eq!(ParticleLayer::Top.to_str(), "Top");
}
}