Class: UnderOs::UI::Collection

Inherits:
View
  • Object
show all
Defined in:
lib/under_os/ui/collection.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Collection

Returns a new instance of Collection.



4
5
6
7
8
9
10
11
12
13
# File 'lib/under_os/ui/collection.rb', line 4

def initialize(options={})
  super

  self.layout = Layout.new                          if ! options[:layout]
  self.layout = options.delete(:layout)             if options[:layout].is_a?(Class)
  self.layout = options.delete(:layout).constantize if options[:layout].is_a?(String)

  @_.delegate = @_.dataSource = Delegate.new(self)
  @_.registerClass(Cell, forCellWithReuseIdentifier:'UOSCollectionCell')
end

Instance Method Details

#item_classObject



33
34
35
# File 'lib/under_os/ui/collection.rb', line 33

def item_class
  Cell.classes[self]
end

#item_class=(klass) ⇒ Object



37
38
39
# File 'lib/under_os/ui/collection.rb', line 37

def item_class=(klass)
  Cell.classes[self] = klass
end

#layoutObject



24
25
26
# File 'lib/under_os/ui/collection.rb', line 24

def layout
  @layout
end

#layout=(layout) ⇒ Object



28
29
30
31
# File 'lib/under_os/ui/collection.rb', line 28

def layout=(layout)
  layout = Layout.new(layout) if layout.is_a?(UICollectionViewLayout)
  @_.collectionViewLayout = (@layout = layout)._
end

#number_of_items(section = 0) ⇒ Object



46
47
48
# File 'lib/under_os/ui/collection.rb', line 46

def number_of_items(section=0)
  (@number_of_items || [0])[section]
end

#number_of_items=(value) ⇒ Object



50
51
52
53
# File 'lib/under_os/ui/collection.rb', line 50

def number_of_items=(value)
  @number_of_items = value.is_a?(Numeric) ? [value] : value
  reload
end

#number_of_sectionsObject



55
56
57
# File 'lib/under_os/ui/collection.rb', line 55

def number_of_sections
  (@number_of_items || [0]).size
end

#on(*args, &block) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/under_os/ui/collection.rb', line 15

def on(*args, &block)
  super *args do |event|
    params = [event.item, event.index, event.section]
    params = params.slice(0, block.arity) if block.arity > -1

    block.call *params
  end
end

#reloadObject



41
42
43
44
# File 'lib/under_os/ui/collection.rb', line 41

def reload
  @_.reloadData
  self
end

#repaint(stylesheet = nil) ⇒ Object



59
60
61
62
63
64
# File 'lib/under_os/ui/collection.rb', line 59

def repaint(stylesheet=nil)
  stylesheet ||= page && page.stylesheet

  self.style = stylesheet.styles_for(self) if stylesheet
  Styles.build(self, stylesheet)           if stylesheet
end