pub struct Panel { /* private fields */ }Expand description
A bordered box around a renderable. Mirrors rich.panel.Panel.
Implementations§
Source§impl Panel
impl Panel
Sourcepub fn new(child: Box<dyn Renderable>) -> Self
pub fn new(child: Box<dyn Renderable>) -> Self
A panel around child with default box (ROUNDED) and padding (0,1).
Sourcepub fn fit(child: Box<dyn Renderable>) -> Self
pub fn fit(child: Box<dyn Renderable>) -> Self
A panel that fits its content rather than expanding to the available
width. Port of Panel.fit (expand=False).
Sourcepub fn expand(self, expand: bool) -> Self
pub fn expand(self, expand: bool) -> Self
Expand to the full available width (upstream expand, default on), or
fit the measured width of the content and title.
Sourcepub fn width(self, width: usize) -> Self
pub fn width(self, width: usize) -> Self
A fixed width for the whole panel, borders included (upstream width),
capped at the available width.
Sourcepub fn title(self, title: impl Into<String>) -> Self
pub fn title(self, title: impl Into<String>) -> Self
Set a title (drawn into the top border, centered by default).
Sourcepub fn title_as_text(self, title: Text) -> Self
pub fn title_as_text(self, title: Text) -> Self
Sourcepub fn title_align(self, align: HorizontalAlign) -> Self
pub fn title_align(self, align: HorizontalAlign) -> Self
Set the title alignment within the top border.
Sourcepub fn subtitle(self, subtitle: impl Into<String>) -> Self
pub fn subtitle(self, subtitle: impl Into<String>) -> Self
Set a subtitle (drawn into the bottom border, centered by default).
Sourcepub fn subtitle_as_text(self, subtitle: Text) -> Self
pub fn subtitle_as_text(self, subtitle: Text) -> Self
Sourcepub fn safe_box(self, safe_box: Option<bool>) -> Self
pub fn safe_box(self, safe_box: Option<bool>) -> Self
Whether to substitute boxes a legacy Windows console cannot draw
(upstream safe_box; None, the default, takes the console’s).
Sourcepub fn subtitle_align(self, align: HorizontalAlign) -> Self
pub fn subtitle_align(self, align: HorizontalAlign) -> Self
Set the subtitle alignment within the bottom border.
Sourcepub fn padding(self, padding: (usize, usize, usize, usize)) -> Self
pub fn padding(self, padding: (usize, usize, usize, usize)) -> Self
Set the inner padding (top, right, bottom, left).
Sourcepub fn highlight(self, highlight: bool) -> Self
pub fn highlight(self, highlight: bool) -> Self
Highlight strings rendered inside the panel (upstream
Panel(highlight=…), default off). Passed to the child as
ConsoleOptions::highlight.
Sourcepub fn border_style(self, style: impl Into<StyleType>) -> Self
pub fn border_style(self, style: impl Into<StyleType>) -> Self
Source§impl Panel
Read access to what a panel holds: upstream’s public Panel fields. Not
upstream as methods, and they change nothing; they let an extension read
a panel instead of its rendering.
impl Panel
Read access to what a panel holds: upstream’s public Panel fields. Not
upstream as methods, and they change nothing; they let an extension read
a panel instead of its rendering.
use rich::{Panel, Text};
use rich::table::Cell;
let panel = Panel::new(Box::new(Text::new("body"))).title("[b]Status[/]");
assert!(matches!(panel.get_title(), Some(Cell::Markup(t)) if t == "[b]Status[/]"));
assert!(panel.get_subtitle().is_none());
assert_eq!(panel.renderable().printed_text().unwrap().plain(), "body");Sourcepub fn renderable(&self) -> &dyn Renderable
pub fn renderable(&self) -> &dyn Renderable
The renderable inside the panel (upstream Panel.renderable).
Sourcepub fn get_title(&self) -> Option<Cell>
pub fn get_title(&self) -> Option<Cell>
The title (upstream Panel.title): a Cell::Text
when set with title_as_text, which wins, else a
Cell::Markup set with title.
Sourcepub fn get_subtitle(&self) -> Option<Cell>
pub fn get_subtitle(&self) -> Option<Cell>
The subtitle (upstream Panel.subtitle), as get_title.
Sourcepub fn get_title_align(&self) -> HorizontalAlign
pub fn get_title_align(&self) -> HorizontalAlign
The title’s alignment (upstream Panel.title_align).
Sourcepub fn get_subtitle_align(&self) -> HorizontalAlign
pub fn get_subtitle_align(&self) -> HorizontalAlign
The subtitle’s alignment (upstream Panel.subtitle_align).
Trait Implementations§
Source§impl Renderable for Panel
impl Renderable for Panel
Source§fn measure(&self, console: &Console, options: &ConsoleOptions) -> Measurement
fn measure(&self, console: &Console, options: &ConsoleOptions) -> Measurement
Port of Panel.__rich_measure__: the widest of the content and the
title, measured inside the borders and padding, plus both; or the
fixed width. Either way the panel asks for exactly one width.
fn rich_render( &self, console: &Console, options: &ConsoleOptions, ) -> Vec<Segment>
Source§fn fit_to_measurement(&self) -> bool
fn fit_to_measurement(&self) -> bool
Console::print shrinks this renderable to its
measured width. Upstream renders every top-level renderable at the full
console width, so the default is false; an extension may opt in.Source§fn vertical(&self) -> Option<VerticalAlign>
fn vertical(&self) -> Option<VerticalAlign>
Table cell holding this renderable uses in
place of its column’s. Upstream reads getattr(renderable, "vertical", None); Align sets it.Source§fn print_end_line(&self, _options: &ConsoleOptions) -> bool
fn print_end_line(&self, _options: &ConsoleOptions) -> bool
"\n", so a print adds the final line break. A renderable
whose upstream output stops without one (Screen, LiveRender, a
Rule whose end has no newline) returns false, and the next
output continues its last line. options are the print’s options.