Class: Tuile::Component::Label

Inherits:
Tuile::Component show all
Defined in:
lib/tuile/component/label.rb

Overview

A label which shows static text. No word-wrapping; long lines are truncated with an ellipsis. Text is modeled as a StyledString; #text= accepts a String (parsed via StyledString.parse, so embedded ANSI is honored) or a StyledString directly. #text always returns the StyledString.

Instance Attribute Summary collapse

Attributes inherited from Tuile::Component

#content_size, #key_shortcut, #on_theme_changed, #parent, #rect

Instance Method Summary collapse

Methods inherited from Tuile::Component

#active=, #active?, #attached?, #children, #cursor_position, #depth, #find_shortcut_component, #focus, #focusable?, #handle_key, #handle_mouse, #keyboard_hint, #on_child_content_size_changed, #on_child_removed, #on_focus, #on_tree, #root, #screen, #tab_stop?

Constructor Details

#initializeLabel

Returns a new instance of Label.



11
12
13
14
15
16
17
# File 'lib/tuile/component/label.rb', line 11

def initialize
  super
  @text = StyledString::EMPTY
  @bg = nil
  @clipped_lines = []
  @blank_line = ""
end

Instance Attribute Details

#bgColor?

Returns background color applied uniformly across every painted row (including padding past the text). ‘nil` (default) leaves whatever bg the text’s own styling carries.

Returns:

  • (Color, nil)

    background color applied uniformly across every painted row (including padding past the text). ‘nil` (default) leaves whatever bg the text’s own styling carries.



26
27
28
# File 'lib/tuile/component/label.rb', line 26

def bg
  @bg
end

#textStyledString

Returns the current text. Defaults to an empty StyledString.

Returns:



21
22
23
# File 'lib/tuile/component/label.rb', line 21

def text
  @text
end

Instance Method Details

#repaintvoid

This method returns an undefined value.

Paints the text into Tuile::Component#rect.

Skips the Tuile::Component#repaint default’s auto-clear: every row is painted explicitly (with pre-padded blanks past the last line), so the “fully draw over your rect” contract is met without an upfront wipe.



68
69
70
71
72
73
74
75
# File 'lib/tuile/component/label.rb', line 68

def repaint
  return if rect.empty?

  (0...rect.height).each do |row|
    line = @clipped_lines[row] || @blank_line
    screen.print TTY::Cursor.move_to(rect.left, rect.top + row), line
  end
end