| |||||||||||||||||
| |||||||||||||||||
Contents | |||||||||||||||||
Description | |||||||||||||||||
The layout module helps to position controls (i.e. buttons, listboxes, etc) on a container. Allthough it is possible to position them by hand using the Dimensions class, it is much easier to position them using layout combinators. Furthermore, the parent widget will automatically reposition them when for example the size of the parent widget changes. Also, a parent widget can determine its initial view size based on the given layout. Here is an example that puts three buttons next to each other: do w <- window [title =: "hi controls"] a <- button [text =: "A"] w b <- button [text =: "B"] w c <- button [text =: "C"] w set w [layout =: a <<< b <<< c] If a and b should have been placed on top of c, we would write: (a <<< b) ^^^ c Each control has some minimal size. We can increase this with the vfix and hfix combinators. We can give for example c a width of 80: (a <<< b) ^^^ hfix 80 c Padding around the controls can be added with the pad combinators. For example: (hpad 10 a <<< b) ^^^ vpad 10 (hfix 80 c) Sometimes, it is easier to add padding between each control in a layout. The padding combinator can be used to do this. Padding can also be added between controls with the extended operators (^^^^) and (<<<<): (a <<<< b) ^^^^ b Each control has both an inherited and occupied area. The inherited area is the area that it gets from the parent widget. The occupied area is the actual area that is occupied by the control. If the occupied area is smaller than the inherited area, the control is positioned in the upper-left corner. A control can also stretch to fill the available space. For example, we can make control a stretch vertically and control c horizontally: (vfill a <<<< b) ^^^^ hfill c There is also glue: an empty control that stretches to fill the available space. Using glue, we can for example put the controls in the lower-right corner: hglue <<< (vglue ^^^ ((a <<< b) ^^^ c)) Or in the middle: hglue <<< (vglue ^^^ ((a <<< b) ^^^ c) ^^^ vglue) <<< hglue This pattern is actually captured in the center combinators: hcenter c = row [hglue,c,hglue] The most primitive combinator is the grid. It positions a matrix of elements in an aligned grid. A grid is flexible -- if a grid contains objects that stretch horizontally or vertically, the entire grid will also stretch. Since (^^^), (<<<), row, column and others have all been formulated in terms of grid, these will also stretch automatically if one of their arguments stretches. For example, the following code will not position item a centered on top of item b: hcenter a ^^^ b Instead, it will stretch out to fill the entire inherited space and center a horizontally in that space. The b item has no stretch and will float to the left. To center the a control relative to b, one needs to prevent the parent grid from stretching. The rigid combinator can be used to do that: rigid (hcenter a ^^^ b) | |||||||||||||||||
Synopsis | |||||||||||||||||
Controls | |||||||||||||||||
class Control w | |||||||||||||||||
| |||||||||||||||||
pack :: (Control w) => w -> Layout | |||||||||||||||||
Create a Layout from a normal control. | |||||||||||||||||
data Layout | |||||||||||||||||
| |||||||||||||||||
Containers | |||||||||||||||||
class Container w | |||||||||||||||||
| |||||||||||||||||
layout :: (Container w, Control c) => Attr w c | |||||||||||||||||
The layout of controls within the window. This attribute is write-only. If a control is not assigned to the layout, it will not show up (unless explicitly positioned using its Dimensions). The window will automatically update the layout when resized or when a control changes its appearance. | |||||||||||||||||
autosize :: (Container w) => Attr w Bool | |||||||||||||||||
Controls whether the widget will automatically resize to display all controls. | |||||||||||||||||
layoutSize :: (Container w) => Attr w Size | |||||||||||||||||
The layoutSize of widget is the minimum size needed to layout the controls assigned to it. This attribute is read-only. | |||||||||||||||||
relayout :: (Container w) => Event w (IO ()) | |||||||||||||||||
The relayout event is called whenever the controls in the window need to be repositioned. For example, when the window is resized or when a control changes its appearance. | |||||||||||||||||
hwindow :: (Container w) => w -> WindowHandle | |||||||||||||||||
Internal | |||||||||||||||||
Operators | |||||||||||||||||
(^^^^) :: (Control w, Control v) => w -> v -> Layout | |||||||||||||||||
Place two controls on top of each other with some padding in between (10 pts). (See also vertical). | |||||||||||||||||
(<<<<) :: (Control w, Control v) => w -> v -> Layout | |||||||||||||||||
Place two controls next to each other with some padding in between (10 pts). (See also horizontal). | |||||||||||||||||
(^^^) :: (Control w, Control v) => w -> v -> Layout | |||||||||||||||||
Place two controls on top of each other. (See also above and col). | |||||||||||||||||
(<<<) :: (Control w, Control v) => w -> v -> Layout | |||||||||||||||||
Place two controls next to each other. (See also beside and row). | |||||||||||||||||
Layout | |||||||||||||||||
tabular :: (Control c) => [[c]] -> Layout | |||||||||||||||||
Place controls in a grid with some padding in between (10 pts). (See also grid). A table stretches automatically if it contains glue (use rigid to prevent this). | |||||||||||||||||
horizontal :: (Control c) => [c] -> Layout | |||||||||||||||||
Place controls beside each other with some padding in between (10 pts). (See also row). A horizontal layout stretches automatically if it contains glue. | |||||||||||||||||
vertical :: (Control c) => [c] -> Layout | |||||||||||||||||
Place controls above each other with some padding in between (10 pts). (See also column). A vertical layout stretches automatically if it contains glue. | |||||||||||||||||
grid :: (Control c) => [[c]] -> Layout | |||||||||||||||||
Primitive: Create a grid of controls, gives precise control over alignment. (See also tabular). A grid will stretch automatically if it contains glue. To prevent this, use the rigid combinator. | |||||||||||||||||
row :: (Control c) => [c] -> Layout | |||||||||||||||||
Place a list of controls next to each other. (See also horizontal). A row stretches automatically if it contains glue. | |||||||||||||||||
column :: (Control c) => [c] -> Layout | |||||||||||||||||
Place a list of controls above each other. (See also vertical). A column stretches automatically if it contains glue. | |||||||||||||||||
above :: (Control w, Control v) => w -> v -> Layout | |||||||||||||||||
Lay out two controls on top of each other. (See also (^^^)). | |||||||||||||||||
beside :: (Control w, Control v) => w -> v -> Layout | |||||||||||||||||
Lay out two controls beside each other. (See also (<<<)). | |||||||||||||||||
Stretch | |||||||||||||||||
hfill :: (Control w) => w -> Layout | |||||||||||||||||
The control will stretch horizontally to fit in the available space. Any grid with at least one filling item will also stretch to fill the entire available space. | |||||||||||||||||
vfill :: (Control w) => w -> Layout | |||||||||||||||||
The control stretches vertically to fit in the available space. Any grid with at least one filling item will also stretch to fill the entire available space. | |||||||||||||||||
fill :: (Control w) => w -> Layout | |||||||||||||||||
The control will stretch both horizontally and vertically to fill the available space. Any grid with at least one filling item will also stretch to fill the entire available space. | |||||||||||||||||
hstretch :: (Control w) => w -> Layout | |||||||||||||||||
The control will stretch horizontally to fit in the available space. When the control is placed in grid then the available space is equal to maximal width of controls in the same column. | |||||||||||||||||
vstretch :: (Control w) => w -> Layout | |||||||||||||||||
The control stretches vertically to fit in the available space. When the control is placed in grid then the available space is equal to maximal height of controls in the same row. | |||||||||||||||||
stretch :: (Control w) => w -> Layout | |||||||||||||||||
The control will stretch both horizontally and vertically to fill the available space. When the control is placed in grid then the available width is equal to maximal width of controls in the same column and the available height is equal to maximal height of controls in the same row. | |||||||||||||||||
hrigid :: (Control w) => w -> Layout | |||||||||||||||||
Make a control horizontally rigid -- it won't stretch to fit the available space (default). | |||||||||||||||||
vrigid :: (Control w) => w -> Layout | |||||||||||||||||
Make a control vertically rigid -- it won't stretch to fit the available space (default). | |||||||||||||||||
rigid :: (Control w) => w -> Layout | |||||||||||||||||
Make a control rigid -- it won't stretch to fit the available space (default). | |||||||||||||||||
hfix :: (Control c) => Int -> c -> Layout | |||||||||||||||||
Set the preferred width of a control. | |||||||||||||||||
vfix :: (Control c) => Int -> c -> Layout | |||||||||||||||||
Set the preferred height of a control. | |||||||||||||||||
Padding | |||||||||||||||||
hpad :: (Control c) => Int -> c -> Layout | |||||||||||||||||
Add horizontal padding on both sides. | |||||||||||||||||
vpad :: (Control c) => Int -> c -> Layout | |||||||||||||||||
Add vertical padding on both the top and bottom. | |||||||||||||||||
hvpad :: (Control c) => Int -> Int -> c -> Layout | |||||||||||||||||
Add both horizontal and vertical padding. | |||||||||||||||||
pad :: (Control c) => Int -> c -> Layout | |||||||||||||||||
Add padding to all sides of a control. | |||||||||||||||||
leftpad :: (Control c) => Int -> c -> Layout | |||||||||||||||||
rightpad :: (Control c) => Int -> c -> Layout | |||||||||||||||||
toppad :: (Control c) => Int -> c -> Layout | |||||||||||||||||
bottompad :: (Control c) => Int -> c -> Layout | |||||||||||||||||
padding :: (Control c) => Int -> c -> Layout | |||||||||||||||||
Add a padding between each control in the layout, including a padding around the entire control. Note that this also adds padding around glue. | |||||||||||||||||
innerpadding :: (Control c) => Int -> c -> Layout | |||||||||||||||||
Add a padding between each control in the layout, but not on the outside of the parent control. Note that this also adds padding around glue. | |||||||||||||||||
Glue | |||||||||||||||||
hglue :: Layout | |||||||||||||||||
An empty control that stretches horizontally. | |||||||||||||||||
vglue :: Layout | |||||||||||||||||
An empty control that stretches vertically. | |||||||||||||||||
glue :: Layout | |||||||||||||||||
An empty control that stretches both horizontally and vertically. | |||||||||||||||||
hcenter :: (Control w) => w -> Layout | |||||||||||||||||
Center a control horizontally. | |||||||||||||||||
vcenter :: (Control w) => w -> Layout | |||||||||||||||||
Center a control vertically. | |||||||||||||||||
center :: (Control w) => w -> Layout | |||||||||||||||||
Center both horizontally and vertically | |||||||||||||||||
Invisible controls | |||||||||||||||||
empty :: Layout | |||||||||||||||||
Primitive: An empty invisible control with a zero size. | |||||||||||||||||
hrod :: Int -> Layout | |||||||||||||||||
A layout control of a certain width with no height. Used to implement padding. | |||||||||||||||||
vrod :: Int -> Layout | |||||||||||||||||
A layout control of a certain height with no width. Used to implement padding. | |||||||||||||||||
Translation | |||||||||||||||||
moveTo :: (Control c) => Point -> c -> Layout | |||||||||||||||||
Render the control normally, and than move it to the specified position. | |||||||||||||||||
moveBy :: (Control c) => Size -> c -> Layout | |||||||||||||||||
Render the control normally, and than move relative to its rendered position. | |||||||||||||||||
move :: (Control c) => (Point -> Size -> Point) -> c -> Layout | |||||||||||||||||
Render the control normally, and than change its position according to its rendered position and size. | |||||||||||||||||
Internal | |||||||||||||||||
Functions | |||||||||||||||||
stdPack :: (w -> WindowHandle) -> (w -> WindowHandle) -> (WindowHandle -> IO Size) -> w -> Layout | |||||||||||||||||
Internal: creates a standard pack function from a parent handle, control handle and a function that returns the preferred size. | |||||||||||||||||
getLayoutSize :: (Control c) => c -> IO Size | |||||||||||||||||
Return the minimal size needed to display this control. | |||||||||||||||||
layoutInRect :: (Control c) => Rect -> c -> IO Size | |||||||||||||||||
Positions a controls in a certain rectangle | |||||||||||||||||
updateControlsVisibility :: Layout -> Layout -> IO () | |||||||||||||||||
Produced by Haddock version 0.4 |