Class: Chamomile::Widgets::VerticalLayout

Inherits:
Object
  • Object
show all
Defined in:
lib/chamomile/frame.rb

Overview

Vertical layout — stacks children.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeVerticalLayout

Returns a new instance of VerticalLayout.



227
228
229
# File 'lib/chamomile/frame.rb', line 227

def initialize
  @children = []
end

Instance Attribute Details

#childrenObject (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

#status_bar(content) ⇒ Object



251
252
253
254
255
# File 'lib/chamomile/frame.rb', line 251

def status_bar(content)
  sb = StatusBar.new(content: content.to_s)
  @children << sb
  sb
end

#text(content) ⇒ Object



238
239
240
241
242
# File 'lib/chamomile/frame.rb', line 238

def text(content)
  t = Text.new(content: content.to_s)
  @children << t
  t
end