News : The level of daily SPAM has reached insane proportions, all registrations are now manual. I ask you to send me an e-mail (john (at) murga (dot) org), to confirm that you want me to create an account for you.


Post Reply  Post Thread 
How to resize main window
Author Message
Don Dailey
Junior Member
**


Posts: 5
Group: Registered
Joined: Jul 2007
Status: Offline
Reputation: 0
Post: #1
How to resize main window

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()

07-24-2007 09:00 AM
Find all posts by this user Quote this message in a reply
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #2
RE: How to resize main window

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.

07-24-2007 09:53 AM
Find all posts by this user Quote this message in a reply
Don Dailey
Junior Member
**


Posts: 5
Group: Registered
Joined: Jul 2007
Status: Offline
Reputation: 0
Post: #3
RE: How to resize main window

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

07-24-2007 11:46 AM
Find all posts by this user Quote this message in a reply
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #4
RE: How to resize main window

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

07-24-2007 01:40 PM
Find all posts by this user Quote this message in a reply
JohnMurga
Administrator
*******


Posts: 381
Group: Administrators
Joined: Apr 2007
Status: Offline
Reputation: 2
Post: #5
RE: How to resize main window

I thought there was a better way to do this too ...

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

Cheers
JohnM

07-24-2007 05:06 PM
Visit this user's website Find all posts by this user Quote this message in a reply
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #6
RE: How to resize main window

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.

07-25-2007 01:07 AM
Find all posts by this user Quote this message in a reply
JohnMurga
Administrator
*******


Posts: 381
Group: Administrators
Joined: Apr 2007
Status: Offline
Reputation: 2
Post: #7
RE: How to resize main window

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 post was last modified: 07-25-2007 01:27 AM by JohnMurga.

07-25-2007 01:24 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Don Dailey
Junior Member
**


Posts: 5
Group: Registered
Joined: Jul 2007
Status: Offline
Reputation: 0
Post: #8
RE: How to resize main window

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()

07-25-2007 02:22 AM
Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: