~extremepopcorn/dhlib/dhlib_ep

« back to all changes in this revision

Viewing changes to app-tutorial/tutorial/LinearLayout.hx

  • Committer: edA-qa mort-ora-y
  • Date: 2010-02-16 05:36:32 UTC
  • Revision ID: eda-qa@disemia.com-20100216053632-60lt7fndfi3fgblw
first

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* <license>
 
2
 * This file is part of the dis-Emi-A HaXe Library. Copyright © edA-qa mort-ora-y
 
3
 * For full copyright and license information please refer to doc/license.txt.
 
4
 * </license> 
 
5
 */
 
6
package tutorial;
 
7
 
 
8
/**
 
9
 * This demonstrates how to create an automatic vertical layout of
 
10
 * several items.  It provides examples of how to use automatic
 
11
 * sizing, relative sizing, and fixed sizing
 
12
 */
 
13
class LinearLayout extends ui.StageLayout
 
14
{
 
15
        var layout : ui.LinearLayout;
 
16
        
 
17
        public function new()
 
18
        {
 
19
                super();
 
20
                
 
21
                //create an empty vertical layout
 
22
                layout = ui.LinearLayout.vertical();
 
23
                addChild( layout );
 
24
                
 
25
                //create a simple text item, allow itself to auto size
 
26
                layout.add( 
 
27
                        ui.StaticText.singleLine( "Auto-sizing text" ) 
 
28
                        );
 
29
                
 
30
                //add a box which is always 10% the height of the entire layout
 
31
                layout.add( 
 
32
                        ui.Box.plain( 
 
33
                                draw.Brush.solid( draw.Color.rgb( 1, 0, 0 ) ),
 
34
                                draw.Pen.solid( 2, draw.Color.rgb( 0.5, 0, 0 ) ) 
 
35
                                ),
 
36
                        ui.SizeType.Primary( 0.1 )
 
37
                        );
 
38
                        
 
39
                //now add some text which is always two-lines high (since the text
 
40
                //expands to fill the area, what we mean is two-line heights of normal
 
41
                //size text
 
42
                layout.add( 
 
43
                        ui.StaticText.singleLine( "2 Text Rows High text" ),
 
44
                        ui.SizeType.Lines( 2 )
 
45
                        );
 
46
                        
 
47
                //then create a box which is always 10units high, not relative to any size
 
48
                layout.add( 
 
49
                        ui.Box.plain( 
 
50
                                draw.Brush.solid( draw.Color.rgb( 0, 1, 0 ) ),
 
51
                                draw.Pen.solid( 1, draw.Color.rgb( 0, 0.5, 0 ) ) 
 
52
                                ),
 
53
                        ui.SizeType.Fixed( 10 )
 
54
                        );
 
55
                
 
56
                //now fill the remaining space with these two items.  They used a weighting
 
57
                //system for allocation: all the weights are added together, and each item
 
58
                //gets its ratio of that weight, in this example:
 
59
                //              Total Weight = 4 + 1 = 5
 
60
                //              First Item = 4 / 5 = 80%
 
61
                //              Second Item = 1 / 5 = 20%
 
62
                //Note that the Fill size type only uses up the remaining space, so these
 
63
                //items could actually shrink to nothing (look at using Min/Max size types
 
64
                //to alleviate that problem)
 
65
                layout.add( 
 
66
                        ui.Box.plain( draw.Brush.solid( draw.Color.rgb( 0, 0, 0.5 ) ) ),
 
67
                        ui.SizeType.Fill( 4 )
 
68
                        );
 
69
                layout.add( 
 
70
                        ui.Box.plain( draw.Brush.solid( draw.Color.rgb( 0, 0.5, 0 ) ) ),
 
71
                        ui.SizeType.Fill( 1 )
 
72
                        );
 
73
        }
 
74
        
 
75
        override function _resize( w : Float, h : Float )
 
76
        {
 
77
                //make the layout use the entire stage area
 
78
                layout.resize( w, h );
 
79
        }
 
80
        
 
81
        static public function main() 
 
82
        {
 
83
                ui.StageLayout.setup( LinearLayout );
 
84
        }
 
85
}