[fxruby-users] deleting children and then adding new ones

Ralph Douglass ralph at grayskies.net
Mon Dec 10 13:38:56 EST 2007


I'm working on the ui for a little video game.  On the left in a map of the
game's galaxy, and on the right in a panel.  When a planet on the left in
clicked on, I want the panel on the right to change to display information
and options for that planet.  When a user clicks on a fleet of ships, I want
it to change to display information and options for the fleet.

Is there perhaps a better way to do this than destroying the contents of the
frame on the right every time?

Thanks,

Ralph

On 12/10/07, Lyle Johnson <lyle at lylejohnson.name> wrote:
>
> On 12/9/07, Ralph Douglass <ralph at grayskies.net> wrote:
>
> > I'm trying to delete the contents of a frame (using removeChild), and
> then
> > add new contents to that frame.  Whenever I do this, it deletes stuff
> just
> > fine, but then the new thing doesn't show up.  Here is a short example:
> >
> > require 'fox16'
> >
> > include Fox
> > app = FXApp.new()
> > main = FXMainWindow.new(app, "Window")
> > vf = FXVerticalFrame.new(main)
> > button = FXButton.new(vf, "Old Button")
> > button.connect (SEL_COMMAND) do
> >   vf.removeChild(button)
> >   FXButton.new(vf, "New Button")
> > end
> >
> > app.create
> > main.show()
> > app.run
> >
> > Click the button... and then there's nothing at all.
> >
> > Is there some sort of magic incantation I need to call to get the frame
> to
> > redraw itself or something?
>
> Yes, you need to call create() on the button and then recalc() on the
> button's parent:
>
>         buttton.connect(SEL_COMMAND) do
>                 vf.removeChild(button)
>                 btn = FXButton.new(vf, "New Button")
>                 btn.create
>                 btn.recalc
>         end
>
> Note that I'm not sure it's a good idea to destroy an object while
> you're executing a message handler for it (as in this example). What
> is it that you're trying to accomplish by removing the old button and
> creating a new one? If you're just wanting to change the button's
> label (for example), you can just do:
>
>         button.connect(SEL_COMMAND) do
>                 button.text = "New Button Text"
>         end
>
> Hope this helps,
>
> Lyle
> _______________________________________________
> fxruby-users mailing list
> fxruby-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/fxruby-users
>



-- 
Ralph
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/fxruby-users/attachments/20071210/98b354f4/attachment-0001.html 


More information about the fxruby-users mailing list