Murga-Projects Forums

Full Version: How to resize main window
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to get a feel for fltk and lua and I'm trying to make some the example code resizeable. Particularly the main window.

For instance how would you make the following program from the documentation page resizeable?

Code:
window = fltk:Fl_Window(505, 145, "My first little app")

fltk:Fl_Button(5, 5, 310, 135, "My First Button")
fltk:Fl_Button(320, 65, 180, 35, "Load a picture")
fltk:Fl_Button(320, 105, 180, 35, "Quittin Time")

window:show()
Fl:run()

First I would set each widget to a variable name, which will give you much better control of your program:

Code:
window = fltk:Fl_Window(505, 145, "My first little app")

button1=fltk:Fl_Button(5, 5, 310, 135, "My First Button")
button2=fltk:Fl_Button(320, 65, 180, 35, "Load a picture")
button3=fltk:Fl_Button(320, 105, 180, 35, "Quittin Time")

window:show()
Fl:run()


Next, use the :resizable() method to allow resizing:

Code:
window = fltk:Fl_Window(505, 145, "My first little app")

button1=fltk:Fl_Button(5, 5, 310, 135, "My First Button")
button2=fltk:Fl_Button(320, 65, 180, 35, "Load a picture")
button3=fltk:Fl_Button(320, 105, 180, 35, "Quittin Time")

window:resizable(button1)
window:show()
Fl:run()


Now this does some ugly stretching of the buttons, And I honestly don't know how to prevent that. It seems to depend on how the widgets are aligned to each other.

mikshaw Wrote:
First I would set each widget to a variable name, which will give you much better control of your program:

Code:
window = fltk:Fl_Window(505, 145, "My first little app")

button1=fltk:Fl_Button(5, 5, 310, 135, "My First Button")
button2=fltk:Fl_Button(320, 65, 180, 35, "Load a picture")
button3=fltk:Fl_Button(320, 105, 180, 35, "Quittin Time")

window:show()
Fl:run()


Next, use the :resizable() method to allow resizing:

Code:
window = fltk:Fl_Window(505, 145, "My first little app")

button1=fltk:Fl_Button(5, 5, 310, 135, "My First Button")
button2=fltk:Fl_Button(320, 65, 180, 35, "Load a picture")
button3=fltk:Fl_Button(320, 105, 180, 35, "Quittin Time")

window:resizable(button1)
window:show()
Fl:run()


Now this does some ugly stretching of the buttons, And I honestly don't know how to prevent that. It seems to depend on how the widgets are aligned to each other.


Wow, this is not very intuitive. I'm trying to get a handle on this. If you want to be able to resize a window, you must resize one of the widgets in the window? I was expecting a callback or something where you manually resized it when the parent tries to resize. Is something like that possible?

I tried resizing a different button to see what would happen and it works too, but the widgets resize differently. It seems the widget you set resizable has the priority and the others follow only if needed.

So now I will try to figure out how to get better control of the sizing behavior.

Thanks for the reply.

- Don

I'm pretty sure there is a better way to set it up, but I've never quite understood how resizable works. As far as I know, you can apply the method to a group rather than the main window, which will hopfully give you better control of the result:
http://www.fltk.org/documentation.php/do....resizable
I thought there was a better way to do this too ...

I'll take a look when I get a second :-)

Cheers
JohnM
I tried it with a box or a child window covering the whole main window, using that as the resizable widget, and both seem to have slightly better results. Now the buttons stretch uniformly.

The best results I've gotten so far were from placing a 0x0 box in the bottom corner:
resize=fltk:Fl_Box(505,145,0,0)
window:resizable(resize)
This is still not ideal, as the windows contents don't do _any_ scaling.
I guess the resizable widget you choose would mostly have to depend on what kind of contents your window has.

There are also the Fl_Scroll and Fl_Pack widgets that could be utilized, if resizing down makes the buttons squash and overlap. I haven't figured out those particular widgets myself, though.
OK, I wanted the main button to resize and the others not to ...

The secret is to read the FLTK docs carefully, and define groups to safeguard the size of certain widgets (with an invisible widget here and there).

It's pretty cool, I think I can get it to do whatever I want now.

As for Fl_Scroll, I'll try and come up with a demo ...

Code:
window = fltk:Fl_Window(505, 145, "My first little app")

button1=fltk:Fl_Button(5, 5, 310, 135, "My First Button")

group = fltk:Fl_Group(320, 5, 180, 135, "")

nothing=fltk:Fl_Box(320, 5, 180, 35, "")
button2=fltk:Fl_Button(320, 65, 180, 35, "Load a picture")
button3=fltk:Fl_Button(320, 105, 180, 35, "Quittin Time")

group:add(nothing)
group:add(button2)
group:add(button3)

group:resizable(nothing)
window:resizable(button1)

window:show()
Fl:run()

This is useful to know and understand, thanks John and Milkshaw.

I want to build a scalable game board (for Go and perhaps Chess.) The behavior I want is this:

Essentially I want to be able to grab the main window and have the board AND the graphics drawn on the board scale accordingly. There will be other panes but the board itself must scale and keep it's aspect ratio. The other panes will have different scaling behavor and needs but once I understand how to implement this, it will not be a problem. I don't mind if I have to catch some event and redraw.


So I'll be playing around with this for a while to see if I can produce a simple demo. If anyone has ideas of course I'm eager to hear them!


JohnMurga Wrote:
OK, I wanted the main button to resize and the others not to ...

The secret is to read the FLTK docs carefully, and define groups to safeguard the size of certain widgets (with an invisible widget here and there).

It's pretty cool, I think I can get it to do whatever I want now.

As for Fl_Scroll, I'll try and come up with a demo ...

Code:
window = fltk:Fl_Window(505, 145, "My first little app")

button1=fltk:Fl_Button(5, 5, 310, 135, "My First Button")

group = fltk:Fl_Group(320, 5, 180, 135, "")

nothing=fltk:Fl_Box(320, 5, 180, 35, "")
button2=fltk:Fl_Button(320, 65, 180, 35, "Load a picture")
button3=fltk:Fl_Button(320, 105, 180, 35, "Quittin Time")

group:add(nothing)
group:add(button2)
group:add(button3)

group:resizable(nothing)
window:resizable(button1)

window:show()
Fl:run()

Reference URL's