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::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::widget::{BorderType, BoxBorder};
24///
25/// let border = BoxBorder::new().border_type(BorderType::Rounded);
26/// ```
27#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
28#[non_exhaustive]
29pub enum BorderType {
30    /// Single-line box-drawing glyphs: `┌─┐│└┘`.
31    #[default]
32    Plain,
33    /// Single-line glyphs with rounded corners: `╭─╮│╰╯`.
34    Rounded,
35    /// Double-line box-drawing glyphs: `╔═╗║╚╝`.
36    Double,
37    /// Heavy single-line box-drawing glyphs: `┏━┓┃┗┛`.
38    Thick,
39}
40
41impl BorderType {
42    /// This variant's [`BorderSet`](retroglyph_core::symbols::BorderSet): the six corner/edge
43    /// glyphs to draw a border with.
44    #[must_use]
45    pub(crate) const fn glyphs(self) -> BorderSet {
46        match self {
47            Self::Plain => border::PLAIN,
48            Self::Rounded => border::ROUNDED,
49            Self::Double => border::DOUBLE,
50            Self::Thick => border::THICK,
51        }
52    }
53}