Class: UnderOs::UI::Collection

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

Defined Under Namespace

Classes: Cell, Delegate, Item, Styles

Constant Summary

Constants included from Wrap

Wrap::INSTANCES_CACHE, Wrap::RAW_WRAPS_MAP, Wrap::WRAPS_TAGS_MAP

Instance Method Summary collapse

Methods inherited from View

#inspect

Methods included from Manipulation

#append, #clear, #insert, #insertTo, #prepend, #remove

Methods included from Traversing

#children, #empty?, #find, #first, #matches, #parent, #siblings

Methods included from Dimensions

#position, #position=, #size, #size=

Methods included from Animation

#animate, #fade_in, #fade_out, #highlight

Methods included from Commons

#data, #data=, #hidden, #hide, #id, #id=, #page, #show, #tagName, #toggle, #visible

Methods included from Styles

#addClass, #className, #className=, #classNames, #classNames=, #hasClass, #radioClass, #removeClass, #style, #style=, #toggleClass

Methods included from Events

#emit, #off, #on=

Methods included from Wrap

included

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



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

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

#number_of_items=(value) ⇒ Object



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

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

#number_of_sectionsObject



53
54
55
# File 'lib/under_os/ui/collection.rb', line 53

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].compact
    params = params.slice(0, block.arity) if block.arity > -1

    block.call *params
  end
end

#reloadObject



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

def reload
  @_.reloadData
end

#repaint(stylesheet = nil) ⇒ Object



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

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

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