Class: Potty::Widgets::Panel
- Defined in:
- lib/potty/widgets/panel.rb
Overview
A bordered, optionally titled container. Stacks its children vertically inside a one-cell border frame.
Instance Attribute Summary collapse
-
#color ⇒ Object
Returns the value of attribute color.
-
#style ⇒ Object
Returns the value of attribute style.
-
#title ⇒ Object
Returns the value of attribute title.
Attributes inherited from Container
Attributes inherited from Base
#app, #focused, #parent, #rect
Instance Method Summary collapse
-
#initialize(app, title: nil, style: :single, color: :normal, spacing: 0) ⇒ Panel
constructor
A new instance of Panel.
- #layout_children ⇒ Object
- #preferred_height(width) ⇒ Object
- #render(window) ⇒ Object
Methods inherited from Container
#add, #focusable_widgets, #on_layout, #tick
Methods inherited from Base
#activate, #blur, #can_focus?, #deactivate, #focus, #handle_escape, #handle_key, #hide, #layout, #on_blur, #on_focus, #on_layout, #show, #theme, #tick, #visible=, #visible?
Methods included from Events
#emit, #listeners?, #off, #on
Constructor Details
#initialize(app, title: nil, style: :single, color: :normal, spacing: 0) ⇒ Panel
Returns a new instance of Panel.
13 14 15 16 17 18 |
# File 'lib/potty/widgets/panel.rb', line 13 def initialize(app, title: nil, style: :single, color: :normal, spacing: 0) super(app, spacing: spacing) @title = title @style = style @color = color end |
Instance Attribute Details
#color ⇒ Object
Returns the value of attribute color.
11 12 13 |
# File 'lib/potty/widgets/panel.rb', line 11 def color @color end |
#style ⇒ Object
Returns the value of attribute style.
11 12 13 |
# File 'lib/potty/widgets/panel.rb', line 11 def style @style end |
#title ⇒ Object
Returns the value of attribute title.
11 12 13 |
# File 'lib/potty/widgets/panel.rb', line 11 def title @title end |
Instance Method Details
#layout_children ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/potty/widgets/panel.rb', line 30 def layout_children inner = Layout::Rect.new( @rect.x + 1, @rect.y + 1, [@rect.width - 2, 0].max, [@rect.height - 2, 0].max ) rects = Layout.stack(inner, @children, spacing: @spacing) @children.zip(rects).each { |child, rect| child.layout(rect) } end |
#preferred_height(width) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/potty/widgets/panel.rb', line 20 def preferred_height(width) inner_w = [width - 2, 0].max inner = if @children.empty? 0 else @children.sum { |c| c.preferred_height(inner_w) } + @spacing * (@children.size - 1) end inner + 2 # top + bottom border end |