On 17.11.2008, at 20:07 , _why wrote:

On Mon, Nov 17, 2008 at 02:39:32PM +0000, Einar Magnús Boson wrote:
My problem now is that inside my widget's `initialize` stack.width is 0,
owner is nil and parent.width is 0.
only later do the widths take on values. I can't find where to put the
logic to get the width of my container to draw. I tried this:

http://pastie.org/316819

but overriding draw screws up a lot of stuff. Just guessing is not getting
me much further. Now I need help.

Yeah, overriding `draw` is never the answer. Even the `cascading`
widget I wrote some months ago is wrong, I feel.

I'm sorry about the lack of documentation on widgets, they aren't
essential to Hackety Hack, so they aren't important to me until
after Hackety Hack is done.

                          {o}
                           ^

Try this for your slider: <http://gist.github.com/25836>

 class Slider < Widget
   def initialize opts = {}
     background white
     para "SLIDER HERE"
   end
 end

You see, a widget is just a `flow` that can be subclassed. A `flow`
is considered the default container (slot) in Shoes. The main Shoes
app window itself starts its little existence as a flow.

If you need it to be a stack, throw a stack inside of it.

Assuming the above `initialize` method, when you write
`slider :width => 0.9`, you will basically wind up with:

 flow :width => 0.9 do
   background white
   para "SLIDER HERE"
 end

However, the `flow` will report itself as a Slider object now.

Any options passed to the widget are passed to the flow first and
then to `initialize`.

                          {o}
                           ^
What good is this? Well, now you can add methods to the Slider
object to manipulate the slot or to respond to slot events.

Take another look at the speedometer sample. The widget is just a
canvas to paint everything on to. And methods like `ticks`
and `position=` make it more than just a canvas, it becomes a
meaningful widget with friendly properties.

Anyway, the point is to avoid having to write custom drawing methods
and parsing of options. You can build the widget from all the art
objects within Shoes and the painting and resizing is handled without
intervention, you know?

_why


Thank you for clarifying that.
Let me clarify my question after having understood that shoes does not reflow. The wwwebness of it fooled me. How can I let my widget know the size of its parent? Since it doesn't reflow the size should be known when initialize is called and you have to agree that it should be considered a bug that in this:

 #[.snip..]
  @left = stack(:width => 200) { |s|
                        background yellow
                        stack {
                                rect_width = width*0.8
                                @r = rect 0,0, rect_width, 20, :stroke => red, 
:fill => green
                        }
                        para "col 1"

        }
#[..snip..]

`width` is not the width of the surrounding container but of the entire window (as is parent.width). No matter if you agree, it would be s convenient that I plead with you to hand size downwards somehow.

Thanks to your clarifications I did create a workaround that works and looks pretty good so I will not nag anymore :)

Thank you!

http://www.pastie.org/317346

(choice of name for the method from java where such an event occurs.)


Einar Magnús Boson
+354-661 1649
[EMAIL PROTECTED]
[EMAIL PROTECTED]

Reply via email to