class BBS::Widgets::Label
A single line of text. The text may carry ANSI colour codes.
Attributes
- text
-
the text shown (anything;
to_sis called on it) - align
-
:left,:centeror:rightwithin the bounds style_key-
the theme role the text is drawn in
- text
-
the text shown (anything;
to_sis called on it) - align
-
:left,:centeror:rightwithin the bounds style_key-
the theme role the text is drawn in
Public Class Methods
# File lib/bbs/widgets/label.rb, line 14 def initialize(text: '', align: :left, style_key: :text, **kw) super(**kw) @text = text @align = align @style_key = style_key end
Creates a label with text, align (default :left) and style_key (default :text).
Calls superclass method
BBS::Widget::new
Public Instance Methods
Source
# File lib/bbs/widgets/label.rb, line 23 def render(frame) return if bounds.width <= 0 clipped = @text.to_s[0, bounds.width].to_s frame.move(bounds.x + offset(clipped.length), bounds.y) frame.write_ansi(clipped, base_sgr: style(@style_key)) end
Draws the text on the first row of the bounds into frame, a BBS::FrameBuffer, cut to the width and aligned.