Skip to main content

Panel

Struct Panel 

Source
pub struct Panel {
    pub title: Option<String>,
    pub border: Style,
    pub title_style: Style,
    pub padding: (usize, usize),
    pub center: bool,
}
Expand description

A rounded box around pre-rendered body lines.

The fields are public so a panel can be written as a struct literal; the builder methods are a shorthand for the common cases.

use shellgame::ui::{Panel, Term, style};

let panel = Panel::new(style::GREEN).padding(0, 1).centered();
let lines = panel.render(&["Hotovo".to_owned()], &Term::plain(20));
assert_eq!(lines, [
    "╭──────────────────╮",
    "│      Hotovo      │",
    "╰──────────────────╯",
]);

Fields§

§title: Option<String>

Text in the top border. It may contain ANSI escape sequences of its own, in which case Panel::title_style should usually be left plain. Newlines become spaces and a title that is too long is truncated with ….

§border: Style

Style of the border characters.

§title_style: Style

Style applied to the whole title, re-applied after any reset inside it.

§padding: (usize, usize)

Blank rows above and below the body, and blank columns left and right of it, inside the border (the order matches Rich: (vertical, horizontal)).

§center: bool

Center every body line instead of left-aligning it.

Implementations§

Source§

impl Panel

Source

pub fn new(border: Style) -> Self

A panel with the given border style and default padding.

Source

pub fn title(self, title: impl Into<String>) -> Self

Sets the title.

Source

pub fn title_style(self, style: Style) -> Self

Sets the title style.

Source

pub fn padding(self, vertical: usize, horizontal: usize) -> Self

Sets vertical and horizontal padding.

Source

pub fn centered(self) -> Self

Centers every body line.

Source

pub fn body_width(&self, term: &Term) -> usize

Columns available to body lines in a panel as wide as term.

Render markdown or wrap text to this width before calling Panel::render.

Source

pub fn render(&self, body_lines: &[String], term: &Term) -> Vec<String>

Draws the panel around body_lines, term.width columns wide.

Body lines may contain ANSI escape sequences and are padded by their visible width. A line wider than the body is folded onto continuation rows that keep its leading indentation (code blocks are the only content that is not wrapped before it gets here). When term.color is off, escape sequences in the body and the title are removed.

Source

pub fn render_markdown(&self, md: &str, term: &Term) -> Vec<String>

Wraps markdown to the body width and draws the panel around it.

Source

pub fn render_text( &self, content: &str, text_style: Style, term: &Term, ) -> Vec<String>

Wraps plain text to the body width, styles it as a whole and draws the panel around it.

The text is printed verbatim (see text::wrap_plain): brackets, asterisks and backticks are not interpreted. Pass style::PLAIN for unstyled text.

Trait Implementations§

Source§

impl Clone for Panel

Source§

fn clone(&self) -> Panel

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Panel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Panel

Source§

fn default() -> Self

A plain, untitled, left-aligned panel with Rich’s (1, 2) padding.

Source§

impl Eq for Panel

Source§

impl PartialEq for Panel

Source§

fn eq(&self, other: &Panel) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Panel

Auto Trait Implementations§

§

impl Freeze for Panel

§

impl RefUnwindSafe for Panel

§

impl Send for Panel

§

impl Sync for Panel

§

impl Unpin for Panel

§

impl UnsafeUnpin for Panel

§

impl UnwindSafe for Panel

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.