FXRuby: adding child widgets after #run has started

Y

Yuri Leikind

Hello all,

Is there a way in Fox to add widgets after the widget hierarchy has been built and
FXApp#run has started ?


Say, I have an empty FXScrollWindow, and I want to add FXMatrix to it with
lots of its own children, on some event (button click, etc).

So far, I have not found a way to see the widgets I've added.
 
Y

Yuri Leikind

See this question from the FOX FAQ list:

http://www.fox-toolkit.org/faq.html#CREATELATER

If you add widgets after the program's started, you'll need to call
create() on them after adding them.


Yes, it does work. In some cases. But in other cases it doesn't. Please take a look at the example:


require "fox"
class App < Fox::FXApp

include Fox

def initialize
super("app")
window = FXMainWindow.new(self,"app", nil, nil, 0, 0, 500, 300)
contents = FXVerticalFrame.new(window, LAYOUT_SIDE_TOP|LAYOUT_FILL_X|LAYOUT_FILL_Y)

grbox1 = FXGroupBox.new(contents, "Options", GROUPBOX_TITLE_LEFT|LAYOUT_FILL_X|LAYOUT_FILL_Y)
build(grbox1, false)

grbox2 = FXGroupBox.new(contents, "Options", GROUPBOX_TITLE_LEFT|LAYOUT_FILL_X|LAYOUT_FILL_Y)
#build(grbox2, false)

FXButton.new(contents, "Click me").connect(SEL_COMMAND) do
build(grbox2, true)
end
create
window.show
run
end

def build(parent, creat)
scrollarea = FXScrollWindow.new(parent, VSCROLLER_ALWAYS|LAYOUT_FILL_X|LAYOUT_FILL_Y)

scrollable = FXMatrix.new(scrollarea, 2, MATRIX_BY_COLUMNS|LAYOUT_FILL_X, DEFAULT_SPACING,
DEFAULT_SPACING, DEFAULT_SPACING, DEFAULT_SPACING, 30, 30)


1.upto(10) do
FXLabel.new(scrollable, "some name", nil, LABEL_NORMAL)
FXCheckButton.new(scrollable, "yes", nil, 0, CHECKBUTTON_NORMAL|LAYOUT_SIDE_LEFT)
end
scrollarea.create if creat
end
end
App.new


We have 2 FXScrollWindow instances here, one of which is built before run , another - after.
So that another FXScrollWindow is never seen. I don't see why.
 
L

Lyle Johnson

Yes, it does work. In some cases. But in other cases it doesn't.
Please take a look at the example:

We have 2 FXScrollWindow instances here, one of which is built before
run , another - after.
So that another FXScrollWindow is never seen. I don't see why.

The problem is that merely adding an FXScrollWindow to the FXGroupBox
during that second call to build() doesn't mark the layout of the group
box as "dirty". That is to say, FOX doesn't assume that adding the
scroll window changed the size of the parent group box (grbox2), and so
that widget's layout doesn't get recalculated as a result. In this
case, you need to explicitly mark the group box layout as dirty by
calling its recalc() method. Try adding the following line at the end
of build(), after the call to FXScrollWindow#create:

scrollarea.recalc

and see if you get the result you're after.

Hope this helps,

Lyle
 
Y

Yuri Leikind

The problem is that merely adding an FXScrollWindow to the FXGroupBox
during that second call to build() doesn't mark the layout of the group
box as "dirty". That is to say, FOX doesn't assume that adding the
scroll window changed the size of the parent group box (grbox2), and so
that widget's layout doesn't get recalculated as a result. In this
case, you need to explicitly mark the group box layout as dirty by
calling its recalc() method. Try adding the following line at the end
of build(), after the call to FXScrollWindow#create:

scrollarea.recalc

and see if you get the result you're after.

Hope this helps,

Oh yes, it does, thank you again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top