Class: TerminalLayout::Box

Inherits:
Object
  • Object
show all
Includes:
EventEmitter
Defined in:
lib/terminal_layout.rb

Direct Known Subclasses

InputBox

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from EventEmitter

#_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

#childrenObject

Returns the value of attribute children.



318
319
320
# File 'lib/terminal_layout.rb', line 318

def children
  @children
end

#computedObject

Returns the value of attribute computed.



318
319
320
# File 'lib/terminal_layout.rb', line 318

def computed
  @computed
end

#contentObject

Returns the value of attribute content.



318
319
320
# File 'lib/terminal_layout.rb', line 318

def content
  @content
end

#nameObject

Returns the value of attribute name.



318
319
320
# File 'lib/terminal_layout.rb', line 318

def name
  @name
end

#styleObject

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

#heightObject



375
376
377
# File 'lib/terminal_layout.rb', line 375

def height
  style[:height]
end

#inspectObject



379
380
381
# File 'lib/terminal_layout.rb', line 379

def inspect
  to_s
end

#positionObject



363
364
365
# File 'lib/terminal_layout.rb', line 363

def position
  Position.new(x, y)
end

#sizeObject



367
368
369
# File 'lib/terminal_layout.rb', line 367

def size
  Dimension.new(width, height)
end

#to_sObject



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_strObject



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

#widthObject



371
372
373
# File 'lib/terminal_layout.rb', line 371

def width
  style[:width]
end