From 4c8d184e6edf0d5c9a4c662f368bf3ca41ac3237 Mon Sep 17 00:00:00 2001 From: David Larrabee Date: Fri, 12 Dec 2014 22:59:33 -0500 Subject: [PATCH] Adds ability to pass HSVA color params directly --- motion/ruby_motion_query/color.rb | 6 ++++++ spec/color.rb | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/motion/ruby_motion_query/color.rb b/motion/ruby_motion_query/color.rb index 57b9069..c343b0d 100644 --- a/motion/ruby_motion_query/color.rb +++ b/motion/ruby_motion_query/color.rb @@ -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] diff --git a/spec/color.rb b/spec/color.rb index a2c0920..54a7bdb 100644 --- a/spec/color.rb +++ b/spec/color.rb @@ -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