module support_button

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

import StdEnv, StdIO

Start :: *World -> *World
Start world
# (id, world) = openId world 
# buttons = [
        ButtonControl "Function"        [ControlFunction (count 1 id)],
        ButtonControl "Hide"            [ControlHide],
        ButtonControl "Id + Width"      [ControlId id, ControlWidth (PixelWidth 250)],
        ButtonControl "ModsFunction"    [ControlModsFunction (modf id)],
        ButtonControl "Pos"             [ControlPos (Left, zero)],
        ButtonControl "SelectState"     [ControlSelectState Able],
        ButtonControl "SelectState"     [ControlSelectState Unable],
        ButtonControl "Tip"             [ControlTip "Some tip"],
        ButtonControl "Width"           [ControlWidth (PixelWidth 250)]
    ]
# controls = ListLS buttons
# dialog = Dialog "Support - ButtonControl" controls [WindowClose (noLS closeProcess)]
= 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)

    modf :: Id Modifiers -> (Int, PSt .l) -> (Int, PSt .l)
    modf id mods = \(count,pst=:{io}) . (count, appPIO (setControlText id (toString mods)) pst)