Class: Potty::Widgets::HBox

Inherits:
Container show all
Defined in:
lib/potty/widgets/container.rb

Overview

Horizontal row — children share the width in equal columns (the last absorbs rounding), each spanning the full height.

Instance Attribute Summary

Attributes inherited from Container

#children

Attributes inherited from Base

#app, #focused, #parent, #rect

Instance Method Summary collapse

Methods inherited from Container

#add, #focusable_widgets, #initialize, #on_layout, #render, #tick

Methods inherited from Base

#activate, #blur, #can_focus?, #deactivate, #focus, #handle_escape, #handle_key, #hide, #initialize, #layout, #on_blur, #on_focus, #on_layout, #render, #show, #theme, #tick, #visible=, #visible?

Methods included from Events

#emit, #listeners?, #off, #on

Constructor Details

This class inherits a constructor from Potty::Widgets::Container

Instance Method Details

#layout_childrenObject



90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/potty/widgets/container.rb', line 90

def layout_children
  n = @children.size
  return if n.zero?

  base = child_width(@rect.width)
  x = @rect.x
  @children.each_with_index do |child, i|
    w = i == n - 1 ? (@rect.x + @rect.width - x) : base
    child.layout(Layout::Rect.new(x, @rect.y, w, @rect.height))
    x += w + @spacing
  end
end

#preferred_height(width) ⇒ Object



84
85
86
87
88
# File 'lib/potty/widgets/container.rb', line 84

def preferred_height(width)
  return 0 if @children.empty?

  @children.map { |c| c.preferred_height(child_width(width)) }.max
end