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
|
define.class("$ui/view", function($ui$, button){
this.attributes = {
tabs:Config({type:Array, value:[]}),
tabcolor: Config({value:vec4(0,0,0,1), meta:"color" }),
activetabcolor: Config({value:vec4(1,1,1,1), meta:"color" }),
textcolor: Config({value:vec4(1,1,1,1), meta:"color" }),
activetextcolor: Config({value:vec4(0,0,0,1), meta:"color" }),
tabclass:undefined,
activetab:Config({persist:true, value:0})
};
this.tooldragroot = true;
this.flexdirection = "row";
this.bgcolor = NaN;
this.style = {
button: {
flex: 1,
justifycontent:"center",
alignitems:"center",
bgcolor:this.tabcolor,
borderradius:0,
arrowheight:5.0,
showarrow:true,
arrowtop:true,
bgcolorfn:function(p) {
var atx = p.x * layout.width;
var aty = p.y * layout.height;
if (showarrow) {
if (arrowtop) {
if (aty < arrowheight && (atx + aty < layout.width * 0.5 || atx - aty > layout.width * 0.5)) {
return "transparent";
}
} else {
if ((layout.height - aty) < arrowheight && (atx + (layout.height - aty) < layout.width * 0.5 || atx - (layout.height - aty) > layout.width * 0.5)) {
return "transparent";
}
}
}
return bgcolor;
}
},
button_folder: {
x:1,
flex: 0,
padding:5,
bgcolor:this.tabcolor,
borderradius:vec4(15,15,0,0),
bgcolorfn:function(p) { return bgcolor; }
}
};
this.render = function() {
var tabs = [];
if (this.tabs) {
for (var i=0;i<this.tabs.length;i++) {
var tabdef = this.tabs[i];
var active = i === this.activetab;
var tab = {
bgimagemode:"stretch",
textcolor: active ? this.activetextcolor : this.textcolor,
textactivecolor: active ? this.activetextcolor : this.textcolor,
bgcolor: active ? this.activetabcolor : this.tabcolor,
buttoncolor1:"transparent",
buttoncolor2:"transparent",
hovercolor1:"transparent",
hovercolor2:"transparent",
pressedcolor1:"transparent",
pressedcolor2:"transparent",
pickalpha:-1,
borderwidth:0,
class:this.tabclass,
tabindex:i,
click:function(ev,v,o) {
this.activetab = o.tabindex;
}.bind(this)
};
if (typeof(tabdef) === "string") {
tab.text = tabdef
} else {
for (var prop in tabdef) {
if (tabdef.hasOwnProperty(prop)) {
tab[prop] = tabdef[prop]
}
}
}
tabs.push(button(tab));
}
}
return tabs;
};
var tabbar = this.constructor;
this.constructor.examples = {
Usage: function() {
return [
tabbar({tabs:["one", "two", "three"], onactivetab:function(ev,tab,bar) {
if (tab) {
console.log('Selected tab', tab, bar.tabs[tab])
}
}})
]
},
Advanced: function() {
var selectionhandler = function(tab,state) {
tab.parent.defaultselectionhandler(tab);
alert("custom logic for " + state + " handler can go here")
};
return [
tabbar({
tabclass:"folder",
tabs:[
{
icon:"gear",
padding:10
},
{
text:"two",
padding:10,
textcolor:"#E44"
},
{
text:"three",
padding:10
}
]})
]
}
}
});
|