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: StyleStyle of the border characters.
title_style: StyleStyle 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: boolCenter every body line instead of left-aligning it.
Implementations§
Source§impl Panel
impl Panel
Sourcepub fn title_style(self, style: Style) -> Self
pub fn title_style(self, style: Style) -> Self
Sets the title style.
Sourcepub fn padding(self, vertical: usize, horizontal: usize) -> Self
pub fn padding(self, vertical: usize, horizontal: usize) -> Self
Sets vertical and horizontal padding.
Sourcepub fn body_width(&self, term: &Term) -> usize
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.
Sourcepub fn render(&self, body_lines: &[String], term: &Term) -> Vec<String>
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.
Sourcepub fn render_markdown(&self, md: &str, term: &Term) -> Vec<String>
pub fn render_markdown(&self, md: &str, term: &Term) -> Vec<String>
Wraps markdown to the body width and draws the panel around it.
Sourcepub fn render_text(
&self,
content: &str,
text_style: Style,
term: &Term,
) -> Vec<String>
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§
impl Eq for Panel
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.