Class: Charming::Presentation::Layout::Pane
- Inherits:
-
Object
- Object
- Charming::Presentation::Layout::Pane
- 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
-
#grow ⇒ Object
readonly
The pane’s focus slot name, fixed width, fixed height, and grow weight.
-
#height ⇒ Object
readonly
The pane’s focus slot name, fixed width, fixed height, and grow weight.
-
#name ⇒ Object
readonly
The pane’s focus slot name, fixed width, fixed height, and grow weight.
-
#width ⇒ Object
readonly
The pane’s focus slot name, fixed width, fixed height, and grow weight.
Instance Method Summary collapse
-
#add_child(_node) ⇒ Object
Raises ArgumentError — panes are leaves and cannot contain layout children.
-
#focusable_names ⇒ Object
Returns [name] when the pane is marked focusable and has a name, otherwise [].
-
#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
constructor
name is the focus slot identifier (optional).
-
#render(rect) ⇒ Object
Renders the pane into rect, applying the configured style, border, and padding around the evaluated content.
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
#grow ⇒ Object (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 |
#height ⇒ Object (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 |
#name ⇒ Object (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 |
#width ⇒ Object (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.
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_names ⇒ Object
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 |