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
/* DreemGL is a collaboration between Teeming Society & Samsung Electronics, sponsored by Samsung and others.
 Copyright 2015-2016 Teeming Society. Licensed under the Apache License, Version 2.0 (the "License"); You may not use this file except in compliance with the License.
 You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing,
 software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and limitations under the License.*/

define.class('$ui/view', function(require, $ui$, view, icon) {
// A table is a container view that lays out it's children in either rows or columns.
// Individual rows and columns can be configured via styles and are given names and style classes conforming to
// either `row#` or `column#` style where `#` is the index of the particular row or column.
// <br/><a href="/examples/tables">examples &raquo;</a>

        this.attributes = {
                // The number of rows in the table (not compatible with `columns`)
                rows:-1,

                // The number of columns in the table (not compatible with `rows`)
                columns:-1,

                // internal, The number of rows or columns in the table (set automatically via `rows` or `columns`)
                sections:1,

                // justifycontent passed to the inner rows or columns
                justifysection: Config({group:"layout", type: Enum('','flex-start','center','flex-end','space-between','space-around'), value: ""}),

                // alignitems passed to the inner rows or columns
                alignsection: Config({group:"layout", type: Enum('flex-start','center','flex-end','stretch'), value:"stretch"}),
        };

        this.onrows = function(ev,v,o) {
                this._columns = -1;
                this.flexdirection = "column";
                this.sections = v;
                this.relayout();
        };

        this.oncolumns = function(ev,v,o) {
                this._rows = -1;
                this.flexdirection = "row";
                this.sections = v;
                this.relayout();
        };

        this.render = function() {

                var rows = [];

                for (var i=0; i < this.sections; i++) {
                        var views = [];
                        for (var j = (i % this.sections); j < this.constructor_children.length; j+=this.sections) {
                                var child = this.constructor_children[j];
                                if (child) {
                                        views.push(child)
                                }
                        }

                        var sectionflex = this.flexdirection === "column" ? "row" : "column";
                        var sectionname = sectionflex + i;

                        rows.push(
                                this.rowcol({
                                        flex:1,
                                        name:sectionname,
                                        class:sectionname,
                                        alignitems:this.alignsection,
                                        justifycontent:this.justifysection,
                                        flexdirection: sectionflex
                                }, views)
                        )
                }

                return rows;

        }

        define.class(this, "rowcol", "$ui/view", function() {
        })

        var table = this.constructor;
        // Basic usage of the table.
        this.constructor.examples = {
                Usage:function() {
                        return [
                                table({
                                            width:200,
                                                columns:3,
                                                alignsection:"center",
                                                style:{
                                                        rowcol: {
                                                                borderwidth:vec4(0,1,0,0),
                                                                bordercolor:"white"
                                                        }
                                                }
                                        },
                                        icon({icon:"facebook"}),
                                        icon({icon:"digg"}),
                                        icon({icon:"cc"}),
                                        icon({icon:"envelope"}),
                                        icon({icon:"empire"}),
                                        icon({icon:"eye"}),
                                        icon({icon:"circle"}),
                                        icon({icon:"circle-o"}),
                                        icon({icon:"star"}),
                                        icon({icon:"star-o"})
                                )
                        ]
                }
        }


});