diff options
author | Camil Staps | 2015-08-21 14:33:40 +0200 |
---|---|---|
committer | Camil Staps | 2015-08-21 14:33:40 +0200 |
commit | a7fd0f20297f3ebbc8009a9fa9f5c71e6a3dd16c (patch) | |
tree | 03d21e2bfb0221d2a16252da15b913997e1a7c95 /tut10_4_2.icl | |
parent | Tut 10.4.1 Talk windows (diff) |
Tut 10.4.2 Resetting the counter
Diffstat (limited to 'tut10_4_2.icl')
-rw-r--r-- | tut10_4_2.icl | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tut10_4_2.icl b/tut10_4_2.icl new file mode 100644 index 0000000..58d9f26 --- /dev/null +++ b/tut10_4_2.icl @@ -0,0 +1,40 @@ +module tut10_4_2 + +// ******************************************************************************** +// Clean tutorial example program. +// +// This program defines a Controls component that implements a manually settable +// counter. A receiver is used to add a reset option. +// ******************************************************************************** + +import StdEnv, StdIO + +Start :: *World -> *World +Start world = startIO NDI Void initialise [] world +where + initialise pst + # (displayId, pst) = accPIO openId pst + # (resetId, pst) = accPIO openRId pst + # (error, pst) = openDialog Void (dialog displayId resetId) pst + | error <> NoError = abort "Counter could not open Dialog." + | otherwise = pst + +dialog displayId resetId = Dialog "Counter" (counter :+: resetButton) [WindowClose (noLS closeProcess)] +where + counter = { newLS = initcount, + newDef = LayoutControl (EditControl (toString initcount) (PixelWidth (hmm 50.0)) 1 [ControlId displayId, ControlSelectState Unable] :+: + ButtonControl "-" [ControlFunction (count(-1)), ControlWidth (PixelWidth (hmm 25.0)), ControlPos (BelowPrev, zero)] :+: + ButtonControl "+" [ControlFunction (count 1 ), ControlWidth (PixelWidth (hmm 25.0))] :+: + Receiver resetId reset []) + [ControlPos (Center, zero), ControlHMargin 0 0, ControlVMargin 0 0, ControlItemSpace 0 0] } + where + initcount = 0 + + count :: Int (Int, PSt .l) -> (Int, PSt .l) + count dx (count, pst) = (count + dx, appPIO (setControlText displayId (toString (count+dx))) pst) + + reset :: m (Int, PSt .l) -> (Int, PSt .l) + reset _ (_, pst) = (initcount, appPIO (setControlText displayId (toString initcount)) pst) + + resetButton = ButtonControl "Reset" [ControlFunction (noLS (snd o syncSend resetId undef)), ControlPos (Center, zero)] + |