Class: TerminalLayout::Box
- Inherits:
-
Object
- Object
- TerminalLayout::Box
show all
- Includes:
- EventEmitter
- Defined in:
- lib/terminal_layout.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
#_callbacks, #emit, #on, #unsubscribe
Constructor Details
#initialize(style: {}, children: [], content: "") ⇒ Box
Returns a new instance of Box.
343
344
345
346
347
348
349
350
351
|
# File 'lib/terminal_layout.rb', line 343
def initialize(style:{}, children:[], content:"")
@style = style
@children = children
@content = ANSIString.new(content)
@computed = {}
initialize_defaults
subscribe_to_events_on_children
end
|
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
341
342
343
|
# File 'lib/terminal_layout.rb', line 341
def children
@children
end
|
#computed ⇒ Object
Returns the value of attribute computed.
341
342
343
|
# File 'lib/terminal_layout.rb', line 341
def computed
@computed
end
|
#content ⇒ Object
Returns the value of attribute content.
341
342
343
|
# File 'lib/terminal_layout.rb', line 341
def content
@content
end
|
#name ⇒ Object
Returns the value of attribute name.
341
342
343
|
# File 'lib/terminal_layout.rb', line 341
def name
@name
end
|
#style ⇒ Object
Returns the value of attribute style.
341
342
343
|
# File 'lib/terminal_layout.rb', line 341
def style
@style
end
|
Instance Method Details
#find_child_of_type(type, &block) ⇒ Object
375
376
377
378
379
380
381
382
383
384
|
# File 'lib/terminal_layout.rb', line 375
def find_child_of_type(type, &block)
children.each do |child|
matches = child.is_a?(type)
matches &= block.call(child) if matches && block
return child if matches
child_matches = child.find_child_of_type(type, &block)
return child_matches if child_matches
end
nil
end
|
#height ⇒ Object
398
399
400
|
# File 'lib/terminal_layout.rb', line 398
def height
style[:height]
end
|
#inspect ⇒ Object
402
403
404
|
# File 'lib/terminal_layout.rb', line 402
def inspect
to_s
end
|
#position ⇒ Object
386
387
388
|
# File 'lib/terminal_layout.rb', line 386
def position
Position.new(x, y)
end
|
#size ⇒ Object
390
391
392
|
# File 'lib/terminal_layout.rb', line 390
def size
Dimension.new(width, height)
end
|
#to_s ⇒ Object
410
411
412
|
# File 'lib/terminal_layout.rb', line 410
def to_s
"<#{self.class}##{object_id} position=(#{x},#{y}) dimensions=#{width}x#{height} display=#{display.inspect} content=#{content} name=#{@name}/>"
end
|
#to_str ⇒ Object
406
407
408
|
# File 'lib/terminal_layout.rb', line 406
def to_str
to_s
end
|
#update_computed(style) ⇒ Object
414
415
416
|
# File 'lib/terminal_layout.rb', line 414
def update_computed(style)
@computed.merge!(style)
end
|
#width ⇒ Object
394
395
396
|
# File 'lib/terminal_layout.rb', line 394
def width
style[:width]
end
|