Class: Yildun::Pane

Inherits:
Object
  • Object
show all
Defined in:
lib/yildun/pane.rb,
sig/yildun.rbs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tab = nil, orientation: :leaf) ⇒ Pane

Returns a new instance of Pane.

Parameters:

  • tab (Object) (defaults to: nil)
  • orientation: (Symbol) (defaults to: :leaf)


7
8
9
# File 'lib/yildun/pane.rb', line 7

def initialize(tab = nil, orientation: :leaf)
  @children, @orientation = tab ? [tab] : [], orientation
end

Instance Attribute Details

#children ⇒ Array[untyped] (readonly)

Returns the value of attribute children.

Returns:

  • (Array[untyped])


5
6
7
# File 'lib/yildun/pane.rb', line 5

def children
  @children
end

#orientation ⇒ Symbol (readonly)

Returns the value of attribute orientation.

Returns:

  • (Symbol)


5
6
7
# File 'lib/yildun/pane.rb', line 5

def orientation
  @orientation
end

Instance Method Details

#leaf? ⇒ Boolean

Returns:

  • (Boolean)


11
# File 'lib/yildun/pane.rb', line 11

def leaf? = @orientation == :leaf

#split(tab, orientation: :horizontal) ⇒ Pane

Parameters:

  • tab (Object)
  • orientation: (Symbol) (defaults to: :horizontal)

Returns:



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/yildun/pane.rb', line 12

def split(tab, orientation: :horizontal)
  if leaf? && @children.empty?
    @children << (tab.is_a?(Pane) ? tab : Pane.new(tab))
    return self
  end

  if leaf?
    existing = @children.map { |child| child.is_a?(Pane) ? child : Pane.new(child) }
    @children = existing
  end
  @orientation = orientation
  @children << (tab.is_a?(Pane) ? tab : Pane.new(tab))
  self
end