Murga-Projects Forums

Full Version: removing/replacing widgets
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I've been struggling with a way to dynamically replace existing widgets or groups of widgets.
FlBig Grinelete_widget() causes a segmentation fault, which I assume is my main problem with this task. The FLTK documentation lists Fl_Group::~Fl_Group() is supposed to destroy a group, but I have no idea how to translate this to murgaLua.
Are both instances of "Fl_Group" to be replaced with the name of the group? Is it name:~Fl_Group()? name:~name()? name:fltk:~FL_Group()? Maybe it doesn't translate to murgaLua?
You have to hide it first (always) ... Not hiding it causes a crash on Windows too ...

This example should work on Linux, I am about to test it :

Code:
local object = fltk:Fl_Double_Window(200, 100)

window = object

button1 = fltk:Fl_Button(25, 25, 150, 25, "Remove Button")
button2 = fltk:Fl_Button(25, 60, 150, 25, "Will go")

function remove_callback(data)
  button2:hide()
  Fl:delete_widget(button2)
end

button1:callback(remove_callback)

window:show()
Fl:run()

OK, this appears to work correctly on Windows, however under Linux it only works when removing windows for some reason (!!) ... Ummm, will look into this.
It seems to work for me. Thank you. I didn't try your example, but used delete_widget() after hiding the widget I was already testing (a browser).
There is still a strange behaviour causing a segfault, though. There seems to be data left over somewhere relating to the deleted widget. If I try to show the deleted widget, or even check to see if it exists, the segfault occurs (where normally it would be an error message). If I set a new value to the widget's name after deleting it, segfault doesn't occur unless I get trigger-happy with the button that checks for it. Either way, it doesn't seem possible to create a new widget using the name of the deleted widget, so I still don't know if dynamically replacing widgets is possible. I know I could hide/show overlapping stuff, but that does not fit with my plan (simplicity and modularity). I'll be messing around with it for a while, though, so I'll keep you updated =o)
I found the issue !! :-)

Again, Linux being a little sensitive about the sequence.

This was tested on both Windows and Linux and never segfaults.

Code:
local object = fltk:Fl_Double_Window(200, 100);

window = object;

button1 = fltk:Fl_Button(25, 25, 150, 25, "Remove Button");
button2 = fltk:Fl_Button(25, 60, 150, 25, "Will go");

function remove_callback(data)
  window:remove(button2)
  Fl:delete_widget(button2)
  window:redraw()
  button2=nil
end

button1:callback(remove_callback)

window:show();
Fl:run();

Yes, that does stop the segfaults. Thank you very much for this help.
One thing I should mention relating to my original post:
In order to dynamically replace the removed widget with a new one, apparently you need to use window:add(button2) after creating a new button2 widget. It took me a bit to figure out why it wasn't showing while I could still access its properties, even after button2:redraw() and window:redraw().

Also, what is the purpose of creating "local object" and then setting "window" to the same value?

mikshaw Wrote:
Also, what is the purpose of creating "local object" and then setting "window" to the same value?


Err ... I was hacking the generated FLUID code (been playing with the converter), it makes NO sense ;-)

Cheers
JohnM

Reference URL's