bork
[clean-tests.git] / 7gui / test.icl
1 module test
2
3 import StdMisc
4 import Data.Func
5 import Data.Tuple
6 import System.Time
7
8 import iTasks
9 import iTasks.UI.Editor.Common
10 import iTasks.Extensions.DateTime
11 import iTasks.Extensions.SVG.SVGEditor => qualified grid
12
13 import qualified Data.Map as DM
14 import Data.Map.GenJSON
15
16 //Start w = doTasks (gui1 0) w
17 //Start w = doTasks gui2 w
18 //Start w = doTasks gui3 w
19 //Start w = doTasks (get currentTimestamp >>- \t->gui4 30 t) w
20 //Start w = doTasks gui5 w
21 Start w = doTasks gui6 w
22
23 gui1 :: Int -> Task Int
24 gui1 c = viewInformation "Counter" [] c
25 >>* [OnAction (Action "Count") (withValue (Just o gui1 o inc))]
26
27 gui2 :: Task Real
28 gui2 = withShared 42.0 \sh->
29 updateSharedInformation "Celcius" [] sh
30 -|| updateSharedInformation "Fahrenheit"
31 [UpdateAs (\c->1.8*c+32.0) \_ f->(f-32.0)/1.8] sh
32
33 //This should be possible with just a custom editor...
34 :: Flight
35 = OneWay Date
36 | Return (Date, Date)
37 derive class iTask Flight
38 gui3 :: Task Flight
39 gui3 = get currentDate
40 >>- \now->editChoice () [] ["one-way flight", "return flight"] (Just "one-way flight")
41 >&> \sh-> whileUnchanged sh \v->case fromJust v of
42 "one-way flight" = withShared now \sh->
43 updateSharedInformation () [] sh
44 -|| updateSharedInformation () [UpdateUsing toString const (gEditor{|*|} <<@ enabledAttr False)] sh
45 >>* [OnAction (Action "Book") $ ifValue (\_->True) $ return o OneWay]
46 "return flight"
47 = updateInformation () [] now
48 -&&- updateInformation () [] now
49 >>* [OnAction (Action "Book") $ ifValue (uncurry (<)) $ return o Return]
50
51 gui4 :: Timestamp Int -> Task Timestamp
52 gui4 startTime duration = withShared duration \duration->
53 viewSharedInformation "Elapsed time: " [ViewUsing toProgress progressBar] (currentTimestamp >*< duration)
54 -&&- viewSharedInformation () [ViewAs \now->on (-) toInt now startTime] currentTimestamp
55 -&&- updateSharedInformation "Duration: " [UpdateUsing id (const id) $ slider <<@ minAttr 0 <<@ maxAttr 3600] duration
56 >>* [OnAction (Action "Reset") $ always $ get (currentTimestamp >*< duration) >>- uncurry gui4]
57 where
58 toProgress (now, duration) =
59 (Just $ toInt $ on (-) (toReal o toInt) now startTime / toReal duration * 100.0, Nothing)
60
61 :: Name = {name :: String, surname :: String}
62 name :: String String -> Name
63 name name surname = {name=name, surname=surname}
64 derive class iTask Name
65 instance toString Name where toString n = n.Name.name +++ ", " +++ n.surname
66
67 gui5 :: Task (Int, Name)
68 gui5 = withShared ('DM'.fromList [(0, name "Emil" "Hans"), (1, name "Mustermann" "Max"), (2, name "Tisch" "Roman")]) \data->
69 enterInformation "Filter prefix" []
70 >&> \v->whileUnchanged (mapRead (fromMaybe " ") v) \filter->
71 tune ArrangeHorizontal
72 $ enterChoiceWithShared () [ChooseFromList (toString o snd)] (mapRead 'DM'.toList data)
73 >&> \sh->whileUnchanged sh \v->case v of
74 Nothing = return () @? const NoValue
75 Just x = updateInformation () [UpdateAs snd (tuple o fst)] x
76 >^* [ OnAction (Action "new") $ always $ upd (\l->'DM'.put (inc $ maxList $ 'DM'.keys l) (name "-" "-") l) data
77 , OnAction (Action "update") $ withValue \(i, n)->Just $ upd ('DM'.put i n) data
78 , OnAction (Action "delete") $ withValue \(i, n)->Just $ upd ('DM'.del i) data
79 ]
80
81 gui6 :: Task [(Real, Real, Real)]
82 gui6 = updateInformation ()
83 [UpdateUsing id (const id) (fromSVGEditor svged)]
84 [(5.0, 5.0, 5.0)]
85
86 svged :: SVGEditor [(Real, Real, Real)] [(Real, Real, Real)]
87 svged = {initView=id, renderImage=renderImage, updModel=const id}
88 where
89 renderImage _ images ts
90 # (_, images) = trace_stdout ("img: ", images)
91 = collage [(px x, px y)\\(_, x, y)<-images] [circle (px r)\\(r, _, _)<-images]
92 $ Host $ rect (px 100.0) (px 100.0)
93 <@< {fill=toSVGColor "white"}
94 <@< {onclick=clicker,local=False}
95
96 clicker m = jsTrace "click" [(5.0, 10.0, 10.0):m]
97
98 import Debug.Trace, StdDebug
99 import iTasks.UI.JavaScript