appcui 0.5.1

A feature-rich and cross-platform TUI/CUI framework for Rust, enabling modern terminal-based applications on Windows, Linux, and macOS. Includes built-in UI components like buttons, menus, list views, tree views, checkboxes, and more. Perfect for building fast and interactive CLI tools and text-based interfaces.
Documentation
use std::fmt::*;

#[derive(Debug,Eq,PartialEq)]
/// A layout construction error caused by conflicting or incomplete parameters.
///
/// [`super::LayoutBuilder::build`] returns this when dock, align, pivot, anchors, and
/// size cannot be combined. Each variant describes one invalid combination.
pub enum Error {
    /// `x`/`y` cannot be combined with `dock`.
    XYParameterUsedWithDock,
    /// Anchors cannot be combined with `dock`.
    AnchorParameterUsedWithDock,
    /// `pivot` cannot be combined with `dock`.
    PivotParameterUsedWithDock,
    /// `align` cannot be combined with `dock`.
    AlignParameterUsedWithDock,
    /// `width` is implied by `Dock::Top` / `Dock::Bottom`.
    WidthParameterUsedWithTopOrBottomDock,
    /// `height` is implied by `Dock::Left` / `Dock::Right`.
    HeightParameterUsedWithLeftOrRightDock,
    /// `width`/`height` are implied by `Dock::Fill`.
    WidthOrHeightParameterUsedWithDockFill,
    /// `x`/`y` cannot be combined with `align`.
    XYParameterUsedWithAlign,
    /// Anchors cannot be combined with `align`.
    AnchorParameterUsedWithAlign,
    /// `pivot` cannot be combined with `align`.
    PivotParameterUsedWithAlign,
    /// `dock` cannot be combined with `align`.
    DockParameterUsedWithAlign,
    /// Anchors cannot be combined with absolute `x`/`y`.
    AnchorParameterUsedWithXY,
    /// A corner anchor already implies `x`/`y`.
    CornerAnchorParameterUsedWithXY,
    /// A corner anchor already implies `pivot`.
    CornerAnchorParameterUsedWithPivot,
    /// All four anchors already imply `x`/`y`.
    AllAnchorsParameterUsedWithXY,
    /// All four anchors already imply `width`/`height`.
    AllAnchorsParameterUsedWithSize,
    /// All four anchors already imply `pivot`.
    AllAnchorsParameterUsedWithPivot,
    /// Left+top+right anchors already imply `x`/`y`.
    LeftTopRightAnchorsUsedWithXY,
    /// Left+top+right anchors already imply `width`.
    LeftTopRightAnchorsUsedWithWidth,
    /// Left+top+right anchors already imply `pivot`.
    LeftTopRightAnchorsUsedWithPivot,
    /// Left+right anchors already imply `x`.
    LeftRightAnchorsUsedWithX,
    /// Left+right anchors already imply `width`.
    LeftRightAnchorsUsedWithWidth,
    /// Left+right anchors require a `pivot`.
    LeftRightAnchorsUsedWithoutPivot,
    /// Left+right anchors require `y`.
    LeftRightAnchorsUsedWithoutY,
    /// Left+bottom+right anchors already imply `x`/`y`.
    LeftBottomRightAnchorsUsedWithXY,
    /// Left+bottom+right anchors already imply `width`.
    LeftBottomRightAnchorsUsedWithWidth,
    /// Left+bottom+right anchors already imply `pivot`.
    LeftBottomRightAnchorsUsedWithPivot,
    /// Top+bottom anchors already imply `y`.
    TopBottomAnchorsUsedWithY,
    /// Top+bottom anchors already imply `height`.
    TopBottomAnchorsUsedWithHeight,
    /// Top+bottom anchors require `x`.
    TopBottomAnchorsUsedWithoutX,
    /// Top+bottom anchors require a `pivot`.
    TopBottomAnchorsUsedWithoutPivot,
    /// Top+bottom anchors only allow left/center/right pivots.
    TopBottomAnchorsUsedWithInvalidPivot,
    /// Top+left+bottom anchors already imply `x`/`y`.
    TopLeftBottomAnchorsUsedWithXY,
    /// Top+left+bottom anchors already imply `height`.
    TopLeftBottomAnchorsUsedWithHeight,
    /// Top+left+bottom anchors already imply `pivot`.
    TopLeftBottomAnchorsUsedWithPivot,
    /// Top+right+bottom anchors already imply `x`/`y`.
    TopRightBottomAnchorsUsedWithXY,
    /// Top+right+bottom anchors already imply `height`.
    TopRightBottomAnchorsUsedWithHeight,
    /// Top+right+bottom anchors already imply `pivot`.
    TopRightBottomAnchorsUsedWithPivot,
    /// A single anchor is equivalent to a pivot; use pivot layout instead.
    SingleAnchor,
    /// `x` was set without `y`.
    XWithoutY,
    /// `y` was set without `x`.
    YWithoutX,
    /// `pivot` requires both `x` and `y`.
    PivotWithoutXorY,
    /// No layout parameters were provided.
    NoParameters,
    /// The combination of layout parameters is invalid.
    InvalidLayoutRule
}

impl Error {
    fn description(&self) -> &'static str {
        match self {
            Error::NoParameters => "No parameters provided to the LayoutBuilder method ! Please provide either an absolute layout, a docked layout, a pivot layout, an alignment layout or an anchored-based  layout !",
            Error::XYParameterUsedWithDock => "When ('dock') parameter is used, 'x' and 'y' parameters can not be used !",
            Error::AnchorParameterUsedWithDock => "When ('dock') parameter is used, anchor parameters ('top', 'bottom', 'left' and 'right') can not be used !",
            Error::PivotParameterUsedWithDock => "When ('dock') parameter is used, 'pivot' parameter can not be used !",
            Error::AlignParameterUsedWithDock => "When ('dock') parameter is used, 'align' parameter can not be used !",
            Error::WidthParameterUsedWithTopOrBottomDock => "When ('dock') parameter is used with the value 'Dock:Top' or 'Dock:Bottom', the 'width' parameter can not be used as it is infered from the parent's width !",
            Error::HeightParameterUsedWithLeftOrRightDock => "When ('dock') parameter is used with the value 'Dock:Left' or 'Dock:Right', the 'height' parameter can not be used as it is infered from the parent's height !",
            Error::WidthOrHeightParameterUsedWithDockFill => "When ('dock') parameter is used with the value 'Dock:Fill', the 'width' and 'height' parameters can not be used as they are infered from the parent's width and height !",
            Error::XYParameterUsedWithAlign => "When ('align') parameter is used,'x' and 'y' parameters can not be used !",
            Error::AnchorParameterUsedWithAlign => "When ('align') parameter is used, anchor parameters ('top', 'bottom', 'left' and 'right') can not be used !",
            Error::PivotParameterUsedWithAlign => "When ('align') parameter is used, 'pivot' parameter can not be used !",
            Error::DockParameterUsedWithAlign => "When ('align') parameter is used, 'dock' parameter can not be used !",
            Error::AnchorParameterUsedWithXY => "When ('x' and 'y') parameters are used, anchor parameters ('top', 'bottom', 'left' and 'right') can not be used !",
            Error::CornerAnchorParameterUsedWithXY => "When a corner anchor is provided - e.g ('top' with `left`, 'top' with `right`, 'bottom' with `left` or 'bottom' with `right`) - 'x' and 'y' parameters can not be used as they are infered from the anchor !",
            Error::CornerAnchorParameterUsedWithPivot => "When a corner anchor is provided - e.g ('top' with `left`, 'top' with `right`, 'bottom' with `left` or 'bottom' with `right`) - 'pivot' parameter can not be used as it is infered from the anchor !",
            Error::InvalidLayoutRule => "The layout rule (combination of parameters) is invalid !",
            Error::AllAnchorsParameterUsedWithXY => "When all anchor parameters ('left', 'top', 'right' and 'bottom') are used, 'x' and 'y' parameters can not be used as they are infered from the anchors !",
            Error::AllAnchorsParameterUsedWithSize => "When all anchor parameters ('left', 'top', 'right' and 'bottom') are used, 'width' and 'height' parameters can not be used as they are infered from the anchors !",
            Error::AllAnchorsParameterUsedWithPivot => "When all anchor parameters ('left', 'top', 'right' and 'bottom') are used, 'pivot' parameter can not be used as it is infered from the anchors !",
            Error::LeftTopRightAnchorsUsedWithXY => "When (left,top,right) anchors are used together, 'x' and 'y' parameter can not be used as they are infered from the anchors !",
            Error::LeftTopRightAnchorsUsedWithWidth => "When (left,top,right) anchors are used together, 'width' parameter can not be used as it is infered from the anchors !",
            Error::LeftTopRightAnchorsUsedWithPivot => "When (left,top,right) anchors are used together, 'pivot' parameter can not be used as it is infered from the anchors !",
            Error::LeftRightAnchorsUsedWithX => "When (left,right) anchors are used together, 'x' parameter can not be used as it is infered from the anchors !",
            Error::LeftRightAnchorsUsedWithWidth => "When (left,right) anchors are used together, 'width' parameter can not be used as it is infered from the anchors !",
            Error::LeftRightAnchorsUsedWithoutPivot => "When (left,right) anchors are used together, 'pivot' parameter must be provided !",
            Error::LeftRightAnchorsUsedWithoutY => "When (left,right) anchors are used together, 'y' parameter must be provided !",
            Error::LeftBottomRightAnchorsUsedWithXY => "When (left,bottom,right) anchors are used together, 'x' and 'y' parameter can not be used as they are infered from the anchors !",
            Error::LeftBottomRightAnchorsUsedWithWidth => "When (left,bottom,right) anchors are used together, 'width' parameter can not be used as it is infered from the anchors !",
            Error::LeftBottomRightAnchorsUsedWithPivot => "When (left,bottom,right) anchors are used together, 'pivot' parameter can not be used as it is infered from the anchors !",
            Error::TopBottomAnchorsUsedWithY => "When (top,bottom) anchors are used together, 'y' parameter can not be used as it is infered from the anchors !",
            Error::TopBottomAnchorsUsedWithHeight => "When (top,bottom) anchors are used together, 'height' parameter can not be used as it is infered from the anchors !",
            Error::TopBottomAnchorsUsedWithoutX => "When (top,bottom) anchors are used together, 'x' parameter must be provided !",
            Error::TopBottomAnchorsUsedWithoutPivot => "When (top,bottom) anchors are used together, 'pivot' parameter must be provided !",
            Error::TopBottomAnchorsUsedWithInvalidPivot => "When (top,bottom) anchors are used together, only Pivot::LeftCenter, Pivot::Center and Pivot::RightCenter pivot values are allowed !",
            Error::TopLeftBottomAnchorsUsedWithXY => "When (top,left,bottom) anchors are used together, 'x' and 'y' parameter can not be used as they are infered from the anchors !",
            Error::TopLeftBottomAnchorsUsedWithHeight => "When (top,left,bottom) anchors are used together, 'height' parameter can not be used as it is infered from the anchors !",
            Error::TopLeftBottomAnchorsUsedWithPivot => "When (top,left,bottom) anchors are used together, 'pivot' parameter can not be used as it is infered from the anchors !",
            Error::TopRightBottomAnchorsUsedWithXY => "When (top,right,bottom) anchors are used together, 'x' and 'y' parameter can not be used as they are infered from the anchors !",
            Error::TopRightBottomAnchorsUsedWithHeight => "When (top,right,bottom) anchors are used together, 'height' parameter can not be used as it is infered from the anchors !",
            Error::TopRightBottomAnchorsUsedWithPivot => "When (top,right,bottom) anchors are used together, 'pivot' parameter can not be used as it is infered from the anchors !",
            Error::SingleAnchor => "Using a single anchor (left, right, top, bottom) is no different than using a pivot. Consider using a pivot instead, combined with (x,y) and optionally and width and a height",
            Error::XWithoutY => "You need to provide the 'y' parameter as well to create a point for an absolute or pivoting layout !",
            Error::YWithoutX => "You need to provide the 'x' parameter as well to create a point for an absolute or pivoting layout !",
            Error::PivotWithoutXorY => "You need to provide both 'x' and 'y' parameter if you provide a pivot value !",
        }
    }
}   

impl Display for Error {
    fn fmt(&self, f: &mut Formatter<'_>) -> Result {
        write!(f, "Layout error: {}", self.description())
    }
}