Browse Source

Better colorify handling on stroke, fill, and text colors

dev
Andy Meneely 12 years ago
parent
commit
c2f6ff6e03
  1. 2
      lib/squib/api/text.rb
  2. 12
      lib/squib/input_helpers.rb

2
lib/squib/api/text.rb

@ -34,7 +34,7 @@ module Squib
# @return [nil] Returns nothing # @return [nil] Returns nothing
# @api public # @api public
def text(opts = {}) def text(opts = {})
opts = needs(opts, [:range, :str, :font, :x, :y, :width, :height, :text_color, :wrap, opts = needs(opts, [:range, :str, :font, :x, :y, :width, :height, :color, :wrap,
:align, :justify, :valign, :ellipsize, :hint, :layout]) :align, :justify, :valign, :ellipsize, :hint, :layout])
opts[:str] = [opts[:str]] * @cards.size unless opts[:str].respond_to? :each opts[:str] = [opts[:str]] * @cards.size unless opts[:str].respond_to? :each
opts[:range].each do |i| opts[:range].each do |i|

12
lib/squib/input_helpers.rb

@ -15,6 +15,8 @@ module Squib
opts = fileify(opts, false, false) if params.include? :file_to_save opts = fileify(opts, false, false) if params.include? :file_to_save
opts = fileify(opts, true, false) if params.include? :files opts = fileify(opts, true, false) if params.include? :files
opts = colorify(opts) if params.include? :color opts = colorify(opts) if params.include? :color
opts = colorify(opts, false, :fill_color) if params.include? :fill_color
opts = colorify(opts, false, :stroke_color) if params.include? :stroke_color
opts = colorify(opts, true) if params.include? :nillable_color opts = colorify(opts, true) if params.include? :nillable_color
opts = dirify(opts) if params.include? :dir opts = dirify(opts) if params.include? :dir
opts = dirify(opts, true) if params.include? :creatable_dir opts = dirify(opts, true) if params.include? :creatable_dir
@ -96,12 +98,12 @@ module Squib
# :nodoc: # :nodoc:
# @api private # @api private
def colorify(opts, nillable=false) def colorify(opts, nillable=false, key=:color)
return opts if nillable && opts[:color].nil? return opts if nillable && opts[key].nil?
if @custom_colors.key? opts[:color].to_s if @custom_colors.key? opts[key].to_s
opts[:color] = @custom_colors[opts[:color].to_s] opts[key] = @custom_colors[opts[key].to_s]
end end
opts[:color] = Cairo::Color.parse(opts[:color]) opts[key] = Cairo::Color.parse(opts[key])
opts opts
end end
module_function :colorify module_function :colorify

Loading…
Cancel
Save