Class: Charming::Presentation::Layout::Pane

Inherits:
Object
  • Object
show all
Defined in:
lib/charming/presentation/layout/pane.rb

Overview

Pane is a leaf layout node: a single rectangle with optional border, padding, and styling, containing a piece of content (a string, a View, or a block evaluated in the view’s context). Panes with a ‘name` and `focus: true` are registered as focusable slots in the controller’s focus ring.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name: nil, content: nil, block: nil, view: nil, width: nil, height: nil, grow: nil, border: nil, padding: nil, style: nil, focused_style: nil, focus: false, scroll: false, clip: true, wrap: false) ⇒ Pane

name is the focus slot identifier (optional). content or block provides the body. width/height/grow control sizing. border may be ‘true` (normal border) or a border name symbol. padding may be 1, 2, or 4 values (CSS-style shorthand). style sets the base style; focused_style overrides it when the pane is focused. *focus: true* marks the pane as focusable. scroll/clip/wrap control how overflow content is rendered (via the embedded Viewport).



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/charming/presentation/layout/pane.rb', line 20

def initialize(name: nil, content: nil, block: nil, view: nil, width: nil, height: nil, grow: nil, border: nil, padding: nil, style: nil, focused_style: nil, focus: false, scroll: false, clip: true, wrap: false)
  @name = name
  @content = content
  @block = block
  @view = view
  @width = width
  @height = height
  @grow = grow
  @border = border
  @padding = padding
  @style = style
  @focused_style = focused_style
  @focus = focus
  @scroll = scroll
  @clip = clip
  @wrap = wrap
end

Instance Attribute Details

#growObject (readonly)

The pane’s focus slot name, fixed width, fixed height, and grow weight.



12
13
14
# File 'lib/charming/presentation/layout/pane.rb', line 12

def grow
  @grow
end

#heightObject (readonly)

The pane’s focus slot name, fixed width, fixed height, and grow weight.



12
13
14
# File 'lib/charming/presentation/layout/pane.rb', line 12

def height
  @height
end

#nameObject (readonly)

The pane’s focus slot name, fixed width, fixed height, and grow weight.



12
13
14
# File 'lib/charming/presentation/layout/pane.rb', line 12

def name
  @name
end

#widthObject (readonly)

The pane’s focus slot name, fixed width, fixed height, and grow weight.



12
13
14
# File 'lib/charming/presentation/layout/pane.rb', line 12

def width
  @width
end

Instance Method Details

#add_child(_node) ⇒ Object

Raises ArgumentError — panes are leaves and cannot contain layout children.

Raises:

  • (ArgumentError)


39
40
41
# File 'lib/charming/presentation/layout/pane.rb', line 39

def add_child(_node)
  raise ArgumentError, "pane cannot contain layout children"
end

#focusable_namesObject

Returns [name] when the pane is marked focusable and has a name, otherwise [].



44
45
46
# File 'lib/charming/presentation/layout/pane.rb', line 44

def focusable_names
  (focus && name) ? [name] : []
end

#render(rect) ⇒ Object

Renders the pane into rect, applying the configured style, border, and padding around the evaluated content.



50
51
52
# File 'lib/charming/presentation/layout/pane.rb', line 50

def render(rect)
  outer_style(rect).render(rendered_content(rect))
end