Class: Tuile::Component::Fill

Inherits:
Component
  • Object
show all
Defined in:
lib/tuile/component/fill.rb,
sig/tuile.rbs

Overview

Fills every cell of its #rect with one glyph. Give it a one-column rect and │ for a vertical rule between two borderless panes, a one-row rect and ─ for a horizontal one — the glyph decides the direction, the parent decides the length:

rule = Component::Fill.new("│", color: Theme.ref(:pane_frame))
bottom = Component::Layout::Horizontal.new
bottom.add(system_pane, Layout::Percent[40])
bottom.add(rule, Layout::Fixed[1])
bottom.add(log_pane, Layout::Expand[1])

Display-only — not focusable, no keys, no mouse. The background behind the glyph is its own #bg_color, else inherited, as for any component.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(char, color: nil) ⇒ Fill

@param char — initial #char=.

@param color — initial #color=.

Parameters:

  • char (String)
  • color: (Color, Theme::Ref, Symbol, Integer, ::Array[Integer], nil) (defaults to: nil)


24
25
26
27
28
29
# File 'lib/tuile/component/fill.rb', line 24

def initialize(char, color: nil)
  super()
  @char = StyledString.validate_glyph(char, :char)
  @color = nil
  self.color = color
end

Instance Attribute Details

#char ⇒ String

@return — the glyph painted into every cell; one grapheme cluster, one column wide.

Returns:

  • (String)


33
34
35
# File 'lib/tuile/component/fill.rb', line 33

def char
  @char
end

#color ⇒ Color, ...

@return — the value as set, so a Theme::Ref comes back unresolved; nil (the default) is the terminal's default foreground.

Returns:



38
39
40
# File 'lib/tuile/component/fill.rb', line 38

def color
  @color
end

Instance Method Details

#repaint(canvas) ⇒ void

This method returns an undefined value.

Paints #char into every cell. Not super: the default's clear would dirty every cell just before it is painted over.

@param canvas — see Tuile::Component#repaint.

Parameters:



80
81
82
83
84
85
# File 'lib/tuile/component/fill.rb', line 80

def repaint(canvas)
  return if rect.empty?

  row = StyledString.styled(@char * rect.width, fg: resolved_color)
  rect.height.times { canvas.set_text(0, _1, row) }
end

#resolved_color ⇒ Color?

Returns:



90
# File 'lib/tuile/component/fill.rb', line 90

def resolved_color = @color.is_a?(Theme::Ref) ? @color.resolve(screen.theme) : @color