Class: Soundcloud2000::UI::Table

Inherits:
View
  • Object
show all
Defined in:
lib/soundcloud2000/ui/table.rb

Direct Known Subclasses

Views::TracksTable

Constant Summary collapse

SEPARATOR =
'  |  '

Constants inherited from View

View::INTERSECTION, View::LINE_SEPARATOR, View::ROW_SEPARATOR

Instance Attribute Summary collapse

Attributes inherited from View

#rect

Instance Method Summary collapse

Methods inherited from View

#body_width, #clear, #padding, #render, #with_color

Constructor Details

#initialize(*args) ⇒ Table

Returns a new instance of Table.



11
12
13
14
15
16
17
18
19
20
# File 'lib/soundcloud2000/ui/table.rb', line 11

def initialize(*args)
  super

  @sizes = []
  @rows = []
  @current, @top = 0, 0
  @selected = nil

  reset
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



8
9
10
# File 'lib/soundcloud2000/ui/table.rb', line 8

def collection
  @collection
end

#currentObject (readonly)

Returns the value of attribute current.



8
9
10
# File 'lib/soundcloud2000/ui/table.rb', line 8

def current
  @current
end

#headerObject

Returns the value of attribute header.



9
10
11
# File 'lib/soundcloud2000/ui/table.rb', line 9

def header
  @header
end

#keysObject

Returns the value of attribute keys.



9
10
11
# File 'lib/soundcloud2000/ui/table.rb', line 9

def keys
  @keys
end

Instance Method Details

#bind_to(collection) ⇒ Object

Raises:

  • (ArgumentError)


22
23
24
25
26
27
28
# File 'lib/soundcloud2000/ui/table.rb', line 22

def bind_to(collection)
  raise ArgumentError if @collection

  @collection = collection
  @collection.events.on(:append) { render }
  @collection.events.on(:replace) { clear; render }
end

#body_heightObject



34
35
36
# File 'lib/soundcloud2000/ui/table.rb', line 34

def body_height
  rect.height - @header.size
end

#bottom?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/soundcloud2000/ui/table.rb', line 38

def bottom?
  current + 1 >= length
end

#deselectObject



63
64
65
66
# File 'lib/soundcloud2000/ui/table.rb', line 63

def deselect
  @selected = nil
  render
end

#downObject



50
51
52
53
54
55
56
# File 'lib/soundcloud2000/ui/table.rb', line 50

def down
  if (@current + 1) < length
    @current += 1
    @top += 1 if @current > body_height
    render
  end
end

#lengthObject



30
31
32
# File 'lib/soundcloud2000/ui/table.rb', line 30

def length
  @collection.size
end

#selectObject



58
59
60
61
# File 'lib/soundcloud2000/ui/table.rb', line 58

def select
  @selected = @current
  render
end

#upObject



42
43
44
45
46
47
48
# File 'lib/soundcloud2000/ui/table.rb', line 42

def up
  if @current > 0
    @current -= 1
    @top -= 1 if @current < @top
    render
  end
end