Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
72 lines (56 sloc) 1.71 KB

The Widget class

A custom Shoes widget is set up by inheriting from the Widget class. Shoes then creates a method using the lowercased name of the class which is used in your app.

# sample22.rb
class Shoes::Answer < Shoes::Widget
  attr_reader :mark
  def initialize word
    para word
    @mark = image('../images/loogink.png', :width => 20, :height => 20).hide
  end
end

Shoes.app :width => 200, :height => 130 do
  stack :width => 0.5 do
    background palegreen
    para '1. apple'
    ans = answer '2. tomato'
    para '3. orange'
    button('Ans.'){ans.mark.toggle}
  end
  stack :width => 0.5 do
    background lightsteelblue
    para '1. cat'
    para '2. dog'
    ans = answer '3. bird'
    button('Ans.'){ans.mark.toggle}
  end
end

sample22.png

sample22.png

One more example

We can use :left and :top without definition in the custom class attributes, because they are inherited from Shoes::Widget.

# sample49.rb
class Shoes::Widgy < Shoes::Widget
  def initialize opts = {}
    size = opts[:size] || 50
    fill opts[:color] || yellow
    rect 0, 0, size, size
  end
end

Shoes.app :width => 300, :height => 300 do
  w1 = widgy :left => 50, :top => 50, :color => red
  w2 = widgy :left => 50, :top => 50, :color => blue, :size => 100
  w2.move 100, 100
  w3 = widgy
  w3.left = 200
  w3.top = 200
end

sample49.png

sample49.png

Original idea was provided by Emanue Carnevale, in the Shoes ML.

Policeman

The sample22.rb and sample49.rb worked well with Shoes-0.r1263