Class: Chamomile::Widgets::VerticalLayout
- Inherits:
-
Object
- Object
- Chamomile::Widgets::VerticalLayout
- Defined in:
- lib/chamomile/frame.rb
Overview
Vertical layout — stacks children.
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
Instance Method Summary collapse
- #horizontal(&block) ⇒ Object
-
#initialize ⇒ VerticalLayout
constructor
A new instance of VerticalLayout.
- #panel(title = nil, border: :rounded, width: nil, &block) ⇒ Object
- #render(width: 80, height: 24) ⇒ Object
- #status_bar(content) ⇒ Object
- #text(content) ⇒ Object
Constructor Details
#initialize ⇒ VerticalLayout
Returns a new instance of VerticalLayout.
227 228 229 |
# File 'lib/chamomile/frame.rb', line 227 def initialize @children = [] end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
225 226 227 |
# File 'lib/chamomile/frame.rb', line 225 def children @children end |
Instance Method Details
#horizontal(&block) ⇒ Object
244 245 246 247 248 249 |
# File 'lib/chamomile/frame.rb', line 244 def horizontal(&block) layout = HorizontalLayout.new block.call(layout) if block @children << layout layout end |
#panel(title = nil, border: :rounded, width: nil, &block) ⇒ Object
231 232 233 234 235 236 |
# File 'lib/chamomile/frame.rb', line 231 def panel(title = nil, border: :rounded, width: nil, &block) p = Panel.new(title: title, border: border, width: width) block.call(p) if block @children << p p end |
#render(width: 80, height: 24) ⇒ Object
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'lib/chamomile/frame.rb', line 257 def render(width: 80, height: 24) return "" if @children.empty? lines = [] remaining = height @children.each_with_index do |child, i| child_height = if i == @children.length - 1 remaining else [remaining / (@children.length - i), 1].max end lines << child.render(width: width, height: child_height) remaining -= child_height end lines.join("\n") end |