module support_popup

// ********************************************************************************
// Clean tutorial example program.
//
// This program can be used to test the different ControlAttributes for a 
// PopUpControl in a Dialog.
// ********************************************************************************

import StdEnv, StdIO

Start :: *World -> *World
Start world
# (textid, world) = openId world 
# popups = let w = PixelWidth 200 in [
        PopUpControl [("Activate " +++ toString i, id) \\ i <- [1..5]]    1 [ControlActivate (count 1 textid)], // doesn't work yet
        PopUpControl [("Deactivate " +++ toString i, id) \\ i <- [1..5]]  2 [ControlDeactivate (count -1 textid)], // doesn't work yet
        PopUpControl [("Hide " +++ toString i, id) \\ i <- [1..5]]        1 [ControlHide],
        PopUpControl [("Id " +++ toString i, id) \\ i <- [1..5]]          3 [], // todo
        PopUpControl [("Pos " +++ toString i, id) \\ i <- [1..5]]         4 [ControlPos (Left, zero)],
        PopUpControl [("SelectState " +++ toString i, id) \\ i <- [1..5]] 5 [ControlSelectState Able],
        PopUpControl [("SelectState " +++ toString i, id) \\ i <- [1..5]] 1 [ControlSelectState Unable],
        PopUpControl [("Tip " +++ toString i, id) \\ i <- [1..5]]         2 [ControlTip "Some tip"],
        PopUpControl [("Width " +++ toString i, id) \\ i <- [1..5]]       3 [ControlWidth (PixelWidth 500)]
    ]
# controls = ButtonControl "For callbacks" [ControlId textid] :+: ListLS popups
# dialog = Dialog "Support - PopUpControl" controls [WindowClose (noLS closeProcess), WindowViewSize {w=1000,h=500}] // because vertical space isn't reserved properly
= startIO NDI Void (initialise dialog) [] world
where
    initialise dialog pst
    # (error,pst)       = openDialog 0 dialog pst
    | error <> NoError  = closeProcess pst
    | otherwise         = pst

    count :: Int Id (Int, PSt .l) -> (Int, PSt .l)
    count dx id (count,pst=:{io}) = (count + dx, appPIO (setControlText id (toString (count+dx))) pst)