[fxruby-users] deleting children and then adding new ones
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?
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
> > add new contents to that frame. Whenever I do this, it deletes stuff
> > 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
> > 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
> btn = FXButton.new(vf, "New Button")
> 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"
> Hope this helps,
> fxruby-users mailing list
> fxruby-users at rubyforge.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the fxruby-users