Debian Codegraph @

demo/overlay/Overlay.hs

raw
1 module Main (main) where
2
3 import Graphics.UI.Gtk
4
5 main :: IO ()
6 main = do
7 initGUI
8
9 -- Create a new window
10 window <- windowNew
11
12 -- Here we connect the "destroy" event to a signal handler.
13 on window objectDestroy mainQuit
14
15 -- Sets the border width of the window.
16 set window [ containerBorderWidth := 10 ]
17
18 overlay <- overlayNew
19
20 set window [ containerChild := overlay ]
21
22 vbox <- vBoxNew True 3
23 label1 <- labelNew (Just "This is an overlaid label")
24 button <- buttonNewWithLabel ("another one")
25 label3 <- labelNew (Just "and a final one")
26 boxPackStart vbox label1 PackNatural 3
27 boxPackStart vbox button PackNatural 3
28 boxPackStart vbox label3 PackNatural 3
29
30 set vbox [ widgetMarginLeft := 150, widgetMarginBottom := 50 ]
31
32 overlayAdd overlay vbox
33
34 hbuttonbox <- hButtonBoxNew
35
36 containerAdd overlay hbuttonbox
37
38 button1 <- buttonNewWithLabel "One"
39 button2 <- buttonNewWithLabel "Two"
40 button3 <- buttonNewWithLabel "Three"
41
42 -- Add each button to the button box with the default packing and padding
43 set hbuttonbox [ containerChild := button
44 | button <- [button1, button2, button3] ]
45
46 -- This sets button3 to be a so called 'secondary child'. When the layout
47 -- style is ButtonboxStart or ButtonboxEnd, the secondary children are
48 -- grouped separately from the others. Resize the window to see the effect.
49 --
50 -- This is not interesting in itself but shows how to set child attributes.
51 -- Note that the child attribute 'buttonBoxChildSecondary' takes the
52 -- button box container child 'button3' as a parameter.
53 set hbuttonbox [ buttonBoxLayoutStyle := ButtonboxStart ]
54 --, buttonBoxChildSecondary button3 := True ]
55
56 -- The final step is to display everything (the window and all the widgets
57 -- contained within it)
58 widgetShowAll window
59
60 -- All Gtk+ applications must run the main event loop. Control ends here and
61 -- waits for an event to occur (like a key press or mouse event).
62 mainGUI