motion-prime 0.9.9.1 → 0.9.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CHANGELOG.md +3 -0
- data/Gemfile.lock +2 -2
- data/files/Gemfile +1 -1
- data/motion-prime/elements/_content_text_mixin.rb +2 -3
- data/motion-prime/elements/base_element.rb +6 -2
- data/motion-prime/elements/draw.rb +1 -1
- data/motion-prime/elements/draw/image.rb +1 -2
- data/motion-prime/elements/draw/label.rb +6 -0
- data/motion-prime/sections/grid.rb +1 -1
- data/motion-prime/support/_control_content_alignment.rb +2 -1
- data/motion-prime/version.rb +1 -1
- data/motion-prime/views/_frame_calculator_mixin.rb +16 -6
- data/motion-prime/views/view_builder.rb +14 -1
- data/spec/unit/elements/label_spec.rb +94 -0
- data/spec/unit/support/frame_calculator_mixin_spec.rb +33 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZmRjOTcxMGQ4OTVhODgwZjk1MmUyZjY3YWQxNDc2ODk3MDc2MTE5Yg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OWY3OTg1M2M3ZDk3ZDg0MjY1NjAyMGRkM2M2ZTU1YzJkM2VjYjQ1MQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ODhiZjRjNDJjMTY3ZDkzOTEzOGUzMmNkYWZiOWI3MjQ4NDlmMzRjZjNlM2Mw
|
10
|
+
NzIxZTQ5MzlkZThmYmIzMTkxNWMzNDFmNmZjOTc4YjZmYTdlYmQ0YTliODZm
|
11
|
+
MTMxMjQ2NmUwYjIyNjA1MmQ3MWVkOThlY2UzZTRmODg5NTQzNDE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NmYzMTFhZDQ0MzFiNjIyODczZmZkZjdiYjQzNTFhY2FjOTA0MmIyNzdjMjE1
|
14
|
+
ODg4OWViMjAzOGQ3MTU0YTJiNDI5NWQyMDBmMDZiZGM5OTMxMDY3MjFlZGYx
|
15
|
+
MGJlODc3NDc1OTYwNmY0MzMwYWE1YTZkMzU1Njk3NzkxM2RkOWM=
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
motion-prime (0.9.9.
|
4
|
+
motion-prime (0.9.9.2)
|
5
5
|
activesupport
|
6
6
|
afmotion (~> 2.1.0)
|
7
7
|
bubble-wrap (~> 1.6.0)
|
@@ -65,7 +65,7 @@ GEM
|
|
65
65
|
open4 (1.3.3)
|
66
66
|
rake (10.3.1)
|
67
67
|
rm-digest (0.0.2)
|
68
|
-
sugarcube (1.6.
|
68
|
+
sugarcube (1.6.2)
|
69
69
|
thor (0.19.1)
|
70
70
|
xcodeproj (0.16.1)
|
71
71
|
activesupport (~> 3.0)
|
data/files/Gemfile
CHANGED
@@ -41,7 +41,7 @@ module MotionPrime
|
|
41
41
|
|
42
42
|
def width_for_attributed_text(attributed_text)
|
43
43
|
min, max = computed_options[:min_width].to_f, computed_options[:max_width]
|
44
|
-
return min if attributed_text.blank?
|
44
|
+
return min if attributed_text.to_s.blank?
|
45
45
|
|
46
46
|
rect = get_content_rect(attributed_text, Float::MAX)
|
47
47
|
[[rect.size.width.ceil, max].compact.min, min].max.ceil
|
@@ -61,8 +61,7 @@ module MotionPrime
|
|
61
61
|
|
62
62
|
def height_for_attributed_text(attributed_text)
|
63
63
|
min, max = computed_options[:min_height].to_f, computed_options[:max_height]
|
64
|
-
return min if attributed_text.blank?
|
65
|
-
|
64
|
+
return min if attributed_text.to_s.blank?
|
66
65
|
rect = get_content_rect(attributed_text, computed_options[:width] - content_padding_width)
|
67
66
|
[[rect.size.height.ceil, max].compact.min, min].max.ceil
|
68
67
|
end
|
@@ -96,17 +96,21 @@ module MotionPrime
|
|
96
96
|
compute_options!
|
97
97
|
end
|
98
98
|
|
99
|
-
def rerender!
|
99
|
+
def rerender!(changed_options = [])
|
100
100
|
render_target = view.try(:superview)
|
101
101
|
view.try(:removeFromSuperview)
|
102
102
|
render(render_target: render_target)
|
103
|
+
|
104
|
+
if (changed_options & [:text, :size_to_fit]).any? && respond_to?(:size_to_fit)
|
105
|
+
size_to_fit
|
106
|
+
end
|
103
107
|
section.try(:on_element_render, self)
|
104
108
|
end
|
105
109
|
|
106
110
|
def update_with_options(new_options = {})
|
107
111
|
options.merge!(new_options)
|
108
112
|
reload!
|
109
|
-
rerender!
|
113
|
+
rerender!(new_options.keys)
|
110
114
|
end
|
111
115
|
|
112
116
|
def update_options(new_options)
|
@@ -15,8 +15,7 @@ module MotionPrime
|
|
15
15
|
def draw_in(rect)
|
16
16
|
return if computed_options[:hidden]
|
17
17
|
draw_background_in_context(UIGraphicsGetCurrentContext())
|
18
|
-
|
19
|
-
if computed_options[:draw_in_rect] || view.is_a?(MPCollectionCellWithSection)
|
18
|
+
if computed_options[:draw_in_rect]
|
20
19
|
draw_in_context(UIGraphicsGetCurrentContext())
|
21
20
|
else
|
22
21
|
draw_with_layer
|
@@ -94,6 +94,12 @@ module MotionPrime
|
|
94
94
|
computed_options[:width] ||= cached_content_outer_width
|
95
95
|
computed_options[:height] ||= cached_content_outer_height
|
96
96
|
reset_computed_values
|
97
|
+
elsif computed_options.slice(:width, :left, :right).values.none?
|
98
|
+
computed_options[:width] ||= cached_content_outer_width
|
99
|
+
reset_computed_values
|
100
|
+
elsif computed_options.slice(:height, :top, :bottom).values.none?
|
101
|
+
computed_options[:height] ||= cached_content_outer_height
|
102
|
+
reset_computed_values
|
97
103
|
end
|
98
104
|
end
|
99
105
|
|
@@ -20,7 +20,8 @@ module MotionPrime
|
|
20
20
|
padding_top.to_i
|
21
21
|
else # center label
|
22
22
|
padding_top_offset = padding_top.to_i - (self.paddingBottom || self.padding).to_i
|
23
|
-
(bounds_height - line_height)/2 +
|
23
|
+
(bounds_height - line_height)/2 + padding_top_offset
|
24
|
+
# TODO: check in which cases we should add `1` here
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
data/motion-prime/version.rb
CHANGED
@@ -23,31 +23,41 @@ module MotionPrime
|
|
23
23
|
temp_height = height || 0.0
|
24
24
|
|
25
25
|
if left && left > 0 && left <= 1 && value_type != 'absolute' && left.is_a?(Float)
|
26
|
-
left = max_width * left
|
26
|
+
left = (max_width * left).round(2)
|
27
27
|
end
|
28
28
|
|
29
29
|
if right && right > 0 && right <= 1 && value_type != 'absolute' && right.is_a?(Float)
|
30
|
-
right = max_width * right
|
30
|
+
right = (max_width * right).round(2)
|
31
|
+
end
|
32
|
+
|
33
|
+
if top && top > 0 && top <= 1 && value_type != 'absolute' && top.is_a?(Float)
|
34
|
+
top = (max_height * top).round(2)
|
35
|
+
end
|
36
|
+
|
37
|
+
if bottom && bottom > 0 && bottom <= 1 && value_type != 'absolute' && bottom.is_a?(Float)
|
38
|
+
bottom = (max_height * bottom).round(2)
|
31
39
|
end
|
32
40
|
|
33
41
|
# calculate left and right if width is relative, e.g 0.7
|
34
42
|
if width && width > 0 && width <= 1 && value_type != 'absolute' && width.is_a?(Float)
|
35
43
|
if right.nil?
|
36
44
|
left ||= 0
|
37
|
-
right = max_width - max_width * width - left
|
45
|
+
right = (max_width - max_width * width - left).round(2)
|
38
46
|
else
|
39
|
-
left = max_width - max_width * width - right
|
47
|
+
left = (max_width - max_width * width - right).round(2)
|
40
48
|
end
|
49
|
+
width = (max_width * width).round(2)
|
41
50
|
end
|
42
51
|
|
43
52
|
# calculate top and bottom if height is relative, e.g 0.7
|
44
53
|
if height && height > 0 && height <= 1 && value_type != 'absolute' && height.is_a?(Float)
|
45
54
|
if bottom.nil?
|
46
55
|
top ||= 0
|
47
|
-
bottom = max_height - max_height * height
|
56
|
+
bottom = (max_height - max_height * height - top).round(2)
|
48
57
|
else
|
49
|
-
top = max_height - max_height * height
|
58
|
+
top = (max_height - max_height * height - bottom).round(2)
|
50
59
|
end
|
60
|
+
height = (max_height * height).round(2)
|
51
61
|
end
|
52
62
|
|
53
63
|
if !left.nil? && !right.nil?
|
@@ -89,7 +89,20 @@ module MotionPrime
|
|
89
89
|
'UICollectionView' => Proc.new{|klass, options|
|
90
90
|
unless layout = options.delete(:layout)
|
91
91
|
layout = UICollectionViewFlowLayout.alloc.init
|
92
|
-
total_width = options[:parent_bounds].size.width / (options.delete(:grid_size) ||
|
92
|
+
total_width = options[:parent_bounds].size.width / (options.delete(:grid_size) || 3)
|
93
|
+
if horizontal_spacing = options.delete(:horizontal_spacing)
|
94
|
+
layout.setMinimumInteritemSpacing horizontal_spacing
|
95
|
+
end
|
96
|
+
if vertical_spacing = options.delete(:vertical_spacing)
|
97
|
+
layout.setMinimumLineSpacing vertical_spacing
|
98
|
+
end
|
99
|
+
if scroll_direction = options.delete(:scroll_direction)
|
100
|
+
if scroll_direction == :horizontal
|
101
|
+
layout.setScrollDirection UICollectionViewScrollDirectionHorizontal
|
102
|
+
else
|
103
|
+
layout.setScrollDirection UICollectionViewScrollDirectionVertical
|
104
|
+
end
|
105
|
+
end
|
93
106
|
width = total_width - layout.minimumInteritemSpacing
|
94
107
|
layout.setItemSize CGSizeMake(width, options.delete(:item_height) || 100)
|
95
108
|
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
describe MotionPrime::Section do
|
2
|
+
before do
|
3
|
+
@screen = BaseScreen.new
|
4
|
+
end
|
5
|
+
|
6
|
+
describe "view label" do
|
7
|
+
before do
|
8
|
+
@section = SampleViewSection.new(screen: @screen)
|
9
|
+
@section.create_elements
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "size_to_fit option" do
|
13
|
+
before do
|
14
|
+
@section.element(:description).options.merge!({
|
15
|
+
text: '',
|
16
|
+
size_to_fit: true
|
17
|
+
})
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should set zero size" do
|
21
|
+
@section.render
|
22
|
+
@section.view(:description).bounds.size.width.should.be.zero
|
23
|
+
@section.view(:description).bounds.size.height.should.be.zero
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should update bounds with text" do
|
27
|
+
@section.render
|
28
|
+
@section.element(:description).update_with_options(text: 'test')
|
29
|
+
@section.view(:description).bounds.size.width.should > 0
|
30
|
+
@section.view(:description).bounds.size.height.should > 0
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# describe "`top` with zero `height`" do
|
35
|
+
# before do
|
36
|
+
# @section.element(:description).options.merge!({
|
37
|
+
# top: 20
|
38
|
+
# })
|
39
|
+
# end
|
40
|
+
|
41
|
+
# it "should set top" do
|
42
|
+
# @section.render
|
43
|
+
# @section.view(:description).origin.y.should == 20
|
44
|
+
# end
|
45
|
+
# end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "draw label" do
|
49
|
+
before do
|
50
|
+
@section = SampleDrawSection.new(screen: @screen)
|
51
|
+
@section.create_elements
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "size_to_fit option" do
|
55
|
+
before do
|
56
|
+
@section.element(:description).options.merge!({
|
57
|
+
text: '',
|
58
|
+
size_to_fit: true
|
59
|
+
})
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should set zero size" do
|
63
|
+
@section.render
|
64
|
+
@section.element(:description).size_to_fit_if_needed
|
65
|
+
@section.element(:description).computed_options[:width].should.be.zero
|
66
|
+
@section.element(:description).computed_options[:height].should.be.zero
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should update bounds with text" do
|
70
|
+
@section.render
|
71
|
+
@section.element(:description).update_with_options(text: 'test')
|
72
|
+
@section.element(:description).size_to_fit_if_needed
|
73
|
+
@section.element(:description).computed_options[:width].should > 0
|
74
|
+
@section.element(:description).computed_options[:height].should > 0
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "`top` with zero `height`" do
|
79
|
+
before do
|
80
|
+
@section.element(:description).options.merge!({
|
81
|
+
top: 20
|
82
|
+
})
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should set top" do
|
86
|
+
@section.render
|
87
|
+
@section.container_view.bounds = UIScreen.mainScreen.bounds
|
88
|
+
@section.element(:description).size_to_fit_if_needed
|
89
|
+
@section.element(:description).draw_options[:top_left_corner].y.should == 20
|
90
|
+
@section.element(:description).draw_options[:inner_rect].origin.y.should == 20
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -40,4 +40,37 @@ describe MotionPrime::FrameCalculatorMixin do
|
|
40
40
|
result = @subject.calculate_frame_for(@parent_bounds, {width: 100, left: 10, right: 10})
|
41
41
|
result.size.width.should == 100
|
42
42
|
end
|
43
|
+
|
44
|
+
it "should calculate relative width" do
|
45
|
+
result = @subject.calculate_frame_for(@parent_bounds, {width: 0.5})
|
46
|
+
result.size.width.should == 150
|
47
|
+
result.origin.x.should == 0
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should calculate relative height" do
|
51
|
+
result = @subject.calculate_frame_for(@parent_bounds, {height: 0.5})
|
52
|
+
result.size.height.should == 100
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should calculate left based on relative width and absolute right" do
|
56
|
+
result = @subject.calculate_frame_for(@parent_bounds, {width: 0.5, right: 70})
|
57
|
+
result.origin.x.should == 80
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should calculate top based on relative height and absolute bottom" do
|
61
|
+
result = @subject.calculate_frame_for(@parent_bounds, {height: 0.5, bottom: 70})
|
62
|
+
result.origin.y.should == 30
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should calculate relative left and width" do
|
66
|
+
result = @subject.calculate_frame_for(@parent_bounds, {left: 0.2, width: 0.4})
|
67
|
+
result.origin.x.should == 60
|
68
|
+
result.size.width.should == 120
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should calculate relative top and height" do
|
72
|
+
result = @subject.calculate_frame_for(@parent_bounds, {top: 0.2, height: 0.4})
|
73
|
+
result.origin.y.should == 40
|
74
|
+
result.size.height.should == 80
|
75
|
+
end
|
43
76
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: motion-prime
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.9.
|
4
|
+
version: 0.9.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Iskander Haziev
|
@@ -400,6 +400,7 @@ files:
|
|
400
400
|
- spec/helpers/has_content.rb
|
401
401
|
- spec/unit/config/store_spec.rb
|
402
402
|
- spec/unit/delegate/delegate_spec.rb
|
403
|
+
- spec/unit/elements/label_spec.rb
|
403
404
|
- spec/unit/models/association_collection_spec.rb
|
404
405
|
- spec/unit/models/associations_spec.rb
|
405
406
|
- spec/unit/models/bag_spec.rb
|
@@ -459,6 +460,7 @@ test_files:
|
|
459
460
|
- spec/helpers/has_content.rb
|
460
461
|
- spec/unit/config/store_spec.rb
|
461
462
|
- spec/unit/delegate/delegate_spec.rb
|
463
|
+
- spec/unit/elements/label_spec.rb
|
462
464
|
- spec/unit/models/association_collection_spec.rb
|
463
465
|
- spec/unit/models/associations_spec.rb
|
464
466
|
- spec/unit/models/bag_spec.rb
|