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.
320
321
322
323
324
325
326
327
328
|
# File 'lib/terminal_layout.rb', line 320
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.
318
319
320
|
# File 'lib/terminal_layout.rb', line 318
def children
@children
end
|
#computed ⇒ Object
Returns the value of attribute computed.
318
319
320
|
# File 'lib/terminal_layout.rb', line 318
def computed
@computed
end
|
#content ⇒ Object
Returns the value of attribute content.
318
319
320
|
# File 'lib/terminal_layout.rb', line 318
def content
@content
end
|
#name ⇒ Object
Returns the value of attribute name.
318
319
320
|
# File 'lib/terminal_layout.rb', line 318
def name
@name
end
|
#style ⇒ Object
Returns the value of attribute style.
318
319
320
|
# File 'lib/terminal_layout.rb', line 318
def style
@style
end
|
Instance Method Details
#find_child_of_type(type, &block) ⇒ Object
352
353
354
355
356
357
358
359
360
361
|
# File 'lib/terminal_layout.rb', line 352
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
375
376
377
|
# File 'lib/terminal_layout.rb', line 375
def height
style[:height]
end
|
#inspect ⇒ Object
379
380
381
|
# File 'lib/terminal_layout.rb', line 379
def inspect
to_s
end
|
#position ⇒ Object
363
364
365
|
# File 'lib/terminal_layout.rb', line 363
def position
Position.new(x, y)
end
|
#size ⇒ Object
367
368
369
|
# File 'lib/terminal_layout.rb', line 367
def size
Dimension.new(width, height)
end
|
#to_s ⇒ Object
387
388
389
|
# File 'lib/terminal_layout.rb', line 387
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
383
384
385
|
# File 'lib/terminal_layout.rb', line 383
def to_str
to_s
end
|
#update_computed(style) ⇒ Object
391
392
393
|
# File 'lib/terminal_layout.rb', line 391
def update_computed(style)
@computed.merge!(style)
end
|
#width ⇒ Object
371
372
373
|
# File 'lib/terminal_layout.rb', line 371
def width
style[:width]
end
|