6265465eba713dfcab74319e987e5d4d98bf5667
[clean-tests.git] / 7gui / test.icl
1 module test
2
3 import Data.Func
4 import Data.Tuple
5 import System.Time
6
7 import iTasks
8 import iTasks.Extensions.DateTime
9 import iTasks.UI.Editor.Common
10
11 Start w = doTasks gui5 w
12
13 gui1 :: Int -> Task Int
14 gui1 c = viewInformation "Counter" [] c
15 >>* [OnAction (Action "Count") (withValue (Just o gui1 o inc))]
16
17 gui2 :: Task Real
18 gui2 = withShared 42.0 \sh->
19 updateSharedInformation "Celcius" [] sh
20 -|| updateSharedInformation "Fahrenheit"
21 [UpdateAs (\c->1.8*c+32.0) \_ f->(f-32.0)/1.8] sh
22
23 :: Flight
24 = OneWay Date
25 | Return (Date, Date)
26 derive class iTask Flight
27
28 gui3 :: Task Flight
29 gui3 = get currentDate
30 >>- \now->editChoice () [] ["one-way flight", "return flight"] (Just "one-way flight")
31 >&> \sh-> whileUnchanged sh \v->case fromJust v of
32 "one-way flight" = withShared now \sh->
33 updateSharedInformation () [] sh
34 -|| updateSharedInformation () [UpdateUsing toString const (gEditor{|*|} <<@ enabledAttr False)] sh
35 >>* [OnAction (Action "Book") $ ifValue (\_->True) $ return o OneWay]
36 "return flight"
37 = updateInformation () [] now
38 -&&- updateInformation () [] now
39 >>* [OnAction (Action "Book") $ ifValue (uncurry (<)) $ return o Return]
40
41 gui4 :: Timestamp Int -> Task Timestamp
42 gui4 startTime duration = withShared duration \duration->
43 viewSharedInformation "Elapsed time: " [ViewUsing toProgress progressBar] (currentTimestamp >*< duration)
44 -&&- viewSharedInformation () [ViewAs \now->on (-) toInt now startTime] currentTimestamp
45 -&&- updateSharedInformation "Duration: " [UpdateUsing id (const id) $ slider <<@ minAttr 0 <<@ maxAttr 3600] duration
46 >>* [OnAction (Action "Reset") $ always $ get (currentTimestamp >*< duration) >>- uncurry gui4]
47 where
48 toProgress (now, duration) =
49 (Just $ toInt $ on (-) (toReal o toInt) now startTime / toReal duration * 100.0, Nothing)
50
51 gui5 = withShared [(0, "Emil", "Hans"), (1, "Mustermann", "Max"), (2, "Tisch", "Roman")] \data->
52 enterInformation "Filter prefix" []
53 >&> \v->whileUnchanged (mapRead (fromMaybe " ") v) \filter->
54 tune ArrangeHorizontal
55 $ enterChoiceWithShared () [ChooseFromList (\(_, f, l)->f +++ ", " +++ l)] data
56 >&> \v->whileUnchanged v \selection->case selection of
57 Nothing = viewInformation "Nothing selected" [] () @? const NoValue
58 Just x = updateInformation () [] x