Sha256: 599e4f5a6ca12792d7458d6c6de4a8aa4ba93237a70a76b13b62b15f65ff07e0

Contents?: true

Size: 1.21 KB

Versions: 7

Compression:

Stored size: 1.21 KB

Contents

# ** What is a Section? **
#
# "Section" is something like "partial" which you may know from RubyOnRails. 
# In the first look it's just a list of elements which will be added to the "Screen".
# But the magic is inside. 
# When you add "Element" to a "Section", e.g. image or label, 
# it will try to draw it using CALayer/CGContext/etc, instead of adding new UIView.
# That way increases application speed (especially on Table elements) by 5-10 times.
#
# Let's get started.
---

# ** Create a section. **
#
# Just inherit it from `Prime::Section`.

class FooSection < Prime::Section
end

# ** Add some elements to the section. **
#
# Each element should have name and type: "image", "label", "button", etc. 
# When you send `:text` option, type will be "label" by default.
# When you send `:image` option, type will be "image" by default.

class FooSection < Prime::Section
  element :welcome, text: 'Hello World!'
  element :avatar, image: 'images/users/avatar.jpg'
  element :cheer, type: :button
end

# ** Render Section in Screen **
# 
# NOTE: You must send "screen" option on section initialization.

class FooScreen < Prime::Screen
  def render
    @main_section = FooSection.new(screen: self)
    @main_section.render
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
motion-prime-0.5.6 doc/code/sections.rb
motion-prime-0.5.5 doc/code/sections.rb
motion-prime-0.5.4 doc/code/sections.rb
motion-prime-0.5.3 doc/code/sections.rb
motion-prime-0.5.2 doc/code/sections.rb
motion-prime-0.5.1 doc/code/sections.rb
motion-prime-0.5.0 doc/code/sections.rb