use thiserror::Error;
pub type LayoutResult<T> = Result<T, LayoutError>;
#[derive(Debug, Error)]
pub enum LayoutError {
#[error("Element not registered: {0}")]
ElementNotFound(ElementId),
#[error("Element already registered: {0}")]
ElementAlreadyRegistered(ElementId),
#[error("Invalid layout region: {0}")]
InvalidRegion(String),
#[error("Layout computation failed: {0}")]
LayoutComputation(String),
#[error("Focus error: {0}")]
Focus(String),
#[error("Event routing error: {0}")]
EventRouting(String),
#[error("Mouse capture error: {0}")]
MouseCapture(String),
#[error("Terminal too small: minimum {0}x{1}, got {2}x{3}")]
TerminalTooSmall(u16, u16, u16, u16),
}
impl LayoutError {
pub fn element_not_found(id: ElementId) -> Self {
Self::ElementNotFound(id)
}
pub fn element_already_registered(id: ElementId) -> Self {
Self::ElementAlreadyRegistered(id)
}
pub fn invalid_region(msg: impl Into<String>) -> Self {
Self::InvalidRegion(msg.into())
}
pub fn layout_computation(msg: impl Into<String>) -> Self {
Self::LayoutComputation(msg.into())
}
pub fn focus(msg: impl Into<String>) -> Self {
Self::Focus(msg.into())
}
pub fn event_routing(msg: impl Into<String>) -> Self {
Self::EventRouting(msg.into())
}
pub fn mouse_capture(msg: impl Into<String>) -> Self {
Self::MouseCapture(msg.into())
}
pub fn terminal_too_small(min_width: u16, min_height: u16, width: u16, height: u16) -> Self {
Self::TerminalTooSmall(min_width, min_height, width, height)
}
}
use crate::types::ElementId;