class BBS::Windows::Info::Body
The body items of an Info window: how many rows each takes, the lines it gives a scrolling body, and the widgets it places in a static one. Each item is of a kind (::kind), and each kind has a method for each of the two.
Constants
- HASH_KINDS
-
The kinds of a Hash item, in the order they are looked for.
- PLAIN_KINDS
-
The kinds of the items that are a Symbol, an empty String or
nil.
Public Class Methods
Source
# File lib/bbs/windows/info/body.rb, line 40 def self.height_of(widget) = widget.bounds.height.positive? ? widget.bounds.height : 1
The height of widget, or 1 before it has one.
Source
# File lib/bbs/windows/info/body.rb, line 43 def self.key_width(item) = item[:label_width] || ((item[:kv].map { |k, _| k.to_s.length }.max || 0) + 1).clamp(8, 16)
The width of the key column of pairs.
Source
# File lib/bbs/windows/info/body.rb, line 18 def self.kind(item) return PLAIN_KINDS[item] if PLAIN_KINDS.key?(item) case item when String then :line when Hash then HASH_KINDS.find { |k| item[k] } || :other when Widget then :raw_widget else :other end end
The kind of item: :blank, :rule, :line (a String), :kv, :widget, :text, :raw_widget (a BBS::Widget) or :other.
Source
# File lib/bbs/windows/info/body.rb, line 47 def initialize(window) @window = window end
A body for window, drawn with its theme and filled with widgets added to it.
Source
# File lib/bbs/windows/info/body.rb, line 30 def self.rows(item) case kind(item) when :kv then item[:kv].length when :widget then item[:height] || 1 when :raw_widget then height_of(item) else 1 end end
The rows item takes in a static body.
Public Instance Methods
Source
# File lib/bbs/windows/info/body.rb, line 53 def lines(item, width) = send(:"lines_#{Body.kind(item)}", item, width)
The lines of item in a scrolling body width wide. Raises ArgumentError for a widget item.
Source
# File lib/bbs/windows/info/body.rb, line 57 def place(item, x, y, width) = send(:"place_#{Body.kind(item)}", item, x, y, width)
Places the widgets of item at x, y, width wide in a static body. Returns the rows it took.