under-os 0.0.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +16 -0
- data/README.md +70 -0
- data/Rakefile +24 -0
- data/app/config.rb +4 -0
- data/app/layouts/alerts.html +8 -0
- data/app/layouts/calculator.html +26 -0
- data/app/layouts/collections.html +7 -0
- data/app/layouts/home.html +14 -0
- data/app/layouts/http.html +8 -0
- data/app/layouts/inputs.html +44 -0
- data/app/layouts/lockers.html +6 -0
- data/app/layouts/navbar.html +9 -0
- data/app/layouts/scrolls.html +42 -0
- data/app/layouts/sidebars.html +17 -0
- data/app/pages/alerts_page.rb +14 -0
- data/app/pages/calculator_page.rb +36 -0
- data/app/pages/collections_page.rb +9 -0
- data/app/pages/home_page.rb +11 -0
- data/app/pages/http_page.rb +33 -0
- data/app/pages/inputs_page.rb +9 -0
- data/app/pages/lockers_page.rb +16 -0
- data/app/pages/navbar_page.rb +19 -0
- data/app/pages/scrolls_page.rb +5 -0
- data/app/pages/sidebars_page.rb +42 -0
- data/app/pages/stuff_page.rb +35 -0
- data/app/styles/application.css +25 -0
- data/app/styles/calculator.css +37 -0
- data/app/styles/collections.css +19 -0
- data/app/styles/home.css +0 -0
- data/app/styles/http.css +24 -0
- data/app/styles/inputs.css +47 -0
- data/app/styles/scrolls.css +67 -0
- data/app/styles/sidebars.css +19 -0
- data/lib/assets/fontawesome-webfont.ttf +0 -0
- data/lib/assets/under-os.css +115 -0
- data/lib/under-os.rb +9 -1
- data/lib/under_os/app.rb +33 -0
- data/lib/under_os/color.rb +176 -0
- data/lib/under_os/config.rb +28 -1
- data/lib/under_os/core/kernel.rb +16 -0
- data/lib/under_os/core/numeric.rb +23 -0
- data/lib/under_os/core/string.rb +40 -0
- data/lib/under_os/delegate.rb +3 -2
- data/lib/under_os/events.rb +85 -0
- data/lib/under_os/file.rb +110 -0
- data/lib/under_os/history.rb +50 -0
- data/lib/under_os/http/receiver.rb +44 -0
- data/lib/under_os/http/request.rb +89 -0
- data/lib/under_os/http/response.rb +24 -0
- data/lib/under_os/http/session.rb +49 -0
- data/lib/under_os/http.rb +5 -0
- data/lib/under_os/page/builder.rb +96 -0
- data/lib/under_os/page/layout.rb +43 -0
- data/lib/under_os/page/matcher.rb +83 -0
- data/lib/under_os/page/stylesheet.rb +67 -0
- data/lib/under_os/page.rb +153 -0
- data/lib/under_os/parser/css.rb +37 -0
- data/lib/under_os/parser/html.rb +97 -0
- data/lib/under_os/parser.rb +24 -0
- data/lib/under_os/point.rb +47 -0
- data/lib/under_os/screen.rb +9 -0
- data/lib/under_os/timer.rb +65 -0
- data/lib/under_os/ui/alert.rb +52 -0
- data/lib/under_os/ui/button.rb +22 -0
- data/lib/under_os/ui/collection/cell.rb +21 -0
- data/lib/under_os/ui/collection/delegate.rb +68 -0
- data/lib/under_os/ui/collection/item.rb +32 -0
- data/lib/under_os/ui/collection/layout.rb +43 -0
- data/lib/under_os/ui/collection/styles.rb +15 -0
- data/lib/under_os/ui/collection.rb +63 -0
- data/lib/under_os/ui/icon/awesome.rb +376 -0
- data/lib/under_os/ui/icon/engine.rb +10 -0
- data/lib/under_os/ui/icon.rb +42 -0
- data/lib/under_os/ui/image.rb +30 -0
- data/lib/under_os/ui/input.rb +41 -0
- data/lib/under_os/ui/label.rb +21 -0
- data/lib/under_os/ui/locker.rb +42 -0
- data/lib/under_os/ui/navbar.rb +115 -0
- data/lib/under_os/ui/progress.rb +17 -0
- data/lib/under_os/ui/scroll.rb +41 -0
- data/lib/under_os/ui/select.rb +98 -0
- data/lib/under_os/ui/sidebar.rb +45 -0
- data/lib/under_os/ui/slider.rb +49 -0
- data/lib/under_os/ui/spinner.rb +23 -0
- data/lib/under_os/ui/style/fonts.rb +60 -0
- data/lib/under_os/ui/style/margins.rb +160 -0
- data/lib/under_os/ui/style/outlining.rb +98 -0
- data/lib/under_os/ui/style/positioning.rb +169 -0
- data/lib/under_os/ui/style.rb +21 -0
- data/lib/under_os/ui/switch.rb +29 -0
- data/lib/under_os/ui/textarea.rb +14 -0
- data/lib/under_os/ui/utils/animation.rb +99 -0
- data/lib/under_os/ui/utils/commons.rb +70 -0
- data/lib/under_os/ui/utils/dimensions.rb +37 -0
- data/lib/under_os/ui/utils/editable.rb +43 -0
- data/lib/under_os/ui/utils/events.rb +75 -0
- data/lib/under_os/ui/utils/manipulation.rb +44 -0
- data/lib/under_os/ui/utils/position.rb +21 -0
- data/lib/under_os/ui/utils/size.rb +21 -0
- data/lib/under_os/ui/utils/styles.rb +89 -0
- data/lib/under_os/ui/utils/traversing.rb +44 -0
- data/lib/under_os/ui/utils/wrap.rb +77 -0
- data/lib/under_os/ui/view.rb +31 -0
- data/lib/under_os/ui.rb +3 -0
- data/lib/under_os.rb +2 -2
- data/resources/Default-568h@2x.png +0 -0
- data/resources/test.png +0 -0
- data/spec/assets/app.css +13 -0
- data/spec/assets/test.css +7 -0
- data/spec/assets/test.html +3 -0
- data/spec/assets/test_page.rb +2 -0
- data/spec/lib/core/numeric_spec.rb +37 -0
- data/spec/lib/core/string_spec.rb +87 -0
- data/spec/lib/under_os/color_spec.rb +133 -0
- data/spec/lib/under_os/events_spec.rb +71 -0
- data/spec/lib/under_os/file_spec.rb +98 -0
- data/spec/lib/under_os/page/builder_spec.rb +128 -0
- data/spec/lib/under_os/page/layout_spec.rb +18 -0
- data/spec/lib/under_os/page/matcher_spec.rb +154 -0
- data/spec/lib/under_os/page/stylesheet_spec.rb +83 -0
- data/spec/lib/under_os/page_spec.rb +5 -0
- data/spec/lib/under_os/parser/css_spec.rb +77 -0
- data/spec/lib/under_os/parser/html_spec.rb +152 -0
- data/spec/lib/under_os/parser_spec.rb +16 -0
- data/spec/lib/under_os/point_spec.rb +54 -0
- data/spec/lib/under_os/screen_spec.rb +11 -0
- data/spec/lib/under_os/timer_spec.rb +93 -0
- data/spec/lib/under_os/ui/button_spec.rb +5 -0
- data/spec/lib/under_os/ui/collection_spec.rb +19 -0
- data/spec/lib/under_os/ui/icon_spec.rb +26 -0
- data/spec/lib/under_os/ui/image_spec.rb +39 -0
- data/spec/lib/under_os/ui/input_spec.rb +77 -0
- data/spec/lib/under_os/ui/label_spec.rb +22 -0
- data/spec/lib/under_os/ui/locker_spec.rb +31 -0
- data/spec/lib/under_os/ui/progress_spec.rb +31 -0
- data/spec/lib/under_os/ui/scroll_spec.rb +40 -0
- data/spec/lib/under_os/ui/select_spec.rb +131 -0
- data/spec/lib/under_os/ui/sidebar_spec.rb +35 -0
- data/spec/lib/under_os/ui/slider_spec.rb +65 -0
- data/spec/lib/under_os/ui/spinner_spec.rb +57 -0
- data/spec/lib/under_os/ui/style/fonts_spec.rb +73 -0
- data/spec/lib/under_os/ui/style/margins_spec.rb +106 -0
- data/spec/lib/under_os/ui/style/outlining_spec.rb +69 -0
- data/spec/lib/under_os/ui/style/positioning_spec.rb +69 -0
- data/spec/lib/under_os/ui/style_spec.rb +19 -0
- data/spec/lib/under_os/ui/switch_spec.rb +56 -0
- data/spec/lib/under_os/ui/textarea_spec.rb +30 -0
- data/spec/lib/under_os/ui/utils/commons_spec.rb +81 -0
- data/spec/lib/under_os/ui/utils/manipulation_spec.rb +130 -0
- data/spec/lib/under_os/ui/utils/styles_spec.rb +140 -0
- data/spec/lib/under_os/ui/utils/traversing_spec.rb +124 -0
- data/spec/lib/under_os/ui/utils/wrap_spec.rb +69 -0
- data/spec/lib/under_os/ui/view_spec.rb +39 -0
- data/under-os.gemspec +32 -0
- metadata +225 -11
- data/lib/under_os/application.rb +0 -16
- data/lib/under_os/window.rb +0 -5
@@ -0,0 +1,169 @@
|
|
1
|
+
#
|
2
|
+
# This module contains things like positions and sizes of the elements
|
3
|
+
#
|
4
|
+
module UnderOs::UI
|
5
|
+
class Style
|
6
|
+
module Positioning
|
7
|
+
def width
|
8
|
+
@view.frame.size.width
|
9
|
+
end
|
10
|
+
|
11
|
+
def width=(width)
|
12
|
+
@view.frame = [[left, top], [convert_size(width, :x), height]]
|
13
|
+
end
|
14
|
+
|
15
|
+
def height
|
16
|
+
@view.frame.size.height
|
17
|
+
end
|
18
|
+
|
19
|
+
def height=(height)
|
20
|
+
@view.frame = [[left, top], [width, convert_size(height, :y)]]
|
21
|
+
end
|
22
|
+
|
23
|
+
def top
|
24
|
+
@view.frame.origin.y
|
25
|
+
end
|
26
|
+
|
27
|
+
def top=(top)
|
28
|
+
@view.frame = [[left, convert_size(top, :y)], [width, height]]
|
29
|
+
end
|
30
|
+
|
31
|
+
def left
|
32
|
+
@view.frame.origin.x
|
33
|
+
end
|
34
|
+
|
35
|
+
def left=(left)
|
36
|
+
@view.frame = [[convert_size(left, :x), top], [width, height]]
|
37
|
+
end
|
38
|
+
|
39
|
+
def right
|
40
|
+
parent_size.x - left
|
41
|
+
end
|
42
|
+
|
43
|
+
def right=(right)
|
44
|
+
@view.frame = [[parent_size[:x] - convert_size(right, :x) - width, top], [width, height]]
|
45
|
+
end
|
46
|
+
|
47
|
+
def bottom
|
48
|
+
parent_size.y - top
|
49
|
+
end
|
50
|
+
|
51
|
+
def bottom=(bottom)
|
52
|
+
@view.frame = [[left, parent_size[:y] - convert_size(bottom, :y) - height], [width, height]]
|
53
|
+
end
|
54
|
+
|
55
|
+
def contentWidth
|
56
|
+
@view.contentSize.width rescue 0
|
57
|
+
end
|
58
|
+
|
59
|
+
def contentWidth=(value)
|
60
|
+
return unless @view.is_a?(UIScrollView)
|
61
|
+
|
62
|
+
if value == 'auto'
|
63
|
+
value = 0
|
64
|
+
@view.subviews.each do |view|
|
65
|
+
x = view.origin.x + view.size.width
|
66
|
+
value = x if x > value
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
@view.contentSize = CGSizeMake(value, contentHeight)
|
71
|
+
end
|
72
|
+
|
73
|
+
def contentHeight
|
74
|
+
@view.contentSize.height rescue 0
|
75
|
+
end
|
76
|
+
|
77
|
+
def contentHeight=(value)
|
78
|
+
return unless @view.is_a?(UIScrollView)
|
79
|
+
|
80
|
+
if value == 'auto'
|
81
|
+
value = 0
|
82
|
+
@view.subviews.each do |view|
|
83
|
+
y = view.origin.y + view.size.height
|
84
|
+
value = y if y > value
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
@view.contentSize = CGSizeMake(contentWidth, value)
|
89
|
+
end
|
90
|
+
|
91
|
+
def zIndex
|
92
|
+
@view.layer.zPosition
|
93
|
+
end
|
94
|
+
|
95
|
+
def zIndex=(number)
|
96
|
+
@view.layer.zPosition = number
|
97
|
+
end
|
98
|
+
|
99
|
+
def overflow
|
100
|
+
case "#{overflowX}-#{overflowY}"
|
101
|
+
when 'visible-visible' then :visible
|
102
|
+
when 'hidden-hidden' then :hidden
|
103
|
+
when 'visible-hidden' then :x
|
104
|
+
when 'hidden-visible' then :y
|
105
|
+
else [overflowX, overflowY]
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def overflow=(value)
|
110
|
+
x, y = case value.to_s
|
111
|
+
when 'x' then ['visible', 'hidden']
|
112
|
+
when 'y' then ['hidden', 'visible']
|
113
|
+
when 'hidden' then ['hidden', 'hidden']
|
114
|
+
else ['visible', 'visible']
|
115
|
+
end
|
116
|
+
|
117
|
+
self.overflowX = x
|
118
|
+
self.overflowY = y
|
119
|
+
end
|
120
|
+
|
121
|
+
def overflowX
|
122
|
+
@view.isScrollEnabled && @view.showsHorizontalScrollIndicator ? :visible : :hidden
|
123
|
+
end
|
124
|
+
|
125
|
+
def overflowX=(value)
|
126
|
+
return unless @view.is_a?(UIScrollView)
|
127
|
+
@view.showsHorizontalScrollIndicator = value.to_s == 'visible'
|
128
|
+
@view.directionalLockEnabled = overflowY == :hidden
|
129
|
+
@view.scrollEnabled = overflowX != :hidden || overflowY != :hidden
|
130
|
+
end
|
131
|
+
|
132
|
+
def overflowY
|
133
|
+
@view.isScrollEnabled && @view.showsVerticalScrollIndicator ? :visible : :hidden
|
134
|
+
end
|
135
|
+
|
136
|
+
def overflowY=(value)
|
137
|
+
return unless @view.is_a?(UIScrollView)
|
138
|
+
@view.showsVerticalScrollIndicator = value.to_s == 'visible'
|
139
|
+
@view.directionalLockEnabled = overflowX == :hidden
|
140
|
+
@view.scrollEnabled = overflowX != :hidden || overflowY != :hidden
|
141
|
+
end
|
142
|
+
|
143
|
+
private
|
144
|
+
|
145
|
+
def convert_size(size, dim)
|
146
|
+
if size.is_a?(String)
|
147
|
+
if size.ends_with?('%')
|
148
|
+
size = size.slice(0, size.size-1).to_f
|
149
|
+
size = parent_size[dim] / 100.0 * size
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
size
|
154
|
+
end
|
155
|
+
|
156
|
+
def parent_size
|
157
|
+
parent = view.superview
|
158
|
+
|
159
|
+
if !parent.superview && parent == UnderOs::App.history.current_page.view._
|
160
|
+
parent = UIScreen.mainScreen.bounds.size
|
161
|
+
else
|
162
|
+
parent = parent.frame.size
|
163
|
+
end
|
164
|
+
|
165
|
+
{x: parent.width, y: parent.height}
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#
|
2
|
+
# The view styles handling wrapper
|
3
|
+
#
|
4
|
+
# The idea here is to provide a DOM like `style` object,
|
5
|
+
# which can take similar to DOM properties and translate
|
6
|
+
# them into iOS equivalents
|
7
|
+
#
|
8
|
+
class UnderOs::UI::Style
|
9
|
+
include Fonts
|
10
|
+
include Margins
|
11
|
+
include Outlining
|
12
|
+
include Positioning
|
13
|
+
|
14
|
+
attr_reader :view
|
15
|
+
|
16
|
+
def initialize(view, type)
|
17
|
+
@view = view
|
18
|
+
@type = type
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class UnderOs::UI::Switch < UnderOs::UI::View
|
2
|
+
include UnderOs::UI::Editable
|
3
|
+
|
4
|
+
wraps UISwitch, tag: 'switch'
|
5
|
+
|
6
|
+
def initialize(options={})
|
7
|
+
super
|
8
|
+
|
9
|
+
self.value = options[:value] if options[:value]
|
10
|
+
self.checked = options[:checked] if options[:checked]
|
11
|
+
end
|
12
|
+
|
13
|
+
def value
|
14
|
+
@_value
|
15
|
+
end
|
16
|
+
|
17
|
+
def value=(value)
|
18
|
+
@_value = value # just saving it on the instance
|
19
|
+
end
|
20
|
+
|
21
|
+
def checked
|
22
|
+
@_.on?
|
23
|
+
end
|
24
|
+
|
25
|
+
def checked=(flag)
|
26
|
+
@_.setOn flag, animated: true
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class UnderOs::UI::Textarea < UnderOs::UI::View
|
2
|
+
include UnderOs::UI::Editable
|
3
|
+
|
4
|
+
wraps UITextView, tag: 'textarea'
|
5
|
+
|
6
|
+
def initialize(options={})
|
7
|
+
super
|
8
|
+
|
9
|
+
self.value = options[:value] if options[:value]
|
10
|
+
self.keyboard = options[:keyboard] if options[:keyboard]
|
11
|
+
end
|
12
|
+
|
13
|
+
alias :text= :value= # to get values from the HTML layouts
|
14
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
module UnderOs::UI::Animation
|
2
|
+
|
3
|
+
def animate(style, options={}, &block)
|
4
|
+
if block_given?
|
5
|
+
options = style
|
6
|
+
style = nil
|
7
|
+
else
|
8
|
+
[:complete, :curve, :autoreverse, :repeat, :duration, :delay].each do |key|
|
9
|
+
options[key] = style.delete(key) if style.has_key?(key)
|
10
|
+
end
|
11
|
+
|
12
|
+
block = Proc.new{ self.style = style }
|
13
|
+
end
|
14
|
+
|
15
|
+
Animation.new(self, options, &block)
|
16
|
+
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
def highlight(color=:yellow, options={})
|
21
|
+
old_color = style.background
|
22
|
+
|
23
|
+
animate({background: color}, {curve: :ease_out}.merge(options))
|
24
|
+
animate({background: old_color}, {curve: :ease_in}.merge(options))
|
25
|
+
end
|
26
|
+
|
27
|
+
def fade_in(options={})
|
28
|
+
animate({opacity: 1}, options)
|
29
|
+
end
|
30
|
+
|
31
|
+
def fade_out(options={})
|
32
|
+
animate({opacity: 0}, options)
|
33
|
+
end
|
34
|
+
|
35
|
+
class Animation
|
36
|
+
CURVES = {
|
37
|
+
ease_in_out: UIViewAnimationOptionCurveEaseInOut,
|
38
|
+
ease_in: UIViewAnimationOptionCurveEaseIn,
|
39
|
+
ease_out: UIViewAnimationOptionCurveEaseOut,
|
40
|
+
linear: UIViewAnimationOptionCurveLinear
|
41
|
+
}.freeze
|
42
|
+
|
43
|
+
FX_QUEUE = {}
|
44
|
+
|
45
|
+
def initialize(view, options, &block)
|
46
|
+
@view = view
|
47
|
+
@options = options
|
48
|
+
@block = block
|
49
|
+
|
50
|
+
@options[:schedule] == false ? run : schedule
|
51
|
+
end
|
52
|
+
|
53
|
+
def queue
|
54
|
+
FX_QUEUE[@view] ||= []
|
55
|
+
end
|
56
|
+
|
57
|
+
def schedule
|
58
|
+
if queue.empty?
|
59
|
+
run
|
60
|
+
else
|
61
|
+
queue << self
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def run
|
66
|
+
@view.emit('animation:start')
|
67
|
+
|
68
|
+
UIView.animateWithDuration duration,
|
69
|
+
delay: delay,
|
70
|
+
options: options,
|
71
|
+
animations: ->{ @block.call },
|
72
|
+
completion: ->(finished){ run_next }
|
73
|
+
end
|
74
|
+
|
75
|
+
def duration
|
76
|
+
@options[:duration] || 0.25
|
77
|
+
end
|
78
|
+
|
79
|
+
def delay
|
80
|
+
@options[:delay] || 0.0
|
81
|
+
end
|
82
|
+
|
83
|
+
def options
|
84
|
+
options = CURVES[@options[:curve]] || @options[:curve] || UIViewAnimationCurveEaseOut
|
85
|
+
options = options | UIViewAnimationOptionAutoreverse if @options[:autoreverse]
|
86
|
+
options = options | UIViewAnimationOptionRepeat if @options[:repeat]
|
87
|
+
options | UIViewAnimationOptionAllowUserInteraction
|
88
|
+
end
|
89
|
+
|
90
|
+
def run_next
|
91
|
+
@view.emit('animation:finished')
|
92
|
+
@options[:complete].call if @options[:complete]
|
93
|
+
|
94
|
+
if next_fx = queue.shift
|
95
|
+
next_fx.run
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module UnderOs::UI::Commons
|
2
|
+
def id
|
3
|
+
@_id
|
4
|
+
end
|
5
|
+
|
6
|
+
def id=(id)
|
7
|
+
@_id = id
|
8
|
+
end
|
9
|
+
|
10
|
+
def tagName
|
11
|
+
@_tag_name ||= begin
|
12
|
+
wraps = UnderOs::UI::Wrap::WRAPS_TAGS_MAP
|
13
|
+
klass = self.class; tag = 'VIEW'
|
14
|
+
|
15
|
+
while klass
|
16
|
+
if wrap = wraps.detect{|t,k| k == klass}
|
17
|
+
tag = wrap[0].upcase
|
18
|
+
break
|
19
|
+
else
|
20
|
+
klass = klass.superclass
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
tag
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def data(key=nil)
|
29
|
+
key && @_data ? @_data[key.to_sym] : @_data
|
30
|
+
end
|
31
|
+
|
32
|
+
def data=(hash)
|
33
|
+
@_data = hash
|
34
|
+
end
|
35
|
+
|
36
|
+
def page
|
37
|
+
resp = @_
|
38
|
+
|
39
|
+
while resp = resp.nextResponder
|
40
|
+
if resp.is_a?(UIViewController)
|
41
|
+
return resp.wrapper
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
nil
|
46
|
+
end
|
47
|
+
|
48
|
+
def hide
|
49
|
+
style.display = :none
|
50
|
+
end
|
51
|
+
|
52
|
+
def show
|
53
|
+
style.display = :block
|
54
|
+
end
|
55
|
+
|
56
|
+
def toggle
|
57
|
+
hidden ? show : hide
|
58
|
+
end
|
59
|
+
|
60
|
+
def hidden
|
61
|
+
@_.isHidden
|
62
|
+
end
|
63
|
+
|
64
|
+
def visible
|
65
|
+
!hidden
|
66
|
+
end
|
67
|
+
|
68
|
+
alias :hidden? :hidden
|
69
|
+
alias :visible? :visible
|
70
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
#
|
2
|
+
# This module handles generic ui dimensions and positions of views
|
3
|
+
#
|
4
|
+
module UnderOs::UI::Dimensions
|
5
|
+
def size(size=nil)
|
6
|
+
if size
|
7
|
+
self.size = size
|
8
|
+
self
|
9
|
+
else
|
10
|
+
@size ||= UnderOs::UI::Size.new(self)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def size=(size)
|
15
|
+
size = UnderOs::Point.new(size) # cleaning up
|
16
|
+
|
17
|
+
self.size.x = size.x if size.x
|
18
|
+
self.size.y = size.y if size.y
|
19
|
+
end
|
20
|
+
|
21
|
+
def position(position=nil)
|
22
|
+
if position
|
23
|
+
self.position = position
|
24
|
+
self
|
25
|
+
else
|
26
|
+
@position ||= UnderOs::UI::Position.new(self)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def position=(position)
|
31
|
+
position = UnderOs::Point.new(position) # cleaning up
|
32
|
+
|
33
|
+
self.position.x = position.x if position.x
|
34
|
+
self.position.y = position.y if position.y
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#
|
2
|
+
# A little trait to handle the common editable fields API
|
3
|
+
#
|
4
|
+
module UnderOs::UI::Editable
|
5
|
+
KEYBOARDS = {
|
6
|
+
default: UIKeyboardTypeDefault,
|
7
|
+
ascii: UIKeyboardTypeASCIICapable,
|
8
|
+
numeric: UIKeyboardTypeNumbersAndPunctuation,
|
9
|
+
url: UIKeyboardTypeURL,
|
10
|
+
numbers: UIKeyboardTypeNumberPad,
|
11
|
+
phone: UIKeyboardTypePhonePad,
|
12
|
+
name: UIKeyboardTypeNamePhonePad,
|
13
|
+
email: UIKeyboardTypeEmailAddress,
|
14
|
+
decimal: UIKeyboardTypeDecimalPad,
|
15
|
+
twitter: UIKeyboardTypeTwitter,
|
16
|
+
search: UIKeyboardTypeWebSearch
|
17
|
+
}
|
18
|
+
|
19
|
+
def value
|
20
|
+
@_.text
|
21
|
+
end
|
22
|
+
|
23
|
+
def value=(value)
|
24
|
+
@_.text = value
|
25
|
+
end
|
26
|
+
|
27
|
+
def placeholder
|
28
|
+
@_.placeholder
|
29
|
+
end
|
30
|
+
|
31
|
+
def placeholder=(value)
|
32
|
+
@_.placeholder = value
|
33
|
+
end
|
34
|
+
|
35
|
+
def keyboard
|
36
|
+
KEYBOARDS.detect{|n,v| v == @_.keyboardType }[0]
|
37
|
+
end
|
38
|
+
|
39
|
+
def keyboard=(keyboard)
|
40
|
+
keyboard = keyboard.to_sym if keyboard.is_a?(String)
|
41
|
+
@_.keyboardType = KEYBOARDS[keyboard] || keyboard
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
#
|
2
|
+
# Special, UI avare events API
|
3
|
+
#
|
4
|
+
module UnderOs::UI::Events
|
5
|
+
|
6
|
+
def on(event, *args, &block)
|
7
|
+
return event.map{|e,b| self.on(e,&b)}[0] || self if event.is_a?(Hash)
|
8
|
+
|
9
|
+
event, recognizer = find_recognizer_from(event)
|
10
|
+
|
11
|
+
@_.addGestureRecognizer(recognizer.alloc.initWithTarget(self, action: :emit)) if recognizer
|
12
|
+
@_.userInteractionEnabled = true
|
13
|
+
|
14
|
+
UnderOs::Events::Listeners.add(self, event, *args, block)
|
15
|
+
end
|
16
|
+
|
17
|
+
def off(event)
|
18
|
+
UnderOs::Events::Listeners.remove(self, event)
|
19
|
+
end
|
20
|
+
|
21
|
+
def emit(*event)
|
22
|
+
if event.is_a?(UIGestureRecognizer)
|
23
|
+
event = Event.new(self, event)
|
24
|
+
else
|
25
|
+
event = Event.new(self, *event)
|
26
|
+
end
|
27
|
+
|
28
|
+
UnderOs::Events::Listeners.kick(self, event, {})
|
29
|
+
end
|
30
|
+
|
31
|
+
def on=(hash)
|
32
|
+
on hash
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
RECOGNIZERS = {
|
38
|
+
tap: UITapGestureRecognizer,
|
39
|
+
pinch: UIPinchGestureRecognizer,
|
40
|
+
rotate: UIRotationGestureRecognizer,
|
41
|
+
swipe: UISwipeGestureRecognizer,
|
42
|
+
pan: UIPanGestureRecognizer,
|
43
|
+
press: UILongPressGestureRecognizer
|
44
|
+
}
|
45
|
+
|
46
|
+
# tries to figure event name and gesture recognizer
|
47
|
+
def find_recognizer_from(event)
|
48
|
+
event = event.to_sym if event.is_a?(String)
|
49
|
+
|
50
|
+
if event.is_a?(Class) && event < UIGestureRecognizer
|
51
|
+
recognizer = event
|
52
|
+
|
53
|
+
if recognizer.respond_to?(:event_name)
|
54
|
+
event = recognizer.event_name
|
55
|
+
else
|
56
|
+
RECOGNIZERS.each{ |e,r| event = e if r == recognizer }
|
57
|
+
end
|
58
|
+
|
59
|
+
elsif RECOGNIZERS[event]
|
60
|
+
recognizer = RECOGNIZERS[event]
|
61
|
+
end
|
62
|
+
|
63
|
+
[event, recognizer]
|
64
|
+
end
|
65
|
+
|
66
|
+
class Event < UnderOs::Events::Event
|
67
|
+
attr_reader :target
|
68
|
+
|
69
|
+
def initialize(view, event, params={})
|
70
|
+
@target = view
|
71
|
+
event, r = view.__send__ :find_recognizer_from, event.class if event.is_a?(UIGestureRecognizer)
|
72
|
+
super event, params
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
#
|
2
|
+
# The ui-views manipulation functionality
|
3
|
+
#
|
4
|
+
module UnderOs::UI::Manipulation
|
5
|
+
|
6
|
+
def insert(view, position=:end)
|
7
|
+
if view.is_a?(Array)
|
8
|
+
view.each{|v| insert(v, position)}
|
9
|
+
else
|
10
|
+
if position == :top
|
11
|
+
@_.insertSubview(view._, atIndex: 0)
|
12
|
+
else
|
13
|
+
@_.addSubview(view._)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
def append(*views)
|
21
|
+
views.each{|v| insert(v)}
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
def prepend(*views)
|
26
|
+
views.each{|v| insert(v, :top) }
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
30
|
+
def insertTo(view, position=nil)
|
31
|
+
view.insert(self, position)
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
def remove
|
36
|
+
@_.removeFromSuperview
|
37
|
+
self
|
38
|
+
end
|
39
|
+
|
40
|
+
def clear
|
41
|
+
children.each(&:remove)
|
42
|
+
self
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class UnderOs::UI::Position < UnderOs::Point
|
2
|
+
def initialize(view)
|
3
|
+
@view = view
|
4
|
+
end
|
5
|
+
|
6
|
+
def x
|
7
|
+
@view.style.left
|
8
|
+
end
|
9
|
+
|
10
|
+
def x=(position)
|
11
|
+
@view.style.left = position
|
12
|
+
end
|
13
|
+
|
14
|
+
def y
|
15
|
+
@view.style.top
|
16
|
+
end
|
17
|
+
|
18
|
+
def y=(position)
|
19
|
+
@view.style.top = position
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class UnderOs::UI::Size < UnderOs::Point
|
2
|
+
def initialize(view)
|
3
|
+
@view = view
|
4
|
+
end
|
5
|
+
|
6
|
+
def x
|
7
|
+
@view.style.width
|
8
|
+
end
|
9
|
+
|
10
|
+
def x=(size)
|
11
|
+
@view.style.width = size
|
12
|
+
end
|
13
|
+
|
14
|
+
def y
|
15
|
+
@view.style.height
|
16
|
+
end
|
17
|
+
|
18
|
+
def y=(size)
|
19
|
+
@view.style.height = size
|
20
|
+
end
|
21
|
+
end
|