summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYakov Goldberg <yakov.g@samsung.com>2012-11-20 16:20:13 +0200
committerYakov Goldberg <yakov.g@samsung.com>2012-11-20 16:21:50 +0200
commitfb3df32b0e5a92882cf1f45da9577a8ecae4fcba (patch)
treecc93263e02ff62fdc53cb2df6ac4b1c1eb0dc8d6
parent26ddb3073c77bdd564a411e1559a07b256cb3874 (diff)
JS examples added
-rw-r--r--examples/elw_button.js159
-rw-r--r--examples/elw_button_old.js247
-rw-r--r--examples/elw_eoisa.js24
-rw-r--r--examples/elw_mixin.js18
-rw-r--r--examples/elw_signal.js54
5 files changed, 502 insertions, 0 deletions
diff --git a/examples/elw_button.js b/examples/elw_button.js
new file mode 100644
index 0000000..b2eefd3
--- /dev/null
+++ b/examples/elw_button.js
@@ -0,0 +1,159 @@
1//var elm = require('jse');
2var elm = require('jse');
3
4//var m = new elm.Mixin()
5
6function cb_add(par){
7 par.alert(par.text + ": calback_added")
8}
9
10function cb_del(par){
11 par.alert(par.text + ": calback_deleted")
12}
13
14//==============================
15var global_obj
16
17function freeze_this(par){
18 par.alert("Object: " + par.text)
19 par.alert("Freezing cb for this obj")
20 global_obj = par
21 par.event_freeze()
22 par.alert("Freeze count = " + par.event_freeze_get())
23}
24
25function thaw_cb(par){
26 par.alert("Thawing cb for global_obj")
27 global_obj.event_thaw()
28}
29//==================================
30
31function numbers_cb(par){
32 par.alert("numbers_cb")
33 par.no_par()
34
35 par.ints(0, 0)
36 print (" === Testing int ===")
37
38 o = par.ints(1, 2, 3)
39 par.alert("xx: " + o.xx)
40 par.alert("yy: " + o.yy)
41
42 par.par_by_ref(1, 2, 3)
43
44
45 print (" === Testing floats ===")
46 a = 7.32
47 b = -21474.5134
48 o = par.floats(a, b)
49
50 par.alert("bb: " + o.bb)
51 par.alert("cc: " + o.cc)
52}
53
54function cb3(par)
55{
56 par.alert("callback called for: " + par.text)
57 par.alert("getting size")
58
59 o = par.size
60 par.alert("W: " + o.w)
61 par.alert("H: " + o.h)
62
63 o = par.position
64 par.alert("X: " + o.x)
65 par.alert("Y: " + o.y)
66}
67
68
69
70var w = elm.ElwWin({
71 size: { w: 300, h: 350},
72 elements: {
73 shalom_bt: elm.ElwButton({
74 text: "Hello",
75 position : {x: 30, y: 30},
76 size: {w: 210, h: 60},
77 color: {r: 159, g: 245, b: 255, a: 255},
78 eo_ev_callback_add : cb_add,
79 eo_ev_callback_del : cb_del,
80 ev_clicked : cb3
81 }),
82
83 ba: elm.ElwButton({
84 text: "(B) ADD cb",
85 position : {x: 30, y: 100},
86 size: {w: 100, h: 50},
87 color: {r: 255, g: 0, b: 255, a: 255},
88 ev_clicked : cb3
89 }),
90
91 red_bt: elm.ElwBoxedbutton({
92 text: "Red button",
93 position : {x: 140, y: 100},
94 size: {w: 100, h: 50},
95 color: {r: 255, g: 0, b: 5, a: 255},
96 ev_clicked : cb3
97
98 }),
99
100 but1: elm.ElwButton({
101 text: "1st but in box",
102 //position : { x: 250, y: 100},
103 //size: { w: 90, h: 20},
104 color: { r: 255, g: 0, b: 255, a: 255},
105 ev_clicked : thaw_cb
106 }),
107
108 but2: elm.ElwButton({
109 text: "2nd but in box",
110 //position : { x: 270, y: 150},
111 //size: { w: 90, h: 50},
112 color: {r: 240, g: 240, b: 0, a: 255},
113 ev_clicked : freeze_this
114 }),
115
116 box : elm.ElwBox ({
117 position : {x: 140, y: 170},
118 size: {w: 100, h: 50},
119 }),
120
121 pb: elm.ElwButton({
122 text: "But in BB (num)",
123 //position : { x: 310, y: 150},
124 //size: { w: 70, h: 50},
125 color: {r: 240, g: 240, b: 245, a: 255},
126 ev_clicked : numbers_cb
127 }),
128
129 ebb: elm.ElwBoxedbutton({
130 text: "BoxedButton",
131 position : {x: 30, y: 170},
132 size: { w: 100, h: 50},
133 color: { r: 100, g: 85, b: 255, a: 255},
134 //ev_clicked : freeze_all,
135 }),
136 }
137});
138
139
140var e = elm.realise(w);
141
142
143e.elements.box.pack_end(e.elements.but1)
144e.elements.box.pack_end(e.elements.but2)
145e.elements.ebb.pack_end(e.elements.pb)
146
147//e.elements.shalom_bt.eo_ev_callback_add = cb_add
148e.elements.shalom_bt.ev_clicked = cb3
149
150
151
152elm.ElwWin.event_global_freeze()
153elm.ElwWin.event_global_thaw()
154
155
156
157
158
159
diff --git a/examples/elw_button_old.js b/examples/elw_button_old.js
new file mode 100644
index 0000000..f71790a
--- /dev/null
+++ b/examples/elw_button_old.js
@@ -0,0 +1,247 @@
1var elm = require('elm');
2//var m = new elm.Mixin()
3
4function cb_add(par){
5 par.alert(par.text + ": calback_added")
6}
7
8function cb_del(par){
9 par.alert(par.text + ": calback_deleted")
10}
11
12//==============================
13var global_obj
14
15function freeze_this(par){
16 par.alert("Object: " + par.text)
17 par.alert("Freezing cb for this obj")
18 global_obj = par
19 par.event_freeze()
20 par.alert("Freeze count = " + par.event_freeze_get())
21}
22
23function thaw_cb(par){
24 par.alert("Thawing cb for global_obj")
25 global_obj.event_thaw()
26}
27//==================================
28
29function numbers_cb(par){
30 par.alert("numbers_cb")
31 par.no_par()
32
33 par.ints(0, 0)
34 print (" === Testing int ===")
35
36 o = par.ints(1, 2, 3)
37 par.alert("xx: " + o.xx)
38 par.alert("yy: " + o.yy)
39
40 par.par_by_ref(1, 2, 3)
41
42 // par.floats(0.6, 43.345)
43 print (" === Testing floats ===")
44 a = 7.32
45 b = -21474.5134
46 o = par.floats(a, b)
47
48 par.alert("bb: " + o.bb)
49 par.alert("cc: " + o.cc)
50
51
52}
53
54function cb3(par){
55 par.alert("callback called for: " + par.text)
56 par.alert("getting size")
57
58 o = par.size
59 par.alert("W: " + o.w)
60 par.alert("H: " + o.h)
61
62 o = par.position
63 par.alert("X: " + o.x)
64 par.alert("Y: " + o.y)
65}
66
67var w = elm.ElwWin({
68 size: { w: 300, h: 350},
69 elements: {
70 shalom_bt: elm.ElwButton({
71 text: "שלום",
72 position : { x: 30, y: 30},
73 size: { w: 210, h: 60},
74 color: { r: 159, g: 245, b: 255, a: 255},
75 eo_ev_callback_add : cb_add,
76 eo_ev_callback_del : cb_del,
77 ev_clicked : cb3
78 }),
79
80 ba: elm.ElwButton({
81 text: "(B) ADD cb",
82 position : { x: 30, y: 100},
83 size: { w: 100, h: 50},
84 color: { r: 255, g: 0, b: 255, a: 255},
85 ev_clicked : cb3
86 }),
87
88 red_bt: elm.ElwBoxedbutton({
89 text: "Красная кнопка",
90 position : { x: 140, y: 100},
91 size: { w: 100, h: 50},
92 color: { r: 255, g: 0, b: 5, a: 255},
93 //ev_clicked : cb2
94
95 }),
96
97 but1: elm.ElwButton({
98 text: "1st but in box (thaw_cb)",
99 //position : { x: 250, y: 100},
100 //size: { w: 90, h: 20},
101 color: { r: 255, g: 0, b: 255, a: 255},
102 ev_clicked : thaw_cb
103 }),
104
105 but2: elm.ElwButton({
106 text: "2nd but in box (freeze_this)",
107 //position : { x: 270, y: 150},
108 //size: { w: 90, h: 50},
109 color: { r: 240, g: 240, b: 0, a: 255},
110 ev_clicked : freeze_this
111
112 }),
113
114 box : elm.ElwBox ({
115 position : {x: 140, y: 170},
116 size: { w: 50, h: 100},
117
118 }),
119
120 pb: elm.ElwButton({
121 text: "But in BB (num)",
122 // position : { x: 310, y: 150},
123 // size: { w: 70, h: 50},
124 color: { r: 240, g: 240, b: 245, a: 255},
125 ev_clicked : numbers_cb
126
127 }),
128
129 ebb: elm.ElwBoxedbutton({
130 text: "BoxedButton",
131 position : { x: 30, y: 170},
132 size: { w: 100, h: 50},
133 color: { r: 100, g: 85, b: 255, a: 255},
134 //ev_clicked : freeze_all,
135 }),
136
137/*
138 bb2: elm.ElwBoxedbutton({
139 text: "BoxedButton",
140// mixin: "hello, שלום, привет",
141 position : { x: 180, y: 250},
142 size: { w: 100, h: 65},
143 color: { r: 0, g: 255, b: 0, a: 255},
144 ev_clicked : cb2,
145 // on_test : cb1,
146
147/*
148 disabled1: elm.Button({
149 text: "Dis1",
150 x: 10,
151 y: 160,
152 width: 100,
153 height: 15,
154 enabled: true,
155 on_click : ff,
156 }),
157
158 disabled2: elm.Button({
159 text: "Dis2",
160 x: 10,
161 y: 190,
162 width: 100,
163 height: 15,
164 enabled: true,
165 on_click : ff,
166 }),
167*/
168/*
169 bb2: elm.ElwBoxedbutton({
170 text: "BoxedButton",
171// mixin: "hello, שלום, привет",
172 position : { x: 180, y: 250},
173 size: { w: 100, h: 65},
174 color: { r: 0, g: 255, b: 0, a: 255},
175 ev_clicked : cb2,
176 // on_test : cb1,
177
178 elements : {
179 label_only: elm.ElwButton({
180 color: { r: 10, g: 20, b: 30, a: 255},
181 text: "button in the boxedbutton!",
182 size: { w: 80, h: 65},
183 }),
184 },
185 }),
186*/
187
188/*
189 disabled: elm.Button({
190 text: "Don",
191 x: 10,
192 y: 160,
193 width: 100,
194 height: 300,
195 enabled: true
196 }),
197
198 label_only: elm.Button({
199 weight: { x: 1.0, y: 1.0 },
200 style: "anchor",
201 text: "hello!",
202 x: 110,
203 y: 260,
204 width: 80,
205 height: 65
206 }),
207*/
208/*
209 hbox2 : elm.ElwBox ({
210 position : {x: 90, y: 180},
211
212 elements : {
213 label_only2: elm.ElwButton({
214 text: "button in the box! + exit()",
215 // pos : {x: 110, y: 260},
216 color: { r: 0, g: 5, b: 255, a: 255},
217 size: { w: 80, h: 65},
218 on_test: function(par){
219 par.alert("close application")
220 elm.exit()
221 }
222
223 }),
224 },
225 }),
226*/
227
228 }
229});
230
231
232var e = elm.realise(w);
233
234e.elements.box.pack_end(e.elements.but1)
235e.elements.box.pack_end(e.elements.but2)
236e.elements.ebb.pack_end(e.elements.pb)
237
238//e.elements.shalom_bt.eo_ev_callback_add = cb_add
239e.elements.shalom_bt.ev_clicked = cb3
240
241
242
243elm.ElwWin.event_global_freeze()
244elm.ElwWin.event_global_thaw()
245
246
247
diff --git a/examples/elw_eoisa.js b/examples/elw_eoisa.js
new file mode 100644
index 0000000..636f362
--- /dev/null
+++ b/examples/elw_eoisa.js
@@ -0,0 +1,24 @@
1//var elm = require('jstest');
2var elm = require('jseoisa');
3
4var so = new elm.Simple()
5
6so.a = 2
7a = so.a
8a2 = so.a_square
9a3 = so.a_power_3
10print("a = " + a + "; a^2 = " + a2 + "; a^3 = " + a3)
11
12print("*******************************\n")
13
14
15var co = new elm.Complex()
16co.a = 3
17a = co.a
18a2 = co.a_square
19a3 = co.a_power_3
20print("a = " + a + "; a^2 = " + a2 + "; a^3 = " + a3)
21
22elm.exit()
23
24
diff --git a/examples/elw_mixin.js b/examples/elw_mixin.js
new file mode 100644
index 0000000..e505714
--- /dev/null
+++ b/examples/elw_mixin.js
@@ -0,0 +1,18 @@
1var elm = require('jsmixin');
2
3var obj1 = new elm.Simple({a:5, b:5})
4
5obj1.a = 1
6obj1.b = 2
7sum = obj1.ab_sum
8
9print("Sum for obj1: " + sum)
10
11
12var obj2 = elm.Simple({a:3, b:4})
13var e = elm.realise(obj2)
14
15sum = e.ab_sum
16print("Sum for obj1: " + sum)
17
18elm.exit()
diff --git a/examples/elw_signal.js b/examples/elw_signal.js
new file mode 100644
index 0000000..df00242
--- /dev/null
+++ b/examples/elw_signal.js
@@ -0,0 +1,54 @@
1var elm = require('jssimple');
2
3
4function cb_add(par){
5 print("Callback on callback adding")
6}
7
8var poo = function(pa){
9 print("Callback on changing: a = " + pa.a);
10}
11
12
13var ms = new elm.Simple()
14
15print("\nSetting a...")
16ms.a = 12345678
17print("a = " + ms.a + "\n")
18
19print("\nAdding callback...")
20ms.eo_ev_callback_add = cb_add
21ms.ev_a_changed = poo
22
23print("\nSetting b(a) to 896...")
24ms.b = 896
25print("Reading \"b\" (no getter for \"b\" prop): " + ms.b)
26
27
28print("\nSetting c(a) to 123...")
29ms.c = 123
30print("Reading \"c\" (no setter for \"c\" prop, so it should be 896): " + ms.c + "\n")
31
32
33
34print("\nFreezing callback...")
35ms.event_freeze()
36ms.a = 123
37
38print("\nThawing callback...")
39ms.event_thaw()
40ms.a = 123
41
42
43
44/*
45
46var ss = elm.realise(elm.Simple({a:5, on_change:poo, b:55}))
47
48ss.ev_a_changed = cb
49ss.a = 123
50*/
51
52elm.exit()
53
54