After some trickery, this works, sort of:
http://pastebin.com/m4acd9d33

It's inelegant though.

What I'm doing is having the widget paint itself, but putting it in a stack
that handles all events. This makes widgets sort of pointless, but it does
work.

Notable points: the explicit width and height args on the stack are
required. If you don't put them in there, then the widget still draws but
none of the events get passed through.

Also, setting left and top on the stack doesn't change the mouse coords of
the click.

Anyway, I think I'll avoid using widgets for the time being, and just do
everything some other way.

On Thu, Sep 18, 2008 at 3:28 PM, Joshua Choi <[EMAIL PROTECTED]> wrote:

> The pastie you linked to seems to reveal bugs in Shoes itself.
>
> The hover(), click(), and leave() methods do not work correctly in a
> Button's block. When a button is clicked on, hover() seems to be
> called. The hover(), click(), and leave() methods also do not work in
> Widgets at all.
>
> This works, however:
>
> class Thing < Widget
>                def initialize &blk
>                         self.width=300
>                        self.height=300
>                        background blue
>                         yield if block_given?
>                 end
>        end
>
>        Shoes.app do
>                thing do
>                         button 'Test' do
>                                alert "Boo"
>                        end
>                end
>        end
>
> When typing out this out, though, I found a third bug—butting braces
> around the button's block instead of do...end raises a syntax error!
>
> Anyways, the code above should work. Keep in mind that Widgets seem to
> still be spotty, and Shoes is still in its birth pangs, but Mr. Why
> still is doing an incredible job for one man.
>
> Sincerely,
> Joshua Choi
>
>
> On Thu, Sep 18, 2008 at 11:30 AM, Ross Andrews <[EMAIL PROTECTED]>
> wrote:
> > Hmm, it's not quite the same... I want to have an event take place when
> you
> > click on the widget, instead of having a button in the widget. You can do
> > this with a stack:
> > Shoes.app do
> >   stack(:width=>300, :height=>300) do
> >     click { alert "Boo" }
> >   end
> > end
> >
> > But my attempts at doing it with a widget are failing miserably:
> > http://pastebin.com/m1f5c037a
> >
> > I am running r970 now, too.
> > On Thu, Sep 18, 2008 at 12:14 PM, Joshua Choi <[EMAIL PROTECTED]> wrote:
> >>
> >> To Mr. Andrews,
> >>
> >> Well, when you're initializing the Thing object, you're passing in a
> >> block...but the Thing's initializer is not calling the block anywhere.
> >>
> >> The code below might have some errors, but I'm whipping it up to
> >> demonstrate.
> >>
> >> class Thing < Widget
> >>
> >>        def initialize &block
> >>                width = 300
> >>                height = 300
> >>                background blue
> >>                yield
> >>        end
> >>
> >> end
> >>
> >> Shoes.app do
> >>        thing do
> >>                button 'Test'
> >>                para 'Testing'
> >>        end
> >> end
> >>
> >> I tried running this, and it looks like it works. Mr. Why fixed a lot
> >> of Widget bugs in the last build, though, so make sure you have the
> >> latest version, Revision 970.
> >>
> >> Also note that the changing the background by a button inside the
> >> block only changes the button's background. I do not know if this is a
> >> bug—perhaps you can ask Mr. Why. :)
> >>
> >> Shoes.app do
> >>        thing do
> >>                button 'Test' do
> >>                        background red
> >>                end
> >>                para 'Testing'
> >>        end
> >> end
> >>
> >> Sincerely,
> >> Joshua Choi
> >>
> >> On Thu, Sep 18, 2008 at 9:28 AM, Ross Andrews <[EMAIL PROTECTED]>
> >> wrote:
> >> > Hi!
> >> > I am trying to make a game in Shoes, and so I am making classes that
> are
> >> > custom widgets. I've got something that can draw itself, but handling
> >> > events
> >> > is still eluding me.
> >> > Here's something like what I would like to do:
> >> > class Thing < Widget
> >> >   def initialize
> >> >     self.width=300
> >> >     self.height=300
> >> >     background blue
> >> >   end
> >> > end
> >> > Shoes.app do
> >> >   thing do
> >> >     hover { background red }
> >> >     leave { background blue }
> >> >     click { alert "Ha!" }
> >> >   end
> >> > end
> >> > Of course, it doesn't work at all (except the painting part). If I
> >> > replace
> >> > "thing" with a stack, then it seems to work, so what magic is stack
> >> > doing
> >> > that other widgets don't?
> >
> >
>

Reply via email to