@@ -23,20 +23,21 @@ class Platform {
23
23
}
24
24
25
25
class Util {
26
- static function format ( fmt : string , list : int [ ] ) : string {
27
- return fmt . replace ( / % / g, ( s ) - > {
28
- return list [ s as int ] as string;
26
+ static function format ( fmt : string , list : variant [ ] ) : string {
27
+ return fmt . replace ( / % \d + / g, ( s ) - > {
28
+ var index = s . slice ( 1 ) as int - 1 ;
29
+ return list [ index ] as string ;
29
30
} ) ;
30
31
}
32
+
33
+ static function format ( fmt : string , list : int [ ] ) : string {
34
+ return Util . format ( fmt , list as __noconvert__ variant [ ] ) ;
35
+ }
31
36
static function format ( fmt : string , list : number [ ] ) : string {
32
- return fmt . replace ( / % / g, ( s ) - > {
33
- return list [ s as int ] as string;
34
- } ) ;
37
+ return Util . format ( fmt , list as __noconvert__ variant [ ] ) ;
35
38
}
36
39
static function format ( fmt : string , list : string [ ] ) : string {
37
- return fmt . replace ( / % / g, ( s ) - > {
38
- return list [ s as int ] as string;
39
- } ) ;
40
+ return Util . format ( fmt , list as __noconvert__ variant [ ] ) ;
40
41
}
41
42
42
43
static function createTextNode ( s : string ) : web . Node {
@@ -65,7 +66,14 @@ class Util {
65
66
}
66
67
67
68
static function borderWithColor ( color : Color ) : string {
68
- return "solid 1px " + color . toStyle ( ) ;
69
+ return "solid 1px " + color . toString ( ) ;
70
+ }
71
+
72
+
73
+ static function applyGradient ( style : web . CSSStyleDeclaration , type : string , begin : string , end : string , fromColor : Color , toColor : Color ) : void {
74
+ var s = Util . format ( "-webkit-gradient(%1, %2, %3, from(%4), to(%5))" ,
75
+ [ type , begin , end , fromColor . toString ( ) , toColor . toString ( ) ] ) ;
76
+ style . background = s ;
69
77
}
70
78
}
71
79
@@ -103,7 +111,7 @@ class Util {
103
111
}
104
112
105
113
mixin Responder {
106
-
114
+ // TODO
107
115
}
108
116
109
117
class Application implements Responder {
@@ -112,7 +120,6 @@ class Application implements Responder {
112
120
113
121
function constructor ( ) {
114
122
this . _view = new View ( ) ;
115
- this . _view . setFrame ( new Rectangle ( 0 , 0 , Platform . getWidth ( ) , Platform . getHeight ( ) ) ) ;
116
123
Application . resetStyles ( ) ;
117
124
}
118
125
@@ -274,21 +281,11 @@ mixin Appearance {
274
281
}
275
282
276
283
class View implements Responder , Appearance {
277
- var _frame : Rectangle = new Rectangle ( 0 , 0 , 0 , 0 ) ;
278
- var _autoSized : boolean = true ;
279
-
280
284
var _backgroundColor : Color = Color . WHITE ;
281
285
282
286
var _parent : View = null ;
283
287
var _subviews = new Array . < View > ( ) ;
284
288
285
- function getFrame ( ) : Rectangle {
286
- return this . _frame ;
287
- }
288
- function setFrame ( rect : Rectangle ) : void {
289
- this . _frame = rect ;
290
- }
291
-
292
289
function getBackgroundColor ( ) : Color {
293
290
return this . _backgroundColor ;
294
291
}
@@ -311,16 +308,6 @@ class View implements Responder, Appearance {
311
308
view . _parent = this ;
312
309
}
313
310
314
- function calculateFrame ( ) : Rectangle {
315
- var frame = new Rectangle ( 0 , 0 , this . _frame . size . width , this . _frame . size . height ) ;
316
- for ( var v = this ; v != null ; v = v . getParent ( ) ) {
317
- var origin = v . getFrame ( ) . origin ;
318
- frame . origin . x += origin . x ;
319
- frame . origin . y += origin . y ;
320
- }
321
- return frame ;
322
- }
323
-
324
311
function onClick ( cb : function ( :MouseEvent ) :void ) : void {
325
312
var listener = function ( e : web . Event ) : void {
326
313
cb ( new MouseEvent ( e ) ) ;
@@ -332,21 +319,11 @@ class View implements Responder, Appearance {
332
319
var block = Util . createDiv ( ) ;
333
320
var style = block . style ;
334
321
335
- style . backgroundColor = this . _backgroundColor . toStyle ( ) ;
336
- style . position = "absolute" ;
337
-
338
- var frame = this . calculateFrame ( ) ;
322
+ style . backgroundColor = this . _backgroundColor . toString ( ) ;
323
+ style . width = "100%" ;
339
324
340
325
if ( Platform . DEBUG ) {
341
- style . border = Util . borderWithColor ( Color . BLUE ) ;
342
- }
343
-
344
- style . left = frame . origin . x as string + "px" ;
345
- style . top = frame . origin . y as string + "px" ;
346
-
347
- if ( ! this . _autoSized ) {
348
- style . width = frame . size . width as string + "px" ;
349
- style . height = frame . size . height as string + "px" ;
326
+ //style.border = Util.borderWithColor(Color.BLUE);
350
327
}
351
328
352
329
this . _subviews . forEach ( ( view ) - > {
@@ -497,6 +474,7 @@ class Control extends View {
497
474
class Label extends View {
498
475
var _content : web . Node = null ;
499
476
var _color : Color = Color . DARK_TEXT ;
477
+ var _align : string ;
500
478
501
479
function constructor ( ) {
502
480
}
@@ -513,14 +491,39 @@ class Label extends View {
513
491
this . _content = content ;
514
492
}
515
493
494
+ function setAlign ( align : string ) : void {
495
+ this . _align = align ;
496
+ }
497
+
498
+ function toCenter ( ) : Label {
499
+ this . setAlign ( "center" ) ;
500
+ return this ;
501
+ }
502
+ function toLeft ( ) : Label {
503
+ this . setAlign ( "left" ) ;
504
+ return this ;
505
+ }
506
+ function toRight ( ) : Label {
507
+ this . setAlign ( "right" ) ;
508
+ return this ;
509
+ }
510
+
516
511
override function _toElement ( ) : web . HTMLElement {
517
512
assert this . _content ! = null ;
518
513
519
514
var element = super . _toElement ( ) ; // <div>
520
515
element . appendChild ( this . _content ) ;
521
516
522
517
var style = element . style ;
523
- style . color = this . _color . toStyle ( ) ;
518
+ style . color = this . _color . toString ( ) ;
519
+ style . textAlign = this . _align ;
520
+ style . paddingTop = "5px" ;
521
+ style . paddingBottom = "5px" ;
522
+ style . margin = "2px" ;
523
+
524
+ style . borderRadius = "8px" ;
525
+ Util . applyGradient ( style , "linear" , "left top" , "left bottom" , Color . WHITE , Color . LIGHT_GRAY ) ;
526
+
524
527
525
528
return element ;
526
529
}
@@ -563,16 +566,29 @@ class TextField extends Control {
563
566
this . _a = a ;
564
567
}
565
568
566
- function toStyle ( ) : string {
569
+ function toRGBAStyle ( ) : string {
567
570
return "rgba("
568
571
+ this . _r as string + ", "
569
572
+ this . _g as string + ", "
570
573
+ this . _b as string + ", "
571
574
+ this . _a as string + ")" ;
572
575
}
573
576
577
+
578
+ function _hex02 ( c : int ) : string {
579
+ var s = c . toString ( 16 ) ;
580
+ return s . length > 1 ? s : "0" + s ;
581
+ }
582
+
583
+ function toHexStyle ( ) : string {
584
+ return "#"
585
+ + this . _hex02 ( this . _r )
586
+ + this . _hex02 ( this . _g )
587
+ + this . _hex02 ( this . _b ) ;
588
+ }
589
+
574
590
override function toString ( ) : string {
575
- return this . toStyle ( ) ;
591
+ return this . toRGBAStyle ( ) ;
576
592
}
577
593
}
578
594
0 commit comments