Class: Uh::Layout::Column

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
GeoAccessors
Defined in:
lib/uh/layout/column.rb

Constant Summary collapse

MODES =
{
  stack:  Arrangers::Stack,
  tile:   Arrangers::VertTile
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(geo, mode: :stack) ⇒ Column

Returns a new instance of Column.



19
20
21
22
23
# File 'lib/uh/layout/column.rb', line 19

def initialize geo, mode: :stack
  @geo      = geo.dup
  @clients  = Container.new
  @mode     = mode
end

Instance Attribute Details

#clientsObject (readonly)

Returns the value of attribute clients.



17
18
19
# File 'lib/uh/layout/column.rb', line 17

def clients
  @clients
end

#geoObject (readonly)

Returns the value of attribute geo.



17
18
19
# File 'lib/uh/layout/column.rb', line 17

def geo
  @geo
end

#modeObject (readonly)

Returns the value of attribute mode.



17
18
19
# File 'lib/uh/layout/column.rb', line 17

def mode
  @mode
end

Instance Method Details

#<<(client) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/uh/layout/column.rb', line 29

def << client
  client.geo = @geo.dup
  if @clients.current
    @clients.insert_after_current client
  else
    @clients << client
  end
  self
end

#arrange_clientsObject



55
56
57
58
# File 'lib/uh/layout/column.rb', line 55

def arrange_clients
  arranger.arrange
  clients.each &:moveresize
end

#arrangerObject



43
44
45
# File 'lib/uh/layout/column.rb', line 43

def arranger
  MODES[@mode].new @clients, @geo
end

#client_swap(direction) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/uh/layout/column.rb', line 47

def client_swap direction
  @clients.set direction
  if @mode == :tile
    arrange_clients
    show_hide_clients
  end
end

#mode_toggleObject



39
40
41
# File 'lib/uh/layout/column.rb', line 39

def mode_toggle
  @mode = MODES.keys[(MODES.keys.index(@mode) + 1) % MODES.keys.size]
end

#show_hide_clients(arranger: self.arranger) ⇒ Object



60
61
62
63
# File 'lib/uh/layout/column.rb', line 60

def show_hide_clients arranger: self.arranger
  arranger.each_visible { |client| client.show if client.hidden? }
  arranger.each_hidden  { |client| client.hide unless client.hidden? }
end

#to_sObject



25
26
27
# File 'lib/uh/layout/column.rb', line 25

def to_s
  "COL geo: #{@geo}"
end