Class: Soundcloud9000::UI::Table

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

Overview

responsible for drawing our table of tracks

Direct Known Subclasses

Views::TracksTable

Constant Summary collapse

SEPARATOR =
'  |  '.freeze

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.



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

def initialize(*args)
  super

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

  reset
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



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

def collection
  @collection
end

#currentObject (readonly)

Returns the value of attribute current.



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

def current
  @current
end

#headerObject

Returns the value of attribute header.



10
11
12
# File 'lib/soundcloud9000/ui/table.rb', line 10

def header
  @header
end

#keysObject

Returns the value of attribute keys.



10
11
12
# File 'lib/soundcloud9000/ui/table.rb', line 10

def keys
  @keys
end

Instance Method Details

#bind_to(collection) ⇒ Object

Raises:

  • (ArgumentError)


24
25
26
27
28
29
30
# File 'lib/soundcloud9000/ui/table.rb', line 24

def bind_to(collection)
  raise ArgumentError if @collection

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

#body_heightObject



36
37
38
# File 'lib/soundcloud9000/ui/table.rb', line 36

def body_height
  rect.height - @header.size
end

#bottom?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/soundcloud9000/ui/table.rb', line 40

def bottom?
  current + 1 >= length
end

#deselectObject



72
73
74
75
# File 'lib/soundcloud9000/ui/table.rb', line 72

def deselect
  @selected = nil
  render
end

#downObject



52
53
54
55
56
57
58
# File 'lib/soundcloud9000/ui/table.rb', line 52

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

#lengthObject



32
33
34
# File 'lib/soundcloud9000/ui/table.rb', line 32

def length
  @collection.size
end

#randomObject



60
61
62
63
64
65
# File 'lib/soundcloud9000/ui/table.rb', line 60

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

#selectObject



67
68
69
70
# File 'lib/soundcloud9000/ui/table.rb', line 67

def select
  @selected = @current
  render
end

#upObject



44
45
46
47
48
49
50
# File 'lib/soundcloud9000/ui/table.rb', line 44

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