Adds ability to pass HSVA color params directly

This commit is contained in:
David Larrabee
2014-12-12 22:59:33 -05:00
parent 3487e3fc55
commit 4c8d184e6e
2 changed files with 10 additions and 1 deletions

View File

@@ -13,6 +13,12 @@ module RubyMotionQuery
b = param[:blue] || param[:b]
a = param[:alpha] || param[:a]
Color.new_from_rgba(r, g, b, a)
elsif (param.keys - [:h, :s, :b, :a, :hue, :saturation, :brightness, :alpha]).empty?
h = param[:hue] || param[:h]
s = param[:saturation] || param[:s]
b = param[:brightness] || param[:b]
a = param[:alpha] || param[:a]
Color.from_hsva(h, s, b, a)
else
color = Color.new_from_hex(param[:x] || param[:hex])
if alpha = param[:a] || param[:alpha]

View File

@@ -171,6 +171,9 @@ describe 'color' do
@rmq.color(red: 10, green: 10, blue: 10, alpha: 1).should == UIColor.colorWithRed(10/255.0, green: 10/255.0, blue: 10/255.0, alpha: 1)
end
#TODO HSL(A)
it 'should allow hsva params in a hash' do
@rmq.color(h: 4, s: 3, b: 2, a: 1).should == UIColor.alloc.initWithHue(4, saturation: 3, brightness: 2, alpha: 1)
@rmq.color(hue: 4, saturation: 3, brightness: 2, alpha: 1).should == UIColor.alloc.initWithHue(4, saturation: 3, brightness: 2, alpha: 1)
end
end
end