Difference between revisions of "WxHaskell/Button sizing problem"

From HaskellWiki
Jump to navigation Jump to search
m (Some proofreading)
(Added category wxHaskell)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
== Button Sizing ==
 
== Button Sizing ==
Note this is for the [[wxHaskell]] library.
+
Note: this is for the [[wxHaskell]] library.
  +
See also [[Talk:WxHaskell/Button sizing problem]]
   
 
Let me draw a background first:
 
Let me draw a background first:
Line 9: Line 10:
 
, clientSize := sz 50 50 ]
 
, clientSize := sz 50 50 ]
   
From the manual, if we want to set the size of a button, it said set the size of button at the time of creation. It looks alright. However, if we follow the previous code, when we resize the frame, then the button will resize to the default size. In the following, it will just give the same problem.
+
The manual states that if we want to set the size of a button, it must be done at the time of creation. This looks alright. However, notice in the previous code that when we resize the frame, the button will resize to the default size. In the following code, the same thing will happen:
   
 
gui = do f <- frame [ text := "Button"
 
gui = do f <- frame [ text := "Button"
Line 16: Line 17:
 
set b [ clientSize := sz 50 50 ]
 
set b [ clientSize := sz 50 50 ]
   
Somebody would say I have not set the layout yet. You are right. But the problem would even worse if we set the button to the layout, you never see the button changed. When you run the program, you always see a default sized button. Since, when the you set the layout, the button will force to set back to the default size, example code 3
+
Some would say I have not set the layout yet. This is correct. But the problem would be even worse if we set the button to the layout, you would never see the button changed. When you run the program, you always see a default sized button. Since, when you set the layout, the button will be set back to the default size, example code 3
   
 
gui = do f <- frame [ text := "Button"
 
gui = do f <- frame [ text := "Button"
Line 24: Line 25:
 
set f [ layout := widget b ]
 
set f [ layout := widget b ]
   
In this example 3, it tells us the frame size will also be changed after we the layout to fit the internal content size. As what i said, it will only give out a default size button. You will say that set the button size after setting the layout. You are right again. It works at the beginning. We can see a button with our intened size. But when we resize the frame, then the program will follow the layout setting, and do the automatic re-adjustment of the frame content, then button will then be set back to the default. It will give the same effect if we are using container.
+
In this example, it tells us that the frame size will also be changed after we define the layout to fit the internal content size. As what I said, it will only give out a default size button. You will say "set the button size after setting the layout". You are right again. It works at the beginning. We can see a button with our intended size. But when we resize the frame, the program will follow the layout setting, and do the automatic re-adjustment of the frame content, then the button will be set back to the default. It will give the same effect if we are using a container.
   
 
You might say "Then we can't have a button with the size we want by using wxHaskell". At the moment, there is a way to solve this problem using a panel to store a button. If we resize a frame, it will affect the size of panel, but not the button. Luckily, the size of button will remain the same. By following this, we can make the button any size we wish.
 
You might say "Then we can't have a button with the size we want by using wxHaskell". At the moment, there is a way to solve this problem using a panel to store a button. If we resize a frame, it will affect the size of panel, but not the button. Luckily, the size of button will remain the same. By following this, we can make the button any size we wish.
Line 34: Line 35:
 
set b [ clientSize := sz 50 50 ]
 
set b [ clientSize := sz 50 50 ]
   
PS: Remember to set positions manually instead of by gridding (AKA, using layout controls), or else the same problem will happen again.
+
P.S.: Remember to set the positions manually instead of by gridding (A.K.A. using layout controls), or else the same problem will happen again.
   
To create a button with prefered size, remember to use a panel to store (contain, or encpasulate) it.
+
To create a button with preferred size, remember to use a panel to store (contain, or encapsulate) it.
  +
  +
  +
[[Category:wxHaskell]]

Latest revision as of 20:46, 15 January 2012

Button Sizing

Note: this is for the wxHaskell library. See also Talk:WxHaskell/Button sizing problem

Let me draw a background first:

gui = do f <- frame [ text := "Button"
                    , clientSize := sz 200 200 ]
         b <- button f [ text := "Button"
                       , clientSize := sz 50 50 ]

The manual states that if we want to set the size of a button, it must be done at the time of creation. This looks alright. However, notice in the previous code that when we resize the frame, the button will resize to the default size. In the following code, the same thing will happen:

gui = do f <- frame [ text := "Button"
                    , clientSize := sz 200 200 ]
         b <- button f [ text := "Button" ]
         set b [ clientSize := sz 50 50 ]

Some would say I have not set the layout yet. This is correct. But the problem would be even worse if we set the button to the layout, you would never see the button changed. When you run the program, you always see a default sized button. Since, when you set the layout, the button will be set back to the default size, example code 3

gui = do f <- frame [ text := "Button"
                    , clientSize := sz 200 200 ]
         b <- button f [ text := "Button"
                       , clientSize := sz 50 50 ]
         set f [ layout := widget b ]

In this example, it tells us that the frame size will also be changed after we define the layout to fit the internal content size. As what I said, it will only give out a default size button. You will say "set the button size after setting the layout". You are right again. It works at the beginning. We can see a button with our intended size. But when we resize the frame, the program will follow the layout setting, and do the automatic re-adjustment of the frame content, then the button will be set back to the default. It will give the same effect if we are using a container.

You might say "Then we can't have a button with the size we want by using wxHaskell". At the moment, there is a way to solve this problem using a panel to store a button. If we resize a frame, it will affect the size of panel, but not the button. Luckily, the size of button will remain the same. By following this, we can make the button any size we wish.

gui = do f <- frame [ text := "Button"
                    , clientSize := sz 200 200 ]
         p <- panel f []
         b <- button p [ text := "Button" ]
         set b [ clientSize := sz 50 50 ]

P.S.: Remember to set the positions manually instead of by gridding (A.K.A. using layout controls), or else the same problem will happen again.

To create a button with preferred size, remember to use a panel to store (contain, or encapsulate) it.