forked from arpit/openpyro
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTestList.as
More file actions
356 lines (284 loc) · 9.87 KB
/
TestList.as
File metadata and controls
356 lines (284 loc) · 9.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
package
{
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.events.*;
import org.openPyro.aurora.AuroraContainerSkin;
import org.openPyro.controls.List;
import org.openPyro.controls.ScrollBar;
import org.openPyro.controls.events.ListEvent;
import org.openPyro.core.*;
import org.openPyro.effects.Effect;
import org.openPyro.events.PyroEvent;
import org.openPyro.examples.DimensionMarkerSkin;
import org.openPyro.examples.HaloTrackSkin;
import org.openPyro.examples.SimpleButtonSkin;
import org.openPyro.layout.*;
import org.openPyro.painters.FillPainter;
import org.openPyro.painters.GradientFillPainter;
import org.openPyro.utils.GlobalTimer;
[SWF(frameRate="30", backgroundColor="#8899aa")]
public class TestList extends Sprite
{
private var list:List;
private var container:UIContainer;
public function TestList()
{
stage.scaleMode = "noScale"
stage.align = "TL"
//testSimpleChildren()
//testSimpleScroll()
testListInLayout()
stage.addEventListener(Event.RESIZE, onStageResize)
var globalTimer:GlobalTimer = new GlobalTimer(stage);
globalTimer.start()
stage.addEventListener(MouseEvent.CLICK, onStageClick);
}
private function onStageClick(event:MouseEvent):void
{
}
private function testSimpleScroll():void{
container = new UIContainer();
container.name = "rootContainer";
container.addEventListener(PyroEvent.UPDATE_COMPLETE,onContainerUpdate);
container.width = stage.stageWidth/3
container.height = stage.stageHeight/3;
addChild(container);
container.backgroundPainter = new FillPainter(0xcccccc)
container.skin = new AuroraContainerSkin();
//createScrollBarFromStyle2();
container.x = 100
container.y = 100;
var spacer:UIControl = new UIControl();
spacer.size(800,400)
spacer.backgroundPainter = new FillPainter(0xff0000);
container.addChild(spacer);
}
private var uic:UIControl
private function testSimpleChildren():void{
uic = new UIControl()
uic.name = "uic1"
uic.backgroundPainter = new FillPainter(0xcdcdcd);
this.uic.width = stage.stageWidth/4;
this.uic.height = stage.stageHeight/4;
addChild(uic)
uic.x = uic.y = 100;
var uic2:UIControl = new UIControl()
uic2.name = "uic2"
uic2.backgroundPainter = new FillPainter(0x00ff00);
uic2.percentUnusedWidth = 50
uic2.percentUnusedHeight = 50;
uic.addChild(uic2)
uic.addEventListener(PyroEvent.UPDATE_COMPLETE, onContainerUpdate);
}
private var s1:UIControl
private var s2:UIControl;
private function testListInLayout():void
{
createList()
createContainer();
container.addChild(list);
s1 = createShape(0xff0000);
container.addChild(s1);
//stage.addEventListener(MouseEvent.CLICK, onMouseClick);
s2 = createShape(0x00ff00);
s2.name = "green";
container.addChild(s2);
//container.validateSize()
container.layout = new HLayout(0);
}
private function onMouseClick(event:Event):void
{
stage.removeEventListener(MouseEvent.CLICK, onMouseClick);
var s1:UIControl = new UIControl()
s1.backgroundPainter = new GradientFillPainter([0xff0000,0x0000ff])
s1.width = container.width+100
s1.height = container.height+100
s1.name = "red"
container.addChild(s1);
stage.dispatchEvent(new Event(Event.RESIZE));
}
private function createContainer():void{
container = new UIContainer();
container.name = "rootContainer";
container.addEventListener(PyroEvent.UPDATE_COMPLETE,onContainerUpdate);
container.width = stage.stageWidth/3;
container.height = stage.stageHeight/3;
addChild(container);
container.backgroundPainter = new FillPainter(0xcccccc)
container.skin = new AuroraContainerSkin();
//createScrollBarFromStyle2();
container.x = 100
container.y = 100;
}
private function onContainerUpdate(event:PyroEvent):void
{
// trace("[container]"+container.height, container.measuredHeight)
/*
trace("Container w/h : "+container.width, container.height)
if(list){
trace("list w/h: ", list.width, list.height)
}
if(s1){
trace("S1 w/h: ", s1.width, s1.height)
}
if(s2){
trace("s2 w/h: ", s2.width, s2.height)
}
*/
}
private function createShape(color:uint):UIControl
{
var spacer:UIControl = new UIControl();
spacer.size("60%","100%");
spacer.skin = new DimensionMarkerSkin();
spacer.backgroundPainter = new FillPainter(color);
return spacer;
}
private function createList():List{
list = new List();
list.addEventListener(ListEvent.ITEM_CLICK, onListClick);
list.width = 200
list.percentUnusedHeight = 100;
var rendererFactory:ClassFactory = new ClassFactory(Renderer);
rendererFactory.properties = {width:500, height:30}
list.itemRenderer = rendererFactory;
list.dataProvider = ["a", "a", "a", "a", "e", "f", "c", "b", "a"];
list.skin = new AuroraContainerSkin()
return list;
}
private function onListClick(_e:ListEvent):void
{
//container.horizontalScrollBar.visible = false;
//trace('list height: '+list.height, 'list measuredht: '+list.measuredHeight, 'hScrollBar y'+list.horizontalScrollBar.y)
trace(List(_e.target).selectedIndex+", "+List(_e.target).selectedItem);
Effect.on(DisplayObject(_e.target)).slideDown(1);
}
public function onStageResize(event:Event):void{
//trace(container.width, container.height)
if(uic){
this.uic.width = stage.stageWidth/4;
this.uic.height = stage.stageHeight/4;
}
if(!container) return;
container.width = stage.stageWidth/3;
container.height = stage.stageHeight/3;
}
private function createScrollBarFromStyle():void
{
/*var vSliderSkin:SliderSkin = new SliderSkin(new SimpleButtonSkin(), new HaloTrackSkin());
var vScrollBarSkin:ScrollBarSkin = new ScrollBarSkin(vSliderSkin, new SimpleButtonSkin(0), new SimpleButtonSkin(0));
var hSliderSkin:SliderSkin = new SliderSkin(new SimpleButtonSkin(), new HaloTrackSkin(Math.PI/2));
var hScrollBarSkin:ScrollBarSkin = new ScrollBarSkin(hSliderSkin, new SimpleButtonSkin(0), new SimpleButtonSkin(0));
var listSkin:UIContainerSkin = new UIContainerSkin(vScrollBarSkin,hScrollBarSkin);
list.skin = listSkin;
*/
}
private function createScrollBarFromStyle2():void
{
/*var vSliderSkin:SliderSkin = new SliderSkin(new SimpleButtonSkin(), new HaloTrackSkin());
var vScrollBarSkin:ScrollBarSkin = new ScrollBarSkin(vSliderSkin, new SimpleButtonSkin(0), new SimpleButtonSkin(0));
var hScrubberSkin:SimpleButtonSkin = new SimpleButtonSkin()
hScrubberSkin.name = "hScrubber"
var hSliderSkin:SliderSkin = new SliderSkin(hScrubberSkin, new HaloTrackSkin(Math.PI/2));
var hScrollBarSkin:ScrollBarSkin = new ScrollBarSkin(hSliderSkin, new SimpleButtonSkin(0), new SimpleButtonSkin(0));
var listSkin:UIContainerSkin = new UIContainerSkin(vScrollBarSkin,hScrollBarSkin);
container.skin = listSkin;
*/
}
private function createVScrollBar():ScrollBar{
var verticalScrollBar:ScrollBar = new ScrollBar(Direction.VERTICAL);
verticalScrollBar.width = 15;
verticalScrollBar.height = 300;
addChild(verticalScrollBar);
verticalScrollBar.slider.trackSkin = new HaloTrackSkin();
verticalScrollBar.slider.thumbSkin = new SimpleButtonSkin();
verticalScrollBar.incrementButtonSkin = new SimpleButtonSkin()
verticalScrollBar.decrementButtonSkin = new SimpleButtonSkin();
return verticalScrollBar;
}
}
}
import flash.display.Sprite;
import flash.display.Graphics;
import flash.geom.ColorTransform;
import org.openPyro.core.UIControl;
import flash.text.TextField;
import flash.events.MouseEvent;
import org.openPyro.controls.listClasses.IListDataRenderer;
import org.openPyro.controls.listClasses.BaseListData;
internal class Renderer extends UIControl implements IListDataRenderer{
private var txt:TextField;
private var m_selected:Boolean;
private var m_bld:BaseListData
public function Renderer(){
txt = new TextField()
//txt.border=true;
addChild(txt);
txt.autoSize = "left";
txt.wordWrap=true;
txt.selectable=false;
//this.addEventListener(MouseEvent.CLICK, onMouseClick)
//this.height = 30;
}
private var addHt:Number = 0
private function onMouseClick(event:MouseEvent):void{
addHt = 100;
this.invalidateSize();
}
public function set data(d:Object):void{
_data = d;
this.txt.text = String(d);
invalidateSize();
}
private var _data:Object;
public function set label(s:String):void{
_data = s;
this.txt.text = s;
this.invalidateSize();
}
override public function measure():void{
super.measure()
//if(this.txt.text == "1"){
//trace(this.txt.text + ':measuring height: '+ _measuredHeight);
//}
//this.invalidateDisplayList()
//trace('[ ROOT set height ]'+_measuredHeight)
}
public function get data():Object
{
return _data;
}
override public function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
if(this.txt.text == "1"){
//trace('updating dl: '+unscaledHeight);
}
super.updateDisplayList(unscaledWidth, unscaledHeight);
txt.width = unscaledWidth-20
txt.x = 10
txt.y = 10
txt.height = 20
var gr:Graphics = this.graphics;
gr.clear()
gr.lineStyle(1, 0x6ab0f7)
gr.beginFill(0xcccccc)
gr.drawRect(0,0,unscaledWidth,unscaledHeight);
gr.endFill();
}
public function get selected():Boolean {
return m_selected;
}
public function set selected(_selected:Boolean):void {
//var e:Error = new Error();
//trace(e.getStackTrace());
m_selected = _selected;
if(m_selected) {
this.transform.colorTransform = new ColorTransform(1.1, 1.1, 1.1);
} else {
this.transform.colorTransform = new ColorTransform(1.0, 1.0, 1.0);
}
}
public function set baseListData(_bld:BaseListData):void {
m_bld = _bld;
}
}