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
#[derive(Copy, Clone, PartialEq, Debug)]
/// A width or height, either in character cells or as a fraction of the parent.
///
/// Absolute values are in cells. Percentage values are typically between `0.0` and
/// `1.0` of the parent size.
pub enum Dimension {
    /// Size in character cells, for example `20`.
    Absolute(u32),
    /// Fraction of the parent size, typically `0.0`–`1.0` (for example `0.5` is 50%).
    Percentage(f32),
}
impl Dimension {
    pub fn is_absolute(&self) -> bool {
        match self {
            Dimension::Absolute(_) => true,
            Dimension::Percentage(_) => false,
        }
    }
    pub fn absolute(&self, parent_size: u16) -> u16 {
        match self {
            Dimension::Absolute(v) => (*v) as u16,
            Dimension::Percentage(v) =>((parent_size as f32) * v) as u16,
        }
    }
}
impl From<u16> for Dimension {
    fn from(value: u16) -> Self {
        Dimension::Absolute(value as u32)
    }
}
impl From<u8> for Dimension {
    fn from(value: u8) -> Self {
        Dimension::Absolute(value as u32)
    }
}
impl From<u32> for Dimension {
    fn from(value: u32) -> Self {
        Dimension::Absolute(value)
    }
}
impl From<u64> for Dimension {
    fn from(value: u64) -> Self {
        Dimension::Absolute(value as u32)
    }
}
impl From<i8> for Dimension {
    fn from(value: i8) -> Self {
        if value > 0 {
            Dimension::Absolute(value as u32)
        } else {
            Dimension::Absolute(0)
        }
    }
}
impl From<i16> for Dimension {
    fn from(value: i16) -> Self {
        if value > 0 {
            Dimension::Absolute(value as u32)
        } else {
            Dimension::Absolute(0)
        }
    }
}
impl From<i32> for Dimension {
    fn from(value: i32) -> Self {
        if value > 0 {
            Dimension::Absolute(value as u32)
        } else {
            Dimension::Absolute(0)
        }
    }
}
impl From<i64> for Dimension {
    fn from(value: i64) -> Self {
        if value > 0 {
            Dimension::Absolute(value as u32)
        } else {
            Dimension::Absolute(0)
        }
    }
}
impl From<f32> for Dimension {
    fn from(value: f32) -> Self {
        Dimension::Percentage(value)
    }
}
impl From<f64> for Dimension {
    fn from(value: f64) -> Self {
        Dimension::Percentage(value as f32)
    }
}