1 {-# LANGUAGE FlexibleContexts, LambdaCase, MultiParamTypeClasses,
4 module RMCA.GUI.Buttons ( buttonNewFromStockWithLabel
5 , toggleButtonNewFromStock
11 import Data.ReactiveValue
12 import Graphics.UI.Gtk
13 import Graphics.UI.Gtk.Reactive
14 import RMCA.GUI.StockId
15 import RMCA.Layer.Board
17 packButton :: (BoxClass a, ButtonClass b, ImageClass i, LabelClass l) =>
18 b -> a -> l -> i -> IO b
19 packButton button buttonBox buttonLabel buttonImg = do
20 containerAdd button buttonBox
21 boxPackStart buttonBox buttonImg PackRepel 0
22 boxPackStart buttonBox buttonLabel PackRepel 0
25 buttonNewFromStockWithLabel :: StockId -> String -> IO Button
26 buttonNewFromStockWithLabel s l = do
28 buttonBox <- hBoxNew False 0
29 buttonImg <- imageNewFromStock s IconSizeButton
30 buttonLabel <- labelNew (Just l)
31 labelSetUseUnderline buttonLabel True
32 packButton button buttonBox buttonLabel buttonImg
34 toggleButtonNewFromStock :: StockId -> IO ToggleButton
35 toggleButtonNewFromStock s = do
36 button <- toggleButtonNew
37 buttonBox <- hBoxNew False 0
38 buttonImg <- imageNewFromStock s IconSizeButton
39 stockTxt <- stockLookupItem s
40 buttonLabel <- labelNew (siLabel <$> stockTxt)
41 labelSetUseUnderline buttonLabel True
42 packButton button buttonBox buttonLabel buttonImg
44 buttonBoxNewWithLabelFromStock :: StockId -> IO HBox
45 buttonBoxNewWithLabelFromStock s = do
46 buttonBox <- hBoxNew False 0
47 buttonImg <- imageNewFromStock s IconSizeButton
48 stockTxt <- stockLookupItem s
49 buttonLabel <- labelNew (siLabel <$> stockTxt)
50 labelSetUseUnderline buttonLabel True
51 boxPackStart buttonBox buttonImg PackRepel 0
52 boxPackStart buttonBox buttonLabel PackRepel 0
55 getButtons :: (ReactiveValueRead boardStatus RunStatus IO) =>
56 boardStatus -> IO ( VBox
57 , ReactiveFieldRead IO ()
58 , ReactiveFieldRead IO ()
59 , ReactiveFieldRead IO Bool
60 , ReactiveFieldRead IO Bool
61 , ReactiveFieldRead IO ()
62 , ReactiveFieldRead IO ()
63 , ReactiveFieldRead IO ()
64 , ReactiveFieldRead IO ()
66 getButtons boardStatusRV = do
68 restartM <- stockLookupItem gtkMediaRestart
69 when (isJust restartM) $ do
70 stockAddItem [(fromJust restartM) { siLabel = "_Restart" }]
71 buttonBox <- vBoxNew False 10
73 buttonBoxAddRmLayers <- hBoxNew True 10
74 boxPackStart buttonBox buttonBoxAddRmLayers PackNatural 0
76 buttonAddLayer <- buttonNewFromStockWithLabel gtkMediaAdd "Add layer"
77 let addLayerRV = buttonActivateField buttonAddLayer
78 boxPackStart buttonBoxAddRmLayers buttonAddLayer PackGrow 0
80 buttonRmLayer <- buttonNewFromStockWithLabel gtkMediaRemove "Remove layer"
81 let rmLayerRV = buttonActivateField buttonRmLayer
82 boxPackStart buttonBoxAddRmLayers buttonRmLayer PackGrow 0
84 buttonBoxSaveLoad <- hBoxNew True 10
85 boxPackStart buttonBox buttonBoxSaveLoad PackNatural 0
87 buttonSave <- buttonNewFromStockWithLabel gtkMediaSave "_Save configuration"
88 let confSaveRV = buttonActivateField buttonSave
89 boxPackStart buttonBoxSaveLoad buttonSave PackGrow 0
91 buttonLoad <- buttonNewFromStockWithLabel gtkMediaOpen "_Load configuration"
92 let confLoadRV = buttonActivateField buttonLoad
93 boxPackStart buttonBoxSaveLoad buttonLoad PackGrow 0
95 buttonBoxBot <- hBoxNew True 10
96 boxPackStart buttonBox buttonBoxBot PackNatural 0
97 buttonPlay <- buttonNewFromStock gtkMediaPlay
98 let playRV = buttonActivateField buttonPlay
99 playStockId = wrapMW (buttonSetLabel buttonPlay)
100 reactiveValueWrite playStockId gtkMediaPlay
101 reactiveValueOnCanRead boardStatusRV $ reactiveValueRead boardStatusRV >>=
103 Stopped -> reactiveValueWrite playStockId $ gtkMediaPlay
104 Running -> reactiveValueWrite playStockId $ gtkMediaRestart
105 boxPackStart buttonBoxBot buttonPlay PackRepel 0
107 buttonPause <- toggleButtonNewFromStock gtkMediaPause
108 let pauseRV = readOnly $ toggleButtonActiveReactive buttonPause
109 boxPackStart buttonBoxBot buttonPause PackRepel 0
111 buttonStop <- buttonNewFromStock gtkMediaStop
112 let stopRV = buttonActivateField buttonStop
113 boxPackStart buttonBoxBot buttonStop PackRepel 0
115 buttonRecord <- toggleButtonNewFromStock gtkMediaRecord
116 let recordRV = readOnly $ toggleButtonActiveReactive buttonRecord
117 boxPackStart buttonBoxBot buttonRecord PackRepel 0