etui/widgets/block

Types

Configuration for a bordered, titled container.

pub type Block {
  Block(
    border: Border,
    title: String,
    title_spans: List(span.Span),
    title_position: TitlePosition,
    title_alignment: text.Alignment,
    padding_top: Int,
    padding_bottom: Int,
    padding_left: Int,
    padding_right: Int,
    fg: style.Color,
    bg: style.Color,
    fill_bg: Bool,
  )
}

Constructors

  • Block(
      border: Border,
      title: String,
      title_spans: List(span.Span),
      title_position: TitlePosition,
      title_alignment: text.Alignment,
      padding_top: Int,
      padding_bottom: Int,
      padding_left: Int,
      padding_right: Int,
      fg: style.Color,
      bg: style.Color,
      fill_bg: Bool,
    )

    Arguments

    title_spans

    Styled title spans. When non-empty, used instead of title.

Box-drawing border style.

pub type Border {
  None
  Single
  Double
  Rounded
}

Constructors

  • None
  • Single
  • Double
  • Rounded

Where to place the block title.

pub type TitlePosition {
  Top
  Bottom
}

Constructors

  • Top
  • Bottom

Values

pub fn block_new() -> Block

New block with no border, no title, no padding, default colors.

pub fn inner(area: geometry.Rect, blk: Block) -> geometry.Rect

Inner area (content region) of a block, accounting for border and padding.

Use this to get the Rect to pass to child widgets:

let b = block.block_new() |> block.with_border(block.Single)
block.render(buf, area, b)
|> paragraph.render(block.inner(area, b), p)
pub fn render(
  buf: buffer.Buffer,
  area: geometry.Rect,
  blk: Block,
) -> buffer.Buffer

Render block into buffer at given area.

pub fn with_bg_fill(blk: Block) -> Block

Fill the inner area with the block’s background color.

pub fn with_border(blk: Block, border: Border) -> Block

Set the border style. Single draws ┌─┐│└─┘, Double ╔═╗║╚═╝, Rounded ╭─╮│╰─╯.

pub fn with_colors(
  blk: Block,
  fg: style.Color,
  bg: style.Color,
) -> Block

Alias for with_style(fg, bg), consistent with other widget naming.

pub fn with_padding(
  blk: Block,
  top: Int,
  bottom: Int,
  left: Int,
  right: Int,
) -> Block

Set inner padding (cells between border and content).

pub fn with_style(
  blk: Block,
  fg: style.Color,
  bg: style.Color,
) -> Block

Set foreground and background colors for the border and title.

pub fn with_title(
  blk: Block,
  title: String,
  position: TitlePosition,
) -> Block

Set a title string and whether it appears on the top or bottom border.

pub fn with_title_alignment(
  blk: Block,
  alignment: text.Alignment,
) -> Block

Set the horizontal alignment of the title within the border.

pub fn with_title_styled(
  blk: Block,
  spans: List(span.Span),
  position: TitlePosition,
) -> Block

Set a styled title from a list of span.Span values. Takes precedence over with_title when non-empty.

block.block_new()
|> block.with_border(block.Rounded)
|> block.with_title_styled([
  span.span_styled("★ ", style.bold_style() |> style.with_fg(style.Rgb(255,215,0))),
  span.span_plain("Dashboard"),
], block.Top)
Search Document