Ur/Web Examples
Check-in [d033bf1632]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:- in jsMove switch back to signal-based instructions
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:d033bf1632ba42c17afc4509af4ebd53a9855c38
User & Date: beyert 2015-02-23 05:17:50
Context
2015-03-01
23:07
- attempt to provide server-side versions of periodic/periodicT, which were unsuccessful since sources and signals aren't allowed server side (eg. the error "Input to exported function 'PseudoRandomIota/randomPeriodic' involves one or more types that are disallowed for page handler inputs: Basis.signal, Basis.source") check-in: 56f4b59eef user: beyert tags: trunk
2015-02-23
05:17
- in jsMove switch back to signal-based instructions check-in: d033bf1632 user: beyert tags: trunk
03:42
- make jsMove more concise check-in: f85bb74c6b user: beyert tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to jsMove/jsMove.ur.

1
2
3
4
5
6
7
8
9
10
11
12
13
..
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
...
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
...
142
143
144
145
146
147
148
149
150
(* jsMove *)

type point = (int * int)
type point' = (source int * source int)
(* this is supposed to be an immutable source *)
type dyn_signal = source

val minPt : point = (0, 0)
val maxPt : point = (640, 480)
val initPt : point = (20, 20)

val show_list_int : show (list int) =
  let fun joinReverse' (lst: list int) (acc: string) : string = case lst of
................................................................................
  in case (touchOn', mouseOn', clickToMove') of
    (False, True, True) => JsMoveJs.onClick f
  | (False, True, False) => JsMoveJs.onMouseMove f
  | (True, True, True) => JsMoveJs.onTouchStart f
  | (True, True, False) => JsMoveJs.onTouchMove f
  | _ => nullifyMouseEvents touchOn' end

fun instructions (touchOn: bool) (keyOn: bool)
  (mouseOn: bool) (click: bool) : string =
  let val device = if touchOn then "touchscreen" else "mouse"
  in "Move the circle via " ^
    (if keyOn then "the arrow keys " else "") ^
    case (keyOn, mouseOn, click) of
      (True, True, True) => "or a mouse click"
    | (True, True, False) => " or a mouse movement"
    | (True, _, _) => ""
    | (False, True, True) => "a " ^ device ^ " click"
    | (False, True, False) => "a " ^ device ^ " movement"
    | _ => "clicking on one of the buttons to reactivate input" end

fun xinstructions (touchOn: dyn_signal bool) (keyOn: dyn_signal bool)
  (mouseOn: dyn_signal bool) (clickMove: dyn_signal bool) : signal xbody =
  touchOn' <- signal touchOn; keyOn' <- signal keyOn;
  mouseOn' <- signal mouseOn; clickMove' <- signal clickMove;
  return <xml>{[instructions touchOn' keyOn' mouseOn' clickMove']}</xml>

fun main_touch () : transaction page =
  x <- source (initPt.1: int); y <- source (initPt.2: int);
  keyOn <- source (False: bool);
  touchOn <- source (True: bool);
  mouseOn <- source (True: bool);
  clickToMove <- source (False: bool);
................................................................................
  <p>Touch Click to move: <dyn signal={clickToMove <- signal clickToMove;
                                       return <xml>{[clickToMove]}</xml>}/>
     <button value="Toggle Touch Click"
       onclick={fn _ => clickToMove' <- get clickToMove;
                set clickToMove (not clickToMove');
                setMouseEvents (s touchOn) (s mouseOn) (s clickToMove) (x, y)
                  minPt maxPt}/></p>
  <p><dyn signal={xinstructions touchOn keyOn mouseOn clickToMove}/></p>
  </body></xml>

fun main () : transaction page =
  x <- source (initPt.1: int); y <- source (initPt.2: int);
  keys <- source ([]: list int);
  keyOn <- source (True: bool);
  touchOn <- source (False: bool);
  mouseOn <- source (True: bool);
................................................................................
  <p>Click to move: <dyn signal={clickToMove <- signal clickToMove;
                                 return <xml>{[clickToMove]}</xml>}/>
  <button value="Toggle Click"
    onclick={fn _ => clickToMove' <- get clickToMove;
             set clickToMove (not clickToMove');
             setMouseEvents (s touchOn) (s mouseOn) (s clickToMove) (x, y)
               minPt maxPt}/></p>
  <p><dyn signal={xinstructions touchOn keyOn mouseOn clickToMove}/></p>
  </body></xml>




<
<







 







|
|



|







|
|
|
<
|







 







|
|







 







|
|
1
2
3
4


5
6
7
8
9
10
11
..
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78

79
80
81
82
83
84
85
86
...
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
...
139
140
141
142
143
144
145
146
147
(* jsMove *)

type point = (int * int)
type point' = (source int * source int)



val minPt : point = (0, 0)
val maxPt : point = (640, 480)
val initPt : point = (20, 20)

val show_list_int : show (list int) =
  let fun joinReverse' (lst: list int) (acc: string) : string = case lst of
................................................................................
  in case (touchOn', mouseOn', clickToMove') of
    (False, True, True) => JsMoveJs.onClick f
  | (False, True, False) => JsMoveJs.onMouseMove f
  | (True, True, True) => JsMoveJs.onTouchStart f
  | (True, True, False) => JsMoveJs.onTouchMove f
  | _ => nullifyMouseEvents touchOn' end

fun instructions (touchOn: bool) (keyOn: bool) (mouseOn: bool)
  (clickToMove: bool) : string =
  let val device = if touchOn then "touchscreen" else "mouse"
  in "Move the circle via " ^
    (if keyOn then "the arrow keys " else "") ^
    case (keyOn, mouseOn, clickToMove) of
      (True, True, True) => "or a mouse click"
    | (True, True, False) => " or a mouse movement"
    | (True, _, _) => ""
    | (False, True, True) => "a " ^ device ^ " click"
    | (False, True, False) => "a " ^ device ^ " movement"
    | _ => "clicking on one of the buttons to reactivate input" end

fun dynInstructions (touchOn: signal bool) (keyOn: signal bool)
  (mouseOn: signal bool) (clickToMove: signal bool) : signal xbody =
  to <- touchOn; ko <- keyOn; mo <- mouseOn; ctm <- clickToMove;

  return <xml>{[instructions to ko mo ctm]}</xml>

fun main_touch () : transaction page =
  x <- source (initPt.1: int); y <- source (initPt.2: int);
  keyOn <- source (False: bool);
  touchOn <- source (True: bool);
  mouseOn <- source (True: bool);
  clickToMove <- source (False: bool);
................................................................................
  <p>Touch Click to move: <dyn signal={clickToMove <- signal clickToMove;
                                       return <xml>{[clickToMove]}</xml>}/>
     <button value="Toggle Touch Click"
       onclick={fn _ => clickToMove' <- get clickToMove;
                set clickToMove (not clickToMove');
                setMouseEvents (s touchOn) (s mouseOn) (s clickToMove) (x, y)
                  minPt maxPt}/></p>
  <p><dyn signal={dynInstructions (s touchOn) (s keyOn) (s mouseOn)
                                  (s clickToMove)}/></p></body></xml>

fun main () : transaction page =
  x <- source (initPt.1: int); y <- source (initPt.2: int);
  keys <- source ([]: list int);
  keyOn <- source (True: bool);
  touchOn <- source (False: bool);
  mouseOn <- source (True: bool);
................................................................................
  <p>Click to move: <dyn signal={clickToMove <- signal clickToMove;
                                 return <xml>{[clickToMove]}</xml>}/>
  <button value="Toggle Click"
    onclick={fn _ => clickToMove' <- get clickToMove;
             set clickToMove (not clickToMove');
             setMouseEvents (s touchOn) (s mouseOn) (s clickToMove) (x, y)
               minPt maxPt}/></p>
  <p><dyn signal={dynInstructions (s touchOn) (s keyOn) (s mouseOn)
                                  (s clickToMove)}/></p></body></xml>