cedro 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/core/application.core.ts +19 -1
- package/src/index.ts +9 -8
- package/src/interfaces/application.interface.ts +4 -0
- package/src/interfaces/widget.interface.ts +10 -3
- package/src/types/orientation.type.ts +1 -0
- package/src/ui/Icon.ui.ts +3 -9
- package/src/ui/IconButton.ui.ts +39 -3
- package/src/ui/accordion.ts +71 -0
- package/src/ui/button.ui.ts +18 -1
- package/src/ui/buttonColor.ui.ts +24 -0
- package/src/ui/buttonmenu.ui.ts +59 -0
- package/src/ui/buttonstack.ui.ts +94 -0
- package/src/ui/checkbox.ui.ts +8 -0
- package/src/ui/datagrid.ui.ts +231 -0
- package/src/ui/draggable.ui.ts +165 -0
- package/src/ui/hpanel.ui.ts +127 -0
- package/src/ui/iconButtonMenu.ui.ts +59 -0
- package/src/ui/index.ts +46 -2
- package/src/ui/loading.ui.ts +10 -0
- package/src/ui/menu.ui.ts +41 -47
- package/src/ui/progressbar.ui.ts +74 -0
- package/src/ui/radiobutton.ts +8 -0
- package/src/ui/scroll.ui.ts +184 -0
- package/src/ui/select.ui.ts +3 -0
- package/src/ui/styles/accordion.css +9 -0
- package/src/ui/styles/button.css +0 -3
- package/src/ui/styles/buttoncolor.css +8 -0
- package/src/ui/styles/datagrid.css +36 -0
- package/src/ui/styles/draggable.css +9 -0
- package/src/ui/styles/hpanel.css +12 -0
- package/src/ui/styles/loading.css +12 -0
- package/src/ui/styles/loading.svg +49 -0
- package/src/ui/styles/main.css +7 -0
- package/src/ui/styles/menu.css +0 -1
- package/src/ui/styles/progressbar.css +19 -0
- package/src/ui/styles/scroll.css +4 -0
- package/src/ui/styles/stackbutton.css +205 -0
- package/src/ui/styles/tabs.css +78 -0
- package/src/ui/styles/textarea.css +13 -0
- package/src/ui/styles/textbox.css +66 -0
- package/src/ui/styles/toolbar.css +19 -0
- package/src/ui/styles/valuebar.css +26 -0
- package/src/ui/styles/vpanel.css +12 -0
- package/src/ui/styles/vstackbutton.css +202 -0
- package/src/ui/switch.ui.ts +7 -0
- package/src/ui/tabs.ui.ts +182 -0
- package/src/ui/textarea.ui.ts +20 -0
- package/src/ui/textbox.ui.ts +9 -0
- package/src/ui/toggle.ui.ts +49 -0
- package/src/ui/toolbar.ui.ts +38 -10
- package/src/ui/valuebar.ui.ts +116 -0
- package/src/ui/vpanel.ui.ts +128 -0
- package/src/ui/widget.ui.ts +63 -4
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import "./styles/tabs.css";
|
|
2
|
+
|
|
3
|
+
import { OrientationTypes } from "src/types/orientation.type";
|
|
4
|
+
import { Widget, WidgetAlignTypes, WidgetTypes } from "./widget.ui";
|
|
5
|
+
import { Toolbar } from "./toolbar.ui";
|
|
6
|
+
import { Label } from "./label.ui";
|
|
7
|
+
import { IconButton } from "./IconButton.ui";
|
|
8
|
+
import { Scroll } from "./scroll.ui";
|
|
9
|
+
|
|
10
|
+
const TAB_HEADER_SIZE = 40;
|
|
11
|
+
|
|
12
|
+
export type TabItem = {
|
|
13
|
+
title: string;
|
|
14
|
+
content: Widget;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export class Tabs extends Widget {
|
|
18
|
+
orientation: OrientationTypes;
|
|
19
|
+
|
|
20
|
+
content: Widget;
|
|
21
|
+
itemControls: Toolbar;
|
|
22
|
+
|
|
23
|
+
items: Map<string, TabItem>;
|
|
24
|
+
itemsScrollable: Map<string, boolean>;
|
|
25
|
+
verticalScrollbar: Scroll | null;
|
|
26
|
+
|
|
27
|
+
constructor(
|
|
28
|
+
id: string,
|
|
29
|
+
parent: Widget | null = null,
|
|
30
|
+
orientation: OrientationTypes = "horizontal"
|
|
31
|
+
) {
|
|
32
|
+
super(id, "div", parent);
|
|
33
|
+
this.orientation = orientation;
|
|
34
|
+
|
|
35
|
+
this.content = new Widget(id + ".content", "div");
|
|
36
|
+
this.content.setType(WidgetTypes.FILL);
|
|
37
|
+
this.content.addClass("WUITabContainer");
|
|
38
|
+
|
|
39
|
+
this.setType(WidgetTypes.FILL);
|
|
40
|
+
|
|
41
|
+
if (this.orientation === "horizontal") {
|
|
42
|
+
this.setAlign(WidgetAlignTypes.VERTICAL);
|
|
43
|
+
} else {
|
|
44
|
+
this.setAlign(WidgetAlignTypes.HORIZONTAL);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
this.items = new Map<string, TabItem>();
|
|
48
|
+
this.itemsScrollable = new Map<string, boolean>();
|
|
49
|
+
this.verticalScrollbar = null;
|
|
50
|
+
|
|
51
|
+
this.itemControls = new Toolbar(id + ".itemControls", null, orientation);
|
|
52
|
+
this.itemControls.setVariant("contained");
|
|
53
|
+
this.itemControls.setFixedSize(TAB_HEADER_SIZE);
|
|
54
|
+
|
|
55
|
+
this.addChild(this.itemControls);
|
|
56
|
+
this.addChild(this.content);
|
|
57
|
+
|
|
58
|
+
this.addClass("WUITab");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public setOrientation(orientation: OrientationTypes) {
|
|
62
|
+
this.orientation = orientation;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public addTab(id: string, title: string, content: Widget, scrollable: boolean = false) {
|
|
66
|
+
this.items.set(id, { title, content });
|
|
67
|
+
this.itemsScrollable.set(id, scrollable);
|
|
68
|
+
|
|
69
|
+
const itemControl = new Label(id + ".itemControl", "span");
|
|
70
|
+
|
|
71
|
+
itemControl.setText(title);
|
|
72
|
+
itemControl.addClass("WUITabControl");
|
|
73
|
+
|
|
74
|
+
if (this.orientation === "horizontal") {
|
|
75
|
+
itemControl.setH(TAB_HEADER_SIZE);
|
|
76
|
+
itemControl.getBody().style.lineHeight = TAB_HEADER_SIZE + "px";
|
|
77
|
+
} else if (this.orientation === "vertical") {
|
|
78
|
+
itemControl.getBody().style.writingMode = "vertical-rl";
|
|
79
|
+
itemControl.getBody().style.transform = "scale(-1,-1)";
|
|
80
|
+
itemControl.getBody().style.paddingTop = "15px";
|
|
81
|
+
itemControl.getBody().style.paddingBottom = "15px";
|
|
82
|
+
itemControl.getBody().style.paddingRight = "12px";
|
|
83
|
+
itemControl.setW(TAB_HEADER_SIZE);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
itemControl.subscribe({
|
|
87
|
+
event: "click",
|
|
88
|
+
then: (_e, _w) => {
|
|
89
|
+
this.setTab(id);
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
this.itemControls.addItem(id, itemControl);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
public addIconTab(id: string, icon: string, content: Widget, scrollable: boolean = false) {
|
|
97
|
+
this.items.set(id, { title: icon, content });
|
|
98
|
+
this.itemsScrollable.set(id, scrollable);
|
|
99
|
+
|
|
100
|
+
const itemControl = new IconButton(id + ".itemControl", icon);
|
|
101
|
+
itemControl.setW(40);
|
|
102
|
+
itemControl.setH(TAB_HEADER_SIZE);
|
|
103
|
+
|
|
104
|
+
itemControl.subscribe({
|
|
105
|
+
event: "click",
|
|
106
|
+
then: (_e, _w) => {
|
|
107
|
+
this.setTab(id);
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
this.itemControls.addItem(id, itemControl);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
public setTab(id: string) {
|
|
115
|
+
this.content.removeAllChilds();
|
|
116
|
+
const actualTab = this.items.get(id);
|
|
117
|
+
|
|
118
|
+
for (const itemId of this.items.keys()) {
|
|
119
|
+
if (itemId != id) {
|
|
120
|
+
this.items.get(itemId)?.content.setVisible(false);
|
|
121
|
+
const ctrlTab = window.w.get(itemId + ".itemControl");
|
|
122
|
+
if (ctrlTab) {
|
|
123
|
+
if (this.orientation === "horizontal") {
|
|
124
|
+
ctrlTab.deleteClass("WUITabControlActive");
|
|
125
|
+
ctrlTab.addClass("WUITabControl");
|
|
126
|
+
} else if (this.orientation === "vertical") {
|
|
127
|
+
if (ctrlTab instanceof IconButton) {
|
|
128
|
+
ctrlTab.deleteClass("WUITabControlActiveIcon_VL");
|
|
129
|
+
} else if (ctrlTab instanceof Label) {
|
|
130
|
+
ctrlTab.deleteClass("WUITabControlActive_VL");
|
|
131
|
+
}
|
|
132
|
+
ctrlTab.addClass("WUITabControl");
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
} else {
|
|
136
|
+
const ctrlTab = window.w.get(itemId + ".itemControl");
|
|
137
|
+
if (ctrlTab) {
|
|
138
|
+
if (this.orientation === "horizontal") {
|
|
139
|
+
ctrlTab.addClass("WUITabControlActive");
|
|
140
|
+
} else if (this.orientation === "vertical") {
|
|
141
|
+
if (ctrlTab instanceof IconButton) {
|
|
142
|
+
ctrlTab.addClass("WUITabControlActiveIcon_VL");
|
|
143
|
+
} else if (ctrlTab instanceof Label) {
|
|
144
|
+
ctrlTab.addClass("WUITabControlActive_VL");
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (actualTab) {
|
|
152
|
+
this.items.get(id)?.content.setVisible(true);
|
|
153
|
+
const scrollable = this.itemsScrollable.get(id);
|
|
154
|
+
|
|
155
|
+
this.content.addChild(actualTab.content);
|
|
156
|
+
|
|
157
|
+
if (scrollable) {
|
|
158
|
+
if (this.verticalScrollbar == null) {
|
|
159
|
+
this.verticalScrollbar = new Scroll(
|
|
160
|
+
actualTab.content.id + ".verticalScrollbar",
|
|
161
|
+
this.content,
|
|
162
|
+
"vertical"
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
} else {
|
|
166
|
+
if (this.verticalScrollbar) {
|
|
167
|
+
this.verticalScrollbar.dispose();
|
|
168
|
+
this.verticalScrollbar = null;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
this.render();
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
public render(): void {
|
|
177
|
+
super.render();
|
|
178
|
+
if (this.verticalScrollbar) {
|
|
179
|
+
this.verticalScrollbar.render();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import "./styles/textarea.css";
|
|
2
|
+
import { Widget } from "./widget.ui";
|
|
3
|
+
|
|
4
|
+
export class TextArea extends Widget {
|
|
5
|
+
constructor(id: string, parent: Widget | null = null) {
|
|
6
|
+
super(id, "textarea", parent);
|
|
7
|
+
|
|
8
|
+
this.addClass("WUITextArea");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
public setText(text: string): void {
|
|
12
|
+
const textArea = this.getBody() as HTMLTextAreaElement;
|
|
13
|
+
textArea.value = text;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public getText(): string {
|
|
17
|
+
const textArea = this.getBody() as HTMLTextAreaElement;
|
|
18
|
+
return textArea.value;
|
|
19
|
+
}
|
|
20
|
+
}
|
package/src/ui/textbox.ui.ts
CHANGED
|
@@ -3,10 +3,14 @@ import { Widget, WidgetTypes } from "./widget.ui";
|
|
|
3
3
|
|
|
4
4
|
export type InputTypes =
|
|
5
5
|
| "text"
|
|
6
|
+
| "date"
|
|
7
|
+
| "datetime-local"
|
|
8
|
+
| "file"
|
|
6
9
|
| "number"
|
|
7
10
|
| "password"
|
|
8
11
|
| "email"
|
|
9
12
|
| "url"
|
|
13
|
+
| "color"
|
|
10
14
|
| "tel";
|
|
11
15
|
|
|
12
16
|
export class Textbox extends Widget {
|
|
@@ -71,6 +75,10 @@ export class Textbox extends Widget {
|
|
|
71
75
|
}
|
|
72
76
|
|
|
73
77
|
private positionLabel(): void {
|
|
78
|
+
if (this.title === "") {
|
|
79
|
+
this.label.setVisible(false);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
74
82
|
if (this.getValue() === "") {
|
|
75
83
|
this.moveLabelToCenter();
|
|
76
84
|
} else {
|
|
@@ -99,6 +107,7 @@ export class Textbox extends Widget {
|
|
|
99
107
|
|
|
100
108
|
this.positionLabel();
|
|
101
109
|
this.input.setWH(this.getW(), this.getH());
|
|
110
|
+
this.input.getBody().style.lineHeight = this.getH() + "px";
|
|
102
111
|
this.input.render();
|
|
103
112
|
|
|
104
113
|
super.render();
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Widget } from "./widget.ui";
|
|
2
|
+
import { IconButton } from "./IconButton.ui";
|
|
3
|
+
|
|
4
|
+
export class ToggleButton extends IconButton {
|
|
5
|
+
state: boolean;
|
|
6
|
+
toggleOnIcon: string;
|
|
7
|
+
toggleOffIcon: string;
|
|
8
|
+
|
|
9
|
+
constructor(
|
|
10
|
+
id: string,
|
|
11
|
+
text: string = "",
|
|
12
|
+
toggleOnIcon: string = "toggle_on",
|
|
13
|
+
toggleOffIcon: string = "toggle_off",
|
|
14
|
+
parent: Widget | null = null
|
|
15
|
+
) {
|
|
16
|
+
super(id, toggleOffIcon, parent);
|
|
17
|
+
|
|
18
|
+
this.toggleOnIcon = toggleOnIcon;
|
|
19
|
+
this.toggleOffIcon = toggleOffIcon;
|
|
20
|
+
|
|
21
|
+
this.state = false;
|
|
22
|
+
|
|
23
|
+
if (text) {
|
|
24
|
+
this.setText(text);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
this.setVariant("text");
|
|
28
|
+
|
|
29
|
+
this.subscribe({
|
|
30
|
+
event: "click",
|
|
31
|
+
then: () => {
|
|
32
|
+
this.toggle();
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public setState(state: boolean): void {
|
|
38
|
+
this.state = state;
|
|
39
|
+
this.setIcon(state ? this.toggleOnIcon : this.toggleOffIcon);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public toggle(): void {
|
|
43
|
+
this.setState(!this.state);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public getState(): boolean {
|
|
47
|
+
return this.state;
|
|
48
|
+
}
|
|
49
|
+
}
|
package/src/ui/toolbar.ui.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
|
+
import "./styles/toolbar.css";
|
|
1
2
|
import { IWidget } from "src/interfaces/widget.interface";
|
|
2
|
-
import { Widget, WidgetTypes } from "./widget.ui";
|
|
3
|
+
import { Widget, WidgetAlignTypes, WidgetTypes } from "./widget.ui";
|
|
3
4
|
import { IconButton } from "./IconButton.ui";
|
|
5
|
+
import { OrientationTypes } from "src/types/orientation.type";
|
|
4
6
|
|
|
5
|
-
export type
|
|
6
|
-
|
|
7
|
+
export type ToolbarVariants = "contained" | "outlined";
|
|
8
|
+
|
|
9
|
+
const TOOLBAR_SIZE = 48;
|
|
7
10
|
const TOOLBAR_BUTTON_SIZE = 40;
|
|
8
11
|
|
|
9
12
|
export class Toolbar extends Widget {
|
|
10
|
-
orientation:
|
|
13
|
+
orientation: OrientationTypes;
|
|
14
|
+
variant: ToolbarVariants;
|
|
11
15
|
items: Map<string, IWidget>;
|
|
12
16
|
size: number; //Indica el alto o ancho de la toolbar.
|
|
13
17
|
|
|
@@ -15,18 +19,33 @@ export class Toolbar extends Widget {
|
|
|
15
19
|
btnLeft: IconButton;
|
|
16
20
|
btnRight: IconButton;
|
|
17
21
|
|
|
18
|
-
constructor(
|
|
22
|
+
constructor(
|
|
23
|
+
id: string,
|
|
24
|
+
parent: Widget | null = null,
|
|
25
|
+
orientationType: OrientationTypes = "horizontal"
|
|
26
|
+
) {
|
|
19
27
|
super(id, "div", parent);
|
|
20
28
|
this.orientation = orientationType;
|
|
21
29
|
this.size = TOOLBAR_SIZE;
|
|
22
30
|
this.items = new Map<string, IWidget>();
|
|
23
31
|
|
|
32
|
+
this.variant = "outlined";
|
|
33
|
+
|
|
34
|
+
if (this.orientation === "vertical") {
|
|
35
|
+
this.setAlign(WidgetAlignTypes.VERTICAL);
|
|
36
|
+
} else {
|
|
37
|
+
this.setAlign(WidgetAlignTypes.HORIZONTAL);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
this.setType(WidgetTypes.FILL);
|
|
41
|
+
this.setFixedSize(TOOLBAR_SIZE);
|
|
42
|
+
this.addClass("WUIToolbar-" + this.variant);
|
|
43
|
+
|
|
24
44
|
this.itemsContainer = new Widget(this.id + ".itemsContainer", "div", this);
|
|
25
45
|
this.itemsContainer.setType(WidgetTypes.CUSTOM);
|
|
26
46
|
this.itemsContainer.getBody().style.position = "absolute";
|
|
27
47
|
this.itemsContainer.getBody().style.overflow = "hidden";
|
|
28
48
|
|
|
29
|
-
this.setType(WidgetTypes.FILL);
|
|
30
49
|
this.getBody().style.overflow = "hidden";
|
|
31
50
|
|
|
32
51
|
this.btnLeft = new IconButton(this.id + ".btnLeft", this.getIconLeft());
|
|
@@ -66,6 +85,12 @@ export class Toolbar extends Widget {
|
|
|
66
85
|
});
|
|
67
86
|
}
|
|
68
87
|
|
|
88
|
+
public setVariant(variant: ToolbarVariants): void {
|
|
89
|
+
this.deleteClass("WUIToolbar-" + this.variant);
|
|
90
|
+
this.variant = variant;
|
|
91
|
+
this.addClass("WUIToolbar-" + this.variant);
|
|
92
|
+
}
|
|
93
|
+
|
|
69
94
|
public getIconLeft(): string {
|
|
70
95
|
if (this.orientation === "horizontal") {
|
|
71
96
|
return "arrow_left";
|
|
@@ -86,7 +111,7 @@ export class Toolbar extends Widget {
|
|
|
86
111
|
* @param {ToolbarOrientationTypes} orientationType - the type of orientation to set
|
|
87
112
|
* @return {void}
|
|
88
113
|
*/
|
|
89
|
-
public setOrientation(orientationType:
|
|
114
|
+
public setOrientation(orientationType: OrientationTypes, size: number = TOOLBAR_SIZE): void {
|
|
90
115
|
this.orientation = orientationType;
|
|
91
116
|
this.size = size;
|
|
92
117
|
}
|
|
@@ -134,8 +159,11 @@ export class Toolbar extends Widget {
|
|
|
134
159
|
}
|
|
135
160
|
|
|
136
161
|
public render(): void {
|
|
162
|
+
super.render();
|
|
137
163
|
const fullSize = this.getFullSize();
|
|
138
|
-
const
|
|
164
|
+
const parent = this.getParent();
|
|
165
|
+
const parentH = parent?.getH() || 0;
|
|
166
|
+
const availableSize = this.orientation === "horizontal" ? this.getW() : parentH;
|
|
139
167
|
|
|
140
168
|
if (fullSize > availableSize) {
|
|
141
169
|
this.btnLeft.setVisible(true);
|
|
@@ -190,14 +218,14 @@ export class Toolbar extends Widget {
|
|
|
190
218
|
item.setY(currentPosition);
|
|
191
219
|
currentPosition += item.getH();
|
|
192
220
|
item.setX(0);
|
|
221
|
+
item.setW(TOOLBAR_BUTTON_SIZE);
|
|
193
222
|
} else {
|
|
194
223
|
item.setX(currentPosition);
|
|
195
224
|
item.setY(0);
|
|
225
|
+
item.setH(TOOLBAR_BUTTON_SIZE);
|
|
196
226
|
currentPosition += item.getW();
|
|
197
227
|
}
|
|
198
228
|
item.render();
|
|
199
229
|
}
|
|
200
|
-
|
|
201
|
-
super.render();
|
|
202
230
|
}
|
|
203
231
|
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import "./styles/valuebar.css";
|
|
2
|
+
import { OrientationTypes } from "src/types/orientation.type";
|
|
3
|
+
import { Widget } from "./widget.ui";
|
|
4
|
+
import { Draggable } from "./draggable.ui";
|
|
5
|
+
|
|
6
|
+
export class ValueBar extends Widget {
|
|
7
|
+
orientation: OrientationTypes;
|
|
8
|
+
value: number;
|
|
9
|
+
|
|
10
|
+
containerBar: Widget;
|
|
11
|
+
bar: Widget;
|
|
12
|
+
handler: Widget;
|
|
13
|
+
|
|
14
|
+
draggable: Draggable;
|
|
15
|
+
|
|
16
|
+
constructor(
|
|
17
|
+
id: string,
|
|
18
|
+
orientation: OrientationTypes = "horizontal",
|
|
19
|
+
parent: Widget | null = null
|
|
20
|
+
) {
|
|
21
|
+
super(id, "div", parent);
|
|
22
|
+
|
|
23
|
+
this.containerBar = new Widget(id + ".containerBar", "div", this);
|
|
24
|
+
this.bar = new Widget(id + ".bar", "div", this.containerBar);
|
|
25
|
+
this.handler = new Widget(id + ".handler", "div", this);
|
|
26
|
+
|
|
27
|
+
this.addClass("WUIValueBar");
|
|
28
|
+
this.containerBar.addClass("WUIValueBarContainer");
|
|
29
|
+
this.bar.addClass("WUIValueBarBar");
|
|
30
|
+
this.handler.addClass("WUIValueBarHandler");
|
|
31
|
+
|
|
32
|
+
this.draggable = new Draggable(this.handler, orientation);
|
|
33
|
+
|
|
34
|
+
this.handler.subscribe({
|
|
35
|
+
event: "drag",
|
|
36
|
+
then: (_e, _w) => {
|
|
37
|
+
this.updateValueFromHandlerPosition();
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
this.orientation = orientation;
|
|
42
|
+
this.value = 10;
|
|
43
|
+
this.handler.raisteTop();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public setValue(value: number): void {
|
|
47
|
+
this.value = value;
|
|
48
|
+
this.render();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public updateValueFromHandlerPosition(): void {
|
|
52
|
+
if (this.orientation === "horizontal") {
|
|
53
|
+
const maxX = this.draggable.maxX ? this.draggable.maxX : 1;
|
|
54
|
+
const ratio = this.handler.getX() / maxX;
|
|
55
|
+
this.value = Math.round(ratio * 100);
|
|
56
|
+
} else if (this.orientation === "vertical") {
|
|
57
|
+
const maxY = this.draggable.maxY ? this.draggable.maxY : 1;
|
|
58
|
+
const ratio = this.handler.getY() / maxY;
|
|
59
|
+
this.value = Math.round(ratio * 100);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
this.render();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public render(): void {
|
|
66
|
+
super.render();
|
|
67
|
+
|
|
68
|
+
if (this.orientation === "horizontal") {
|
|
69
|
+
const handlerSize = 24;
|
|
70
|
+
const heightBar = 14;
|
|
71
|
+
const width = this.getW() - 3;
|
|
72
|
+
const height = this.getH();
|
|
73
|
+
const widthBar = width * (this.value / 100);
|
|
74
|
+
|
|
75
|
+
this.containerBar.setX(0);
|
|
76
|
+
this.containerBar.setY(height / 2 - heightBar / 2);
|
|
77
|
+
this.containerBar.setH(heightBar);
|
|
78
|
+
this.containerBar.setW(width);
|
|
79
|
+
|
|
80
|
+
this.bar.setX(0);
|
|
81
|
+
this.bar.setY(0);
|
|
82
|
+
this.bar.setW(widthBar);
|
|
83
|
+
this.bar.setH(heightBar - 4);
|
|
84
|
+
|
|
85
|
+
this.handler.setX(widthBar - handlerSize + 2);
|
|
86
|
+
this.handler.setY(height / 2 - handlerSize / 2);
|
|
87
|
+
this.handler.setWH(handlerSize, handlerSize);
|
|
88
|
+
|
|
89
|
+
this.draggable.setMinX(0);
|
|
90
|
+
this.draggable.setMaxX(width - handlerSize + 2);
|
|
91
|
+
} else if (this.orientation === "vertical") {
|
|
92
|
+
const handlerSize = 24;
|
|
93
|
+
const widthBar = 14;
|
|
94
|
+
const height = this.getH() - 3;
|
|
95
|
+
const width = this.getW();
|
|
96
|
+
const heightBar = height * (this.value / 100);
|
|
97
|
+
|
|
98
|
+
this.containerBar.setY(0);
|
|
99
|
+
this.containerBar.setX(width / 2 - widthBar / 2);
|
|
100
|
+
this.containerBar.setW(widthBar);
|
|
101
|
+
this.containerBar.setH(height);
|
|
102
|
+
|
|
103
|
+
this.bar.setX(0);
|
|
104
|
+
this.bar.setY(0);
|
|
105
|
+
this.bar.setH(heightBar);
|
|
106
|
+
this.bar.setW(widthBar - 4);
|
|
107
|
+
|
|
108
|
+
this.handler.setY(heightBar - handlerSize + 2);
|
|
109
|
+
this.handler.setX(width / 2 - handlerSize / 2);
|
|
110
|
+
this.handler.setWH(handlerSize, handlerSize);
|
|
111
|
+
|
|
112
|
+
this.draggable.setMinY(0);
|
|
113
|
+
this.draggable.setMaxY(height - handlerSize + 2);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { Draggable } from "./draggable.ui";
|
|
2
|
+
import "./styles/vpanel.css";
|
|
3
|
+
import { Widget, WidgetAlignTypes, WidgetTypes } from "./widget.ui";
|
|
4
|
+
|
|
5
|
+
const VPANEL_HANDLER_SIZE = 4;
|
|
6
|
+
|
|
7
|
+
export class VPanel extends Widget {
|
|
8
|
+
topContent: Widget | null;
|
|
9
|
+
bottomContent: Widget | null;
|
|
10
|
+
|
|
11
|
+
topHeight: number | null;
|
|
12
|
+
bottomHeight: number | null;
|
|
13
|
+
|
|
14
|
+
handler: Widget;
|
|
15
|
+
draggable: Draggable;
|
|
16
|
+
|
|
17
|
+
constructor(id: string, parent: Widget | null = null) {
|
|
18
|
+
super(id, "div", parent);
|
|
19
|
+
this.setAlign(WidgetAlignTypes.VERTICAL);
|
|
20
|
+
this.setType(WidgetTypes.FILL);
|
|
21
|
+
//this.setPadding(VPANEL_HANDLER_SIZE);
|
|
22
|
+
|
|
23
|
+
this.handler = new Widget(id + ".handler", "div", null);
|
|
24
|
+
this.handler.addClass("WUIVPanelHandler");
|
|
25
|
+
|
|
26
|
+
this.draggable = new Draggable(this.handler, "vertical");
|
|
27
|
+
this.draggable.setDraggingClass("WUIVPanelDragging");
|
|
28
|
+
this.draggable.setBackgroundCursor("row-resize");
|
|
29
|
+
|
|
30
|
+
this.handler.subscribe({
|
|
31
|
+
event: "drag",
|
|
32
|
+
then: (_e, _w) => {
|
|
33
|
+
this.updateSizeFromHandlerPosition();
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
this.subscribe({
|
|
38
|
+
event: "mousemove",
|
|
39
|
+
then: (e, _w) => {
|
|
40
|
+
this.updateHandlerOpacity(e as MouseEvent);
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
this.topContent = null;
|
|
45
|
+
this.bottomContent = null;
|
|
46
|
+
|
|
47
|
+
this.topHeight = null;
|
|
48
|
+
this.bottomHeight = null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
private updateHandlerOpacity(e: MouseEvent): void {
|
|
52
|
+
const handlerY = this.handler.getY();
|
|
53
|
+
const mouseY = e.clientY;
|
|
54
|
+
const umbral = 100; //Distancia donde comienza a aparecer.
|
|
55
|
+
const minDistance = 20; //Distancia a la que toma 100 de opacidad
|
|
56
|
+
const distance = Math.abs(mouseY - handlerY);
|
|
57
|
+
|
|
58
|
+
if (distance < umbral && distance > minDistance) {
|
|
59
|
+
const ratio = 1 - distance / umbral;
|
|
60
|
+
this.handler.getBody().style.opacity = ratio.toString();
|
|
61
|
+
} else if (distance < minDistance) {
|
|
62
|
+
this.handler.getBody().style.opacity = "1";
|
|
63
|
+
} else {
|
|
64
|
+
this.handler.getBody().style.opacity = "0";
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public setTop(content: Widget, fixHeight: number | null = null): void {
|
|
69
|
+
this.topContent = content;
|
|
70
|
+
this.topHeight = fixHeight;
|
|
71
|
+
if (fixHeight !== null) {
|
|
72
|
+
this.bottomHeight = null;
|
|
73
|
+
this.topContent.setFixedSize(fixHeight);
|
|
74
|
+
}
|
|
75
|
+
this.addChild(content);
|
|
76
|
+
|
|
77
|
+
const spacer = new Widget("spacer." + Date.now().toString(), "div", null);
|
|
78
|
+
spacer.setType(WidgetTypes.FILL);
|
|
79
|
+
spacer.setFixedSize(VPANEL_HANDLER_SIZE);
|
|
80
|
+
this.addChild(spacer);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public setBottom(content: Widget, fixHeight: number | null = null): void {
|
|
84
|
+
this.bottomContent = content;
|
|
85
|
+
this.bottomHeight = fixHeight;
|
|
86
|
+
if (fixHeight !== null) {
|
|
87
|
+
this.topHeight = null;
|
|
88
|
+
this.bottomContent.setFixedSize(fixHeight);
|
|
89
|
+
}
|
|
90
|
+
this.addChild(content);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
private updateSizeFromHandlerPosition(): void {
|
|
94
|
+
if (this.topHeight !== null) {
|
|
95
|
+
const topY = this.topContent ? this.topContent.getY(true) : 0;
|
|
96
|
+
this.topHeight = this.handler.getY() - topY;
|
|
97
|
+
} else if (this.bottomHeight !== null) {
|
|
98
|
+
this.bottomHeight = this.getH() - this.handler.getY();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
this.render();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
public render(): void {
|
|
105
|
+
super.render();
|
|
106
|
+
this.handler.setH(VPANEL_HANDLER_SIZE);
|
|
107
|
+
this.handler.setW(this.getW());
|
|
108
|
+
|
|
109
|
+
if (this.topHeight !== null) {
|
|
110
|
+
const topY = this.topContent ? this.topContent.getY(true) : 0;
|
|
111
|
+
this.handler.setY(topY + this.topHeight);
|
|
112
|
+
this.topContent?.setFixedSize(this.topHeight);
|
|
113
|
+
} else if (this.bottomHeight !== null) {
|
|
114
|
+
const bottomY = this.bottomContent ? this.bottomContent.getY(true) : 0;
|
|
115
|
+
this.handler.setY(bottomY + this.bottomHeight);
|
|
116
|
+
this.bottomContent?.setFixedSize(this.bottomHeight);
|
|
117
|
+
} else {
|
|
118
|
+
if (this.topHeight === null) {
|
|
119
|
+
this.topHeight = this.getH() / 2 - VPANEL_HANDLER_SIZE / 2;
|
|
120
|
+
}
|
|
121
|
+
const topY = this.topContent ? this.topContent.getY(true) : 0;
|
|
122
|
+
this.handler.setY(topY + this.topHeight);
|
|
123
|
+
this.topContent?.setFixedSize(this.topHeight);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
this.handler.setX(this.getX(true));
|
|
127
|
+
}
|
|
128
|
+
}
|