Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

69 lines (51 sloc) 1.832 kb

Style

We can change the style of an element with the style method, whereas calling the method without arguments returns a hash of the styles presently applied to the element.

More information can be found in section 6.3, Styling Master List

# sample26.rb
Shoes.app :width => 400, :height => 250 do
  def sampling
    stack(:width => 1.0){para 'p: pause  r: restart'}
    #stack(:width => 0.5){@o = oval 0, 0, 50}
    stack(:width => 0.5){@r = rect 0, 0, 50, 50, 10}
    stack(:width => 0.5){@p = para ''}

    @a = every(1) do
      @r.style :width => 10 + rand(100), :height => 10 + rand(100),
                  :curve => rand(20),
                  :fill => send( COLORS.keys[rand COLORS.keys.length] ),
                  :strokewidth => rand(10),
                  :stroke => send( COLORS.keys[rand COLORS.keys.length])
      @r.move rand(100), rand(100)
      @p.replace @r.style.to_a.map{|e| e.join(': ')}.join("\n")
    end
  end

  sampling
  keypress do |k|
    case k
      when 'p'
        @a.stop
      when 'r'
        @a.stop if @a
        clear{sampling}
      else
    end
  end
end

sample26.png

sample26.png

We can style an entire class of elements at a time like this:

# sample56.rb
Shoes.app :width => 200, :height => 160 do
  style Para, :align => 'center', :stroke => pink, :size => 30
  stack do
    para "hello"
    para "hello", :size => 10, :stroke => red
    para "hello"
  end
end

sample56.png

sample56.png

Policeman

The sample26.rb worked well with Shoes-0.r1263. It also shows one more style, cap with no value, though.

The sample56.rb worked well.

Jump to Line
Something went wrong with that request. Please try again.