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
impl BlockStyle
pub fn new() -> Self
Sourcepub fn from_text_style(text_style: TextStyle) -> Self
pub fn from_text_style(text_style: TextStyle) -> Self
Creates a block style filled with text.
Sourcepub const fn text_style(&self) -> &TextStyle
pub const fn text_style(&self) -> &TextStyle
Returns the style filling this block.
Sourcepub fn foreground(self, color: impl Into<Color>) -> Self
pub fn foreground(self, color: impl Into<Color>) -> Self
Sets the fill (and text) foreground color.
Sourcepub fn reset_foreground(self) -> Self
pub fn reset_foreground(self) -> Self
Returns the fill foreground color to the terminal default.
Sourcepub fn background(self, color: impl Into<Color>) -> Self
pub fn background(self, color: impl Into<Color>) -> Self
Sets the fill (and text) background color.
Sourcepub fn reset_background(self) -> Self
pub fn reset_background(self) -> Self
Returns the fill background color to the terminal default.
Sourcepub fn add_attribute(self, attribute: TextAttribute) -> Self
pub fn add_attribute(self, attribute: TextAttribute) -> Self
Adds one active fill text attribute.
Sourcepub fn add_attributes(self, attributes: TextAttributes) -> Self
pub fn add_attributes(self, attributes: TextAttributes) -> Self
Adds a set of active fill text attributes.
Sourcepub fn remove_attribute(self, attribute: TextAttribute) -> Self
pub fn remove_attribute(self, attribute: TextAttribute) -> Self
Removes one active fill text attribute.
Sourcepub fn remove_attributes(self, attributes: TextAttributes) -> Self
pub fn remove_attributes(self, attributes: TextAttributes) -> Self
Removes a set of active fill text attributes.
Sourcepub fn reset_attributes(self) -> Self
pub fn reset_attributes(self) -> Self
Restores the active fill text attributes to their default value.
pub fn bold(self) -> Self
pub fn dim(self) -> Self
pub fn italic(self) -> Self
Sourcepub fn underlined(self) -> Self
pub fn underlined(self) -> Self
Underlines the fill text with a single line in the foreground color.
Sourcepub fn underline_style(self, style: UnderlineStyle) -> Self
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.
Sourcepub fn underline_color(self, color: impl Into<Color>) -> Self
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.
Sourcepub fn underline(self, underline: Underline) -> Self
pub fn underline(self, underline: Underline) -> Self
Replaces the complete fill text underline value.
Sourcepub fn reset_underline(self) -> Self
pub fn reset_underline(self) -> Self
Removes the fill text underline, including its color.
Sourcepub fn hyperlink(self, hyperlink: impl Into<Hyperlink>) -> Self
pub fn hyperlink(self, hyperlink: impl Into<Hyperlink>) -> Self
Attaches an OSC 8 hyperlink to the fill text.
Sourcepub fn reset_hyperlink(self) -> Self
pub fn reset_hyperlink(self) -> Self
Removes the OSC 8 hyperlink from the fill text.
pub fn blink(self) -> Self
pub fn reverse(self) -> Self
pub fn hide(self) -> Self
pub fn strikethrough(self) -> Self
Sourcepub fn padding(self, sides: impl Into<Sides>) -> Self
pub fn padding(self, sides: impl Into<Sides>) -> Self
Sets padding between the content and the border.
Sourcepub fn reset_padding(self) -> Self
pub fn reset_padding(self) -> Self
Restores the block padding to its default value.
Sourcepub fn reset_margin(self) -> Self
pub fn reset_margin(self) -> Self
Restores the block margin to its default value.
Sourcepub fn border(self, border: Border) -> Self
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.
Sourcepub fn reset_border(self) -> Self
pub fn reset_border(self) -> Self
Removes the border glyph set. Edge configuration is retained.
Sourcepub fn border_top(self, enabled: bool) -> Self
pub fn border_top(self, enabled: bool) -> Self
Enables or disables the top border edge.
Sourcepub fn reset_border_top(self) -> Self
pub fn reset_border_top(self) -> Self
Restores top-edge visibility to its default value.
Sourcepub fn border_right(self, enabled: bool) -> Self
pub fn border_right(self, enabled: bool) -> Self
Enables or disables the right border edge.
Sourcepub fn reset_border_right(self) -> Self
pub fn reset_border_right(self) -> Self
Restores right-edge visibility to its default value.
Sourcepub fn border_bottom(self, enabled: bool) -> Self
pub fn border_bottom(self, enabled: bool) -> Self
Enables or disables the bottom border edge.
Sourcepub fn reset_border_bottom(self) -> Self
pub fn reset_border_bottom(self) -> Self
Restores bottom-edge visibility to its default value.
Sourcepub fn border_left(self, enabled: bool) -> Self
pub fn border_left(self, enabled: bool) -> Self
Enables or disables the left border edge.
Sourcepub fn reset_border_left(self) -> Self
pub fn reset_border_left(self) -> Self
Restores left-edge visibility to its default value.
Sourcepub fn border_text_style(self, style: TextStyle) -> Self
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.
Sourcepub fn reset_border_text_style(self) -> Self
pub fn reset_border_text_style(self) -> Self
Restores the complete logical border-glyph style to its default value.
Sourcepub fn border_foreground(self, color: impl Into<Color>) -> Self
pub fn border_foreground(self, color: impl Into<Color>) -> Self
Sets the border foreground color.
Sourcepub fn reset_border_foreground(self) -> Self
pub fn reset_border_foreground(self) -> Self
Removes the border foreground override.
Sourcepub fn border_background(self, color: impl Into<Color>) -> Self
pub fn border_background(self, color: impl Into<Color>) -> Self
Sets the border background color.
Sourcepub fn reset_border_background(self) -> Self
pub fn reset_border_background(self) -> Self
Removes the border background override.
Sourcepub fn width(self, width: impl Into<Length>) -> Self
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.
Sourcepub fn reset_width(self) -> Self
pub fn reset_width(self) -> Self
Returns the width to auto sizing.
Sourcepub fn height(self, height: impl Into<Length>) -> Self
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.
Sourcepub fn reset_height(self) -> Self
pub fn reset_height(self) -> Self
Returns the height to auto sizing.
Sourcepub fn reset_min_width(self) -> Self
pub fn reset_min_width(self) -> Self
Removes the minimum width.
Sourcepub fn min_height(self, height: u16) -> Self
pub fn min_height(self, height: u16) -> Self
Sets the height below which the box does not shrink.
Sourcepub fn reset_min_height(self) -> Self
pub fn reset_min_height(self) -> Self
Removes the minimum height.
Sourcepub fn max_width(self, width: u16) -> Self
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.
Sourcepub fn reset_max_width(self) -> Self
pub fn reset_max_width(self) -> Self
Removes the maximum width.
Sourcepub fn max_height(self, height: u16) -> Self
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.
Sourcepub fn reset_max_height(self) -> Self
pub fn reset_max_height(self) -> Self
Removes the maximum height.
Sourcepub fn overflow(self, overflow: Overflow) -> Self
pub fn overflow(self, overflow: Overflow) -> Self
Sets how content wider than the box is absorbed.
Sourcepub fn reset_overflow(self) -> Self
pub fn reset_overflow(self) -> Self
Restores the overflow policy to its default value.
Sourcepub fn align(self, align: Align) -> Self
pub fn align(self, align: Align) -> Self
Sets the horizontal alignment of content within the box.
Sourcepub fn reset_align(self) -> Self
pub fn reset_align(self) -> Self
Restores horizontal alignment to its default value.
Sourcepub fn vertical_align(self, align: VerticalAlign) -> Self
pub fn vertical_align(self, align: VerticalAlign) -> Self
Sets the vertical alignment of content within a fixed-height box.
Sourcepub fn reset_vertical_align(self) -> Self
pub fn reset_vertical_align(self) -> Self
Restores vertical alignment to its default value.
Sourcepub const fn get_foreground(&self) -> Option<Color>
pub const fn get_foreground(&self) -> Option<Color>
Returns the fill foreground color instruction, if one is set.
Sourcepub const fn get_background(&self) -> Option<Color>
pub const fn get_background(&self) -> Option<Color>
Returns the fill background color instruction, if one is set.
Sourcepub const fn get_underline(&self) -> Option<Underline>
pub const fn get_underline(&self) -> Option<Underline>
Returns the fill text’s underline instruction, if one is set.
Sourcepub const fn get_attributes(&self) -> TextAttributes
pub const fn get_attributes(&self) -> TextAttributes
Returns the active fill text attributes.
Sourcepub const fn get_padding(&self) -> Sides
pub const fn get_padding(&self) -> Sides
Returns the padding applied inside the border.
Sourcepub const fn get_margin(&self) -> Sides
pub const fn get_margin(&self) -> Sides
Returns the unstyled margin applied outside the border.
Sourcepub const fn get_border(&self) -> Option<Border>
pub const fn get_border(&self) -> Option<Border>
Returns the border glyph set, if a border is enabled.
Sourcepub const fn get_border_top(&self) -> bool
pub const fn get_border_top(&self) -> bool
Returns whether the top border edge is enabled.
Sourcepub const fn get_border_right(&self) -> bool
pub const fn get_border_right(&self) -> bool
Returns whether the right border edge is enabled.
Sourcepub const fn get_border_bottom(&self) -> bool
pub const fn get_border_bottom(&self) -> bool
Returns whether the bottom border edge is enabled.
Sourcepub const fn get_border_left(&self) -> bool
pub const fn get_border_left(&self) -> bool
Returns whether the left border edge is enabled.
Sourcepub const fn get_border_text_style(&self) -> &TextStyle
pub const fn get_border_text_style(&self) -> &TextStyle
Returns the complete logical style used as the border-style base.
Sourcepub const fn get_border_foreground(&self) -> Option<Color>
pub const fn get_border_foreground(&self) -> Option<Color>
Returns the border foreground color instruction.
Sourcepub const fn get_border_background(&self) -> Option<Color>
pub const fn get_border_background(&self) -> Option<Color>
Returns the border background color instruction.
Sourcepub const fn get_height(&self) -> Option<Length>
pub const fn get_height(&self) -> Option<Length>
Returns the box’s height, if one is set.
Sourcepub const fn get_min_width(&self) -> Option<u16>
pub const fn get_min_width(&self) -> Option<u16>
Returns the box’s minimum width, if one is set.
Sourcepub const fn get_min_height(&self) -> Option<u16>
pub const fn get_min_height(&self) -> Option<u16>
Returns the box’s minimum height, if one is set.
Sourcepub const fn get_max_width(&self) -> Option<u16>
pub const fn get_max_width(&self) -> Option<u16>
Returns the box’s maximum width, if one is set.
Sourcepub const fn get_max_height(&self) -> Option<u16>
pub const fn get_max_height(&self) -> Option<u16>
Returns the box’s maximum height, if one is set.
Sourcepub const fn get_overflow(&self) -> &Overflow
pub const fn get_overflow(&self) -> &Overflow
Returns how content wider than the box is absorbed.
Sourcepub fn frame_size(&self) -> Size
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.
Sourcepub const fn get_align(&self) -> Align
pub const fn get_align(&self) -> Align
Returns the horizontal alignment within the content box.
Sourcepub const fn get_vertical_align(&self) -> VerticalAlign
pub const fn get_vertical_align(&self) -> VerticalAlign
Returns the vertical alignment within the content box.
Trait Implementations§
Source§impl Clone for BlockStyle
impl Clone for BlockStyle
Source§fn clone(&self) -> BlockStyle
fn clone(&self) -> BlockStyle
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for BlockStyle
impl Debug for BlockStyle
Source§impl Default for BlockStyle
impl Default for BlockStyle
Source§impl PartialEq for BlockStyle
impl PartialEq for BlockStyle
Source§fn eq(&self, other: &BlockStyle) -> bool
fn eq(&self, other: &BlockStyle) -> bool
self and other values to be equal, and is used by ==.