-
-
Notifications
You must be signed in to change notification settings - Fork 260
/
TabButton.js
227 lines (189 loc) · 6.17 KB
/
TabButton.js
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
/* ************************************************************************
qooxdoo - the new era of web development
http://qooxdoo.org
Copyright:
2004-2009 1&1 Internet AG, Germany, http://www.1und1.de
License:
MIT: https://opensource.org/licenses/MIT
See the LICENSE file in the project's top-level directory for details.
Authors:
* Jonathan Weiß (jonathan_rass)
************************************************************************ */
/**
* A TabButton is the tapable part sitting on the {@link qx.ui.tabview.Page}.
* By tapping on the TabButton the user can set a Page active.
*
* @childControl label {qx.ui.basic.Label} label of the tab button
* @childControl icon {qx.ui.basic.Image} icon of the tab button
* @childControl close-button {qx.ui.form.Button} close button of the tab button
*/
qx.Class.define("qx.ui.tabview.TabButton", {
extend: qx.ui.form.RadioButton,
implement: qx.ui.form.IRadioItem,
/*
*****************************************************************************
CONSTRUCTOR
*****************************************************************************
*/
construct() {
super();
var layout = new qx.ui.layout.Grid(2, 0);
layout.setRowAlign(0, "left", "middle");
layout.setColumnAlign(0, "right", "middle");
this._getLayout().dispose();
this._setLayout(layout);
this.initShowCloseButton();
},
/*
*****************************************************************************
EVENTS
*****************************************************************************
*/
events: {
/**
* Fired by {@link qx.ui.tabview.Page} if the close button is tapped.
*
* Event data: The tab button.
*/
close: "qx.event.type.Data"
},
/*
*****************************************************************************
PROPERTIES
*****************************************************************************
*/
properties: {
/** Indicates if the close button of a TabButton should be shown. */
showCloseButton: {
check: "Boolean",
init: false,
apply: "_applyShowCloseButton"
}
},
/*
*****************************************************************************
MEMBERS
*****************************************************************************
*/
members: {
// overridden
/**
* @lint ignoreReferenceField(_forwardStates)
*/
_forwardStates: {
focused: true,
checked: true
},
/*
---------------------------------------------------------------------------
WIDGET API
---------------------------------------------------------------------------
*/
_applyIconPosition(value, old) {
var children = {
icon: this.getChildControl("icon"),
label: this.getChildControl("label"),
closeButton: this.getShowCloseButton()
? this.getChildControl("close-button")
: null
};
// Remove all children before adding them again
for (var child in children) {
if (children[child]) {
this._remove(children[child]);
}
}
switch (value) {
case "top":
this._add(children.label, { row: 3, column: 2 });
this._add(children.icon, { row: 1, column: 2 });
if (children.closeButton) {
this._add(children.closeButton, { row: 0, column: 4 });
}
break;
case "bottom":
this._add(children.label, { row: 1, column: 2 });
this._add(children.icon, { row: 3, column: 2 });
if (children.closeButton) {
this._add(children.closeButton, { row: 0, column: 4 });
}
break;
case "left":
this._add(children.label, { row: 0, column: 2 });
this._add(children.icon, { row: 0, column: 0 });
if (children.closeButton) {
this._add(children.closeButton, { row: 0, column: 4 });
}
break;
case "right":
this._add(children.label, { row: 0, column: 0 });
this._add(children.icon, { row: 0, column: 2 });
if (children.closeButton) {
this._add(children.closeButton, { row: 0, column: 4 });
}
break;
}
},
// overridden
_createChildControlImpl(id, hash) {
var control;
switch (id) {
case "label":
var control = new qx.ui.basic.Label(this.getLabel());
control.setAnonymous(true);
this._add(control, { row: 0, column: 2 });
this._getLayout().setColumnFlex(2, 1);
break;
case "icon":
control = new qx.ui.basic.Image(this.getIcon());
control.setAnonymous(true);
this._add(control, { row: 0, column: 0 });
break;
case "close-button":
control = new qx.ui.form.Button();
control.setFocusable(false);
control.setKeepActive(true);
control.addListener("tap", this._onCloseButtonTap, this);
this._add(control, { row: 0, column: 4 });
if (!this.getShowCloseButton()) {
control.exclude();
}
break;
}
return control || super._createChildControlImpl(id);
},
/*
---------------------------------------------------------------------------
EVENT LISTENERS
---------------------------------------------------------------------------
*/
/**
* Fires a "close" event when the close button is tapped.
*/
_onCloseButtonTap() {
this.fireDataEvent("close", this);
},
/*
---------------------------------------------------------------------------
PROPERTY APPLY
---------------------------------------------------------------------------
*/
// property apply
_applyShowCloseButton(value, old) {
if (value) {
this._showChildControl("close-button");
} else {
this._excludeChildControl("close-button");
}
},
// property apply
_applyCenter(value) {
var layout = this._getLayout();
if (value) {
layout.setColumnAlign(2, "center", "middle");
} else {
layout.setColumnAlign(2, "left", "middle");
}
}
}
});