"It's not a bug. It's a feature!" ;)
I agree you are absolutely correct with the explanation what's going on. However I'm not sure is it a bug or a feature indeed. Things may go wrong if the Widget class will be changed in the future and simply misuse some values in the legacy code. What if the Widget class will get some extra features, for example a :data value, which could be currently used by my custom widget Cell. I think such things should be done explicitly in the constructor. Now they are handled in the background method. On the other hand, perhaps the simple specification would be enough? A middle class in the inheritance hierarchy? Or the explicit class like AbstractWidget? No idea.

sw

Wiadomość napisana w dniu 2009-01-24, o godz. 18:47, przez Krzysztof B. Wicher:

I do not think it is a bug:
----in case of cell1 you create a widget with a hash which specifies its dimensions to h=100 and w=100 and than you start to paint starting from 100(x) etc so de facto you are painting outside the widget display area. If you change your paint method to:
 def paint
   fill(white)
   rect(0, 0, @width, @height)
   line(0, 0, @width, 0)
   line(0, 0, 0,  @height)
   line(@width, 0, @width, @height)
   line(0,  @height, @width,  @height)
end
everything is OK, right?

----for cell2 you do not specify any widget parameters explicitly so it is an "open" slot onto which you paint rectangle and lines and use up as much space as necessary.

This is how I understand what happens.

Hope it helps

Krzys

On Sat, Jan 24, 2009 at 4:23 PM, Szymon Wrozynski sw <[email protected]> wrote:
Hello,

Could you point me what's wrong here?

The code:

class Cell1 < Shoes::Widget
 def initialize(opts={})
   @x = opts[:x]
   @y = opts[:y]
   @width = opts[:width]
   @height = opts[:height]
   paint
 end

 def paint
   fill(white)
   rect(@x, @y, @width, @height)
   line(@x, @y, @x + @width, @y)
   line(@x, @y, @x, @y + @height)
   line(@x + @width, @y, @x + @width, @y + @height)
   line(@x, @y + @height, @x + @width, @y + @height)
 end
end

class Cell2 < Shoes::Widget
 def initialize(x, y, width, height)
   @x = x
   @y = y
   @width = width
   @height = height
   paint
 end

 def paint
   fill(white)
   rect(@x, @y, @width, @height)
   line(@x, @y, @x + @width, @y)
   line(@x, @y, @x, @y + @height)
   line(@x + @width, @y, @x + @width, @y + @height)
   line(@x, @y + @height, @x + @width, @y + @height)
 end
end

Shoes.app do
 cell1(:x=>100, :y=>100, :width=>100, :height=>100) # doesn't work!!
 cell2(100, 100, 100, 100) # works ok
end


The paint methods are the same.
Is it a bug? Why it doesn't work while passing a hash? The console says nothing.

As usually any help will be blessed.

kind regards

sw


Reply via email to