Skip to main content

Layout

Struct Layout 

Source
pub struct Layout { /* private fields */ }
Expand description

A node in a layout tree. Mirrors rich.layout.Layout.

Implementations§

Source§

impl Layout

Source

pub fn new() -> Self

An empty layout (no renderable, so it shows the placeholder; no children).

Source

pub fn with_renderable(renderable: Box<dyn Renderable>) -> Self

A leaf layout wrapping renderable.

Source

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

Name this layout, for get (upstream name).

Source

pub fn visible(self, visible: bool) -> Self

Show or hide this layout (upstream visible, default on). A hidden child takes no space in its parent’s split.

Source

pub fn size(self, size: usize) -> Self

Pin this region to a fixed size along its parent’s split axis.

Source

pub fn ratio(self, ratio: usize) -> Self

Set the flex weight used when this region is unsized.

Source

pub fn minimum_size(self, minimum_size: usize) -> Self

Set the minimum size this region may shrink to.

Source

pub fn set_name(&mut self, name: Option<String>) -> &mut Self

Set (or clear) the name in place.

Source

pub fn set_visible(&mut self, visible: bool) -> &mut Self

Set the visibility in place.

Source

pub fn set_size(&mut self, size: Option<usize>) -> &mut Self

Set (or clear) the fixed size in place.

Source

pub fn set_ratio(&mut self, ratio: usize) -> &mut Self

Set the ratio in place.

Source

pub fn set_minimum_size(&mut self, minimum_size: usize) -> &mut Self

Set the minimum size in place.

Source

pub fn get_name(&self) -> Option<&str>

The name, if any.

Source

pub fn is_visible(&self) -> bool

Whether this layout is visible.

Source

pub fn get_size(&self) -> Option<usize>

The fixed size, if any.

Source

pub fn get_ratio(&self) -> usize

The ratio.

Source

pub fn get_minimum_size(&self) -> usize

The minimum size.

Source

pub fn splitter(&self) -> Splitter

The splitter dividing this layout among its children.

Source

pub fn renderable(&self) -> Option<&dyn Renderable>

The leaf renderable, if one is set (none shows the placeholder).

Source

pub fn update(&mut self, renderable: Box<dyn Renderable>)

Replace the leaf renderable. Port of Layout.update.

Source

pub fn children(&self) -> Vec<&Layout>

The visible children (upstream’s children property).

Source

pub fn all_children(&self) -> &[Layout]

Every child, hidden ones included (upstream _children).

Source

pub fn all_children_mut(&mut self) -> &mut Vec<Layout>

Every child, mutably.

Source

pub fn split(&mut self, children: Vec<Layout>, splitter: Splitter)

Split into children with splitter. Port of Layout.split.

Source

pub fn split_column(&mut self, children: Vec<Layout>)

Split into children stacked vertically. Port of Layout.split_column.

Source

pub fn split_row(&mut self, children: Vec<Layout>)

Split into children placed side by side. Port of Layout.split_row.

Source

pub fn add_split(&mut self, children: Vec<Layout>)

Add children to the existing split. Port of Layout.add_split.

Source

pub fn unsplit(&mut self)

Remove every child. Port of Layout.unsplit.

Source

pub fn get(&self, name: &str) -> Option<&Layout>

The first layout named name, depth first from this one. Port of Layout.get.

Source

pub fn get_mut(&mut self, name: &str) -> Option<&mut Layout>

get, mutably.

Source

pub fn at_path(&self, path: &[usize]) -> Option<&Layout>

The layout at path (child indexes, hidden children counted), as LayoutRender::path records it.

Source

pub fn tree(&self) -> Tree

A tree renderable showing the layout’s structure. Port of Layout.tree.

Source

pub fn region_map( &self, width: usize, height: usize, ) -> Vec<(Vec<usize>, Region)>

Every layout’s region for a width by height render, as (path, region) sorted by region. Port of Layout._make_region_map.

Source

pub fn render_regions( &self, console: &Console, options: &ConsoleOptions, ) -> Vec<LayoutRender>

Render every leaf into its region. Port of Layout.render: options give the width and (else the console’s) height.

Source

pub fn refresh_screen( &self, console: &Console, layout_name: &str, ) -> Result<bool>

Render the layout named layout_name again and write it over its region of the alternate screen. Port of Layout.refresh_screen: the layout must be a leaf of the last render (upstream raises KeyError otherwise; here, Ok(false) and nothing is written), and the console must be in the alternate screen (RichError::NoAltScreen otherwise).

Source

pub fn map(&self) -> Vec<LayoutRender>

The leaves of the last render. Port of Layout.map.

Trait Implementations§

Source§

impl Default for Layout

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Index<&str> for Layout

Source§

fn index(&self, name: &str) -> &Layout

layout[name]; panics as upstream raises KeyError when there is no such layout.

Source§

type Output = Layout

The returned type after indexing.
Source§

impl IndexMut<&str> for Layout

Source§

fn index_mut(&mut self, name: &str) -> &mut Layout

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl Renderable for Layout

Source§

fn rich_render( &self, console: &Console, options: &ConsoleOptions, ) -> Vec<Segment>

Source§

fn measure(&self, _console: &Console, options: &ConsoleOptions) -> Measurement

The (minimum, maximum) cell width this renderable wants. The default assumes the renderable fills the available width (e.g. Panel, Table); Text overrides it with its content width so the top-level print path can shrink to fit. Port of __rich_measure__ / Measurement.get.
Source§

fn fit_to_measurement(&self) -> bool

Whether a top-level 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>

The vertical alignment a Table cell holding this renderable uses in place of its column’s. Upstream reads getattr(renderable, "vertical", None); Align sets it.

Auto Trait Implementations§

§

impl !Freeze for Layout

§

impl !RefUnwindSafe for Layout

§

impl !Send for Layout

§

impl !Sync for Layout

§

impl !UnwindSafe for Layout

§

impl Unpin for Layout

§

impl UnsafeUnpin for Layout

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.