Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
89 lines (66 sloc) 2.34 KB

Classes List and Colors List

We can see the colors list in the built-in manual.
We can also see them with the following sample code.

# sample30.rb
Shoes.app :width => 642, :height => 700, :resizable => false do
  COLORS.keys.map{|sym|sym.to_s}.sort.each do |color|
    flow :width => 160, :height => 20 do
      c = send(color)
      fill c
      rect 0, 0, 160, 20
      inscription color, :stroke => c.dark? ? white : black
    end
  end
end

sample30.png

sample30.png

_why is thinking about some more method related colors.
e.g. invert, dark?, light?, black?, white?, opaque?, transparent?
We might be able to get them in the near future.

Note

I used send() method in the above sample30. But I noticed an alternative way. See the below sample30-1.

# sample30-1.rb
Shoes.app :width => 642, :height => 700, :resizable => false do
  COLORS.sort_by{|sym,| sym.to_s}.each do |color, v|
    flow :width => 160, :height => 20 do
      fill v
      rect 0, 0, 160, 20
      inscription color, :stroke => v.dark? ? white : black
    end
  end
end

sample30-1.png

sample30-1.png

NOTE: There is no need to use .to_s in the map or sort_by method's block by right. But with Shoes 2, the below error will occur if it's ommited. I guess this is a bug of Shoes...

OMG! It's my fault. See the following.

C:\>ruby -v
ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]

C:\>irb --simple-prompt
>> a = [:z, :y, :m, :s]
=> [:z, :y, :m, :s]
>> a.sort
NoMethodError: undefined method `<=>' for :z:Symbol
        from (irb):2:in `sort'
        from (irb):2
>>

There was need to define <=> for Symbol class. Revised code is sample 30-2.

# sample30-2.rb
class ::Symbol
  def <=> other
    self.to_s <=> other.to_s
  end
end

Shoes.app :width => 642, :height => 700, :resizable => false do
  COLORS.sort_by{|sym,| sym}.each do |color, v|
    flow :width => 160, :height => 20 do
      fill v
      rect 0, 0, 160, 20
      inscription color, :stroke => v.dark? ? white : black
    end
  end
end

Policeman

The sample30.rb, sample30-1.rb and sample30-2.rb all worked well with Shoes-0.r1263.