use serde::{Deserialize, Serialize};
use super::origin::SemanticOrigin;
#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
#[cfg_attr(feature = "wasm", derive(tsify_next::Tsify))]
#[cfg_attr(feature = "wasm", tsify(into_wasm_abi, from_wasm_abi))]
pub struct OverlayState {
pub selected_index: Option<u32>,
pub filter: String,
pub scroll_offset: u32,
pub loading: bool,
}
impl OverlayState {
#[must_use]
pub const fn new() -> Self {
Self {
selected_index: None,
filter: String::new(),
scroll_offset: 0,
loading: false,
}
}
#[must_use]
pub const fn with_selection(index: u32) -> Self {
Self {
selected_index: Some(index),
filter: String::new(),
scroll_offset: 0,
loading: false,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "wasm", derive(tsify_next::Tsify))]
#[cfg_attr(feature = "wasm", tsify(into_wasm_abi, from_wasm_abi))]
pub struct LogicalOverlay {
pub id: String,
pub origin: Option<SemanticOrigin>,
pub kind: String,
pub data: serde_json::Value,
pub state: OverlayState,
pub priority: u32,
}
impl LogicalOverlay {
#[must_use]
pub fn new(id: impl Into<String>, kind: impl Into<String>) -> Self {
Self {
id: id.into(),
origin: None,
kind: kind.into(),
data: serde_json::Value::Null,
state: OverlayState::new(),
priority: 0,
}
}
#[must_use]
pub const fn with_origin(mut self, origin: SemanticOrigin) -> Self {
self.origin = Some(origin);
self
}
#[must_use]
pub fn with_data(mut self, data: serde_json::Value) -> Self {
self.data = data;
self
}
#[must_use]
pub const fn with_priority(mut self, priority: u32) -> Self {
self.priority = priority;
self
}
#[must_use]
#[cfg_attr(coverage_nightly, coverage(off))]
pub fn with_state(mut self, state: OverlayState) -> Self {
self.state = state;
self
}
}
#[cfg(test)]
#[path = "overlay_tests.rs"]
mod tests;