Skip to main content

BlockStyle

Struct BlockStyle 

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

A rectangle: padding, margin, border, dimensions, alignment, and the TextStyle that fills the geometry they create.

A BlockStyle is an immutable value, like TextStyle. Its text properties — colors and attributes — are the style of the block’s own fill: padding rows, alignment gaps, and text explicitly built from BlockStyle::text_style. A block’s style does not flow into a child view; each child carries its own complete value.

use urushi::{BlockStyle, Border, TextStyle, View};

let panel = BlockStyle::new().border(Border::ROUNDED).padding((0, 1));
let view = View::block(panel, View::text("こんにちは, urushi!", TextStyle::new()));

Implementations§

Source§

impl BlockStyle

Source

pub fn new() -> Self

Source

pub fn from_text_style(text_style: TextStyle) -> Self

Creates a block style filled with text.

Source

pub const fn text_style(&self) -> &TextStyle

Returns the style filling this block.

Source

pub fn foreground(self, color: impl Into<Color>) -> Self

Sets the fill (and text) foreground color.

Source

pub fn reset_foreground(self) -> Self

Returns the fill foreground color to the terminal default.

Source

pub fn background(self, color: impl Into<Color>) -> Self

Sets the fill (and text) background color.

Source

pub fn reset_background(self) -> Self

Returns the fill background color to the terminal default.

Source

pub fn add_attribute(self, attribute: TextAttribute) -> Self

Adds one active fill text attribute.

Source

pub fn add_attributes(self, attributes: TextAttributes) -> Self

Adds a set of active fill text attributes.

Source

pub fn remove_attribute(self, attribute: TextAttribute) -> Self

Removes one active fill text attribute.

Source

pub fn remove_attributes(self, attributes: TextAttributes) -> Self

Removes a set of active fill text attributes.

Source

pub fn reset_attributes(self) -> Self

Restores the active fill text attributes to their default value.

Source

pub fn bold(self) -> Self

Source

pub fn dim(self) -> Self

Source

pub fn italic(self) -> Self

Source

pub fn underlined(self) -> Self

Underlines the fill text with a single line in the foreground color.

Source

pub fn underline_style(self, style: UnderlineStyle) -> Self

Sets the shape the fill text’s underline is drawn with, adding an underline in the foreground color when the style has none.

Source

pub fn underline_color(self, color: impl Into<Color>) -> Self

Sets the color the fill text’s underline is drawn in, adding a single underline when the style has none.

Source

pub fn underline(self, underline: Underline) -> Self

Replaces the complete fill text underline value.

Source

pub fn reset_underline(self) -> Self

Removes the fill text underline, including its color.

Attaches an OSC 8 hyperlink to the fill text.

Removes the OSC 8 hyperlink from the fill text.

Source

pub fn reverse(self) -> Self

Source

pub fn hide(self) -> Self

Source

pub fn strikethrough(self) -> Self

Source

pub fn padding(self, sides: impl Into<Sides>) -> Self

Sets padding between the content and the border.

Source

pub fn reset_padding(self) -> Self

Restores the block padding to its default value.

Source

pub fn margin(self, sides: impl Into<Sides>) -> Self

Sets unstyled spacing outside the border.

Source

pub fn reset_margin(self) -> Self

Restores the block margin to its default value.

Source

pub fn border(self, border: Border) -> Self

Sets the border glyphs around the padded content.

A new style enables all four edges. Use the border_* builders to configure edge visibility independently.

Source

pub fn reset_border(self) -> Self

Removes the border glyph set. Edge configuration is retained.

Source

pub fn border_top(self, enabled: bool) -> Self

Enables or disables the top border edge.

Source

pub fn reset_border_top(self) -> Self

Restores top-edge visibility to its default value.

Source

pub fn border_right(self, enabled: bool) -> Self

Enables or disables the right border edge.

Source

pub fn reset_border_right(self) -> Self

Restores right-edge visibility to its default value.

Source

pub fn border_bottom(self, enabled: bool) -> Self

Enables or disables the bottom border edge.

Source

pub fn reset_border_bottom(self) -> Self

Restores bottom-edge visibility to its default value.

Source

pub fn border_left(self, enabled: bool) -> Self

Enables or disables the left border edge.

Source

pub fn reset_border_left(self) -> Self

Restores left-edge visibility to its default value.

Source

pub fn border_text_style(self, style: TextStyle) -> Self

Replaces the complete logical style used for border glyphs.

A subsequently applied border foreground or background overrides the corresponding property in this style.

Source

pub fn reset_border_text_style(self) -> Self

Restores the complete logical border-glyph style to its default value.

Source

pub fn border_foreground(self, color: impl Into<Color>) -> Self

Sets the border foreground color.

Source

pub fn reset_border_foreground(self) -> Self

Removes the border foreground override.

Source

pub fn border_background(self, color: impl Into<Color>) -> Self

Sets the border background color.

Source

pub fn reset_border_background(self) -> Self

Removes the border background override.

Source

pub fn width(self, width: impl Into<Length>) -> Self

Sets the width of the box: content plus padding plus enabled border edges, with margin outside it.

The absence of a width means auto — the content’s own width. Content wider than the resolved box is absorbed by BlockStyle::overflow; the frame closes at the resolved width either way.

Source

pub fn reset_width(self) -> Self

Returns the width to auto sizing.

Source

pub fn height(self, height: impl Into<Length>) -> Self

Sets the height of the box: content plus padding plus enabled border edges, with margin outside it.

This is a size, not a minimum: taller content is clipped inside the frame rather than growing the box. The absence of a height means auto.

Source

pub fn reset_height(self) -> Self

Returns the height to auto sizing.

Source

pub fn min_width(self, width: u16) -> Self

Sets the width below which the box does not shrink.

Source

pub fn reset_min_width(self) -> Self

Removes the minimum width.

Source

pub fn min_height(self, height: u16) -> Self

Sets the height below which the box does not shrink.

Source

pub fn reset_min_height(self) -> Self

Removes the minimum height.

Source

pub fn max_width(self, width: u16) -> Self

Bounds the box’s width. The box shrinks to fit its content and never exceeds this bound; the bound never cuts the frame.

Source

pub fn reset_max_width(self) -> Self

Removes the maximum width.

Source

pub fn max_height(self, height: u16) -> Self

Bounds the box’s height. The box shrinks to fit its content and never exceeds this bound; the bound never cuts the frame.

Source

pub fn reset_max_height(self) -> Self

Removes the maximum height.

Source

pub fn overflow(self, overflow: Overflow) -> Self

Sets how content wider than the box is absorbed.

Source

pub fn reset_overflow(self) -> Self

Restores the overflow policy to its default value.

Source

pub fn align(self, align: Align) -> Self

Sets the horizontal alignment of content within the box.

Source

pub fn reset_align(self) -> Self

Restores horizontal alignment to its default value.

Source

pub fn vertical_align(self, align: VerticalAlign) -> Self

Sets the vertical alignment of content within a fixed-height box.

Source

pub fn reset_vertical_align(self) -> Self

Restores vertical alignment to its default value.

Source

pub const fn get_foreground(&self) -> Option<Color>

Returns the fill foreground color instruction, if one is set.

Source

pub const fn get_background(&self) -> Option<Color>

Returns the fill background color instruction, if one is set.

Source

pub const fn get_underline(&self) -> Option<Underline>

Returns the fill text’s underline instruction, if one is set.

Source

pub const fn get_attributes(&self) -> TextAttributes

Returns the active fill text attributes.

Source

pub const fn get_padding(&self) -> Sides

Returns the padding applied inside the border.

Source

pub const fn get_margin(&self) -> Sides

Returns the unstyled margin applied outside the border.

Source

pub const fn get_border(&self) -> Option<Border>

Returns the border glyph set, if a border is enabled.

Source

pub const fn get_border_top(&self) -> bool

Returns whether the top border edge is enabled.

Source

pub const fn get_border_right(&self) -> bool

Returns whether the right border edge is enabled.

Source

pub const fn get_border_bottom(&self) -> bool

Returns whether the bottom border edge is enabled.

Source

pub const fn get_border_left(&self) -> bool

Returns whether the left border edge is enabled.

Source

pub const fn get_border_text_style(&self) -> &TextStyle

Returns the complete logical style used as the border-style base.

Source

pub const fn get_border_foreground(&self) -> Option<Color>

Returns the border foreground color instruction.

Source

pub const fn get_border_background(&self) -> Option<Color>

Returns the border background color instruction.

Source

pub const fn get_width(&self) -> Option<Length>

Returns the box’s width, if one is set.

Source

pub const fn get_height(&self) -> Option<Length>

Returns the box’s height, if one is set.

Source

pub const fn get_min_width(&self) -> Option<u16>

Returns the box’s minimum width, if one is set.

Source

pub const fn get_min_height(&self) -> Option<u16>

Returns the box’s minimum height, if one is set.

Source

pub const fn get_max_width(&self) -> Option<u16>

Returns the box’s maximum width, if one is set.

Source

pub const fn get_max_height(&self) -> Option<u16>

Returns the box’s maximum height, if one is set.

Source

pub const fn get_overflow(&self) -> &Overflow

Returns how content wider than the box is absorbed.

Source

pub fn frame_size(&self) -> Size

Returns the per-axis overhead of enabled border edges plus padding.

This is the conversion between the box a dimension measures and the content area inside it: outer minus frame_size() is the content area. Margin lies outside the box and keeps BlockStyle::get_margin.

Source

pub const fn get_align(&self) -> Align

Returns the horizontal alignment within the content box.

Source

pub const fn get_vertical_align(&self) -> VerticalAlign

Returns the vertical alignment within the content box.

Trait Implementations§

Source§

impl Clone for BlockStyle

Source§

fn clone(&self) -> BlockStyle

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 BlockStyle

Source§

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

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

impl Default for BlockStyle

Source§

fn default() -> Self

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

impl PartialEq for BlockStyle

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for BlockStyle

Source§

impl StructuralPartialEq for BlockStyle

Auto Trait Implementations§

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<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.