Go to the first, previous, next, last section, table of contents.

Physical layout

Layout of components can be done in countless number of ways, but the simplest and perhaps the most useful is the boxes-and-glue style of layout. A set of DisplayHandles are combined together in a box, tiling them either horisontally or vertically:


module Main(main) where

import Haggis
import Random (randomInts)

main =
 mkDC ["*title: BoxORama"] >>= \ env ->
 let
  rs = take 64 (map (`mod` 40) (randomInts 17 57))
 in
 zipWithIO
   (\ sz ix ->
      button (text (show ix)) ix env >>= \ (btn,dh) ->
      return (btn, augmentNatSize (sz,0) dh))
   rs
   [1..64]     >>= \ ls ->
 realiseDH env (layout True (map (snd) ls)) >>
 return ()
 
{-
 Constructs a tiling layout that changes orientation of
 box used at each level. Assumes n>=2 and power of 2, where
 n is initial length of list.
-}
layout :: Bool -> [DisplayHandle] -> DisplayHandle
layout flg [x,y] = (if flg then vbox else hbox) [x,y]
layout flg ls  = 
 let
  (as,bs) = splitAt (length ls `div` 2) ls
 in
 (if flg then vbox else hbox) [layout (not flg) as,layout (not flg) bs]

BoxORama


Go to the first, previous, next, last section, table of contents.