Skip to main content

retroglyph_ui/widget/
border_type.rs

1//! [`BorderType`]: which box-drawing glyph set a bordered widget draws with.
2use retroglyph_core::symbols::BorderSet;
3use retroglyph_core::symbols::border;
4
5/// The box-drawing glyph set [`BoxBorder`](super::BoxBorder), [`Panel`](super::Panel), and
6/// [`Modal`](super::Modal) draw their corners and edges with.
7///
8/// [`BorderType::Plain`] is the default: the single-line set every one of these widgets drew
9/// before this type existed, so adding it is purely additive. The other three variants exist to
10/// make nested or stateful boxes visually distinct at a glance: an outer [`BorderType::Double`]
11/// around an inner [`BorderType::Plain`] reads instantly, where two identical single lines don't,
12/// and double/thick borders are a legible way to mark an active pane even on a 16-color terminal
13/// where [`Theme`](crate::Theme) alone can't carry that distinction.
14///
15/// Covers four of ratatui's six `BorderType` variants (`Plain`, `Rounded`, `Double`, `Thick`);
16/// `QuadrantInside`/`QuadrantOutside` are omitted since nothing here has a use for them yet. Each
17/// variant maps directly to a [`BorderSet`](retroglyph_core::symbols::BorderSet) in
18/// [`retroglyph_core::symbols::border`], the shared glyph tables every crate draws borders from.
19///
20/// # Examples
21///
22/// ```
23/// use retroglyph_ui::{BorderType, BoxBorder};
24///
25/// let border = BoxBorder::new().border_type(BorderType::Rounded);
26/// ```
27#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
28pub enum BorderType {
29    /// Single-line box-drawing glyphs: `┌─┐│└┘`.
30    #[default]
31    Plain,
32    /// Single-line glyphs with rounded corners: `╭─╮│╰╯`.
33    Rounded,
34    /// Double-line box-drawing glyphs: `╔═╗║╚╝`.
35    Double,
36    /// Heavy single-line box-drawing glyphs: `┏━┓┃┗┛`.
37    Thick,
38}
39
40impl BorderType {
41    /// This variant's [`BorderSet`](retroglyph_core::symbols::BorderSet): the six corner/edge
42    /// glyphs to draw a border with.
43    #[must_use]
44    pub(crate) const fn glyphs(self) -> BorderSet {
45        match self {
46            Self::Plain => border::PLAIN,
47            Self::Rounded => border::ROUNDED,
48            Self::Double => border::DOUBLE,
49            Self::Thick => border::THICK,
50        }
51    }
52}