cedro 0.1.4 → 0.1.6

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.
Files changed (54) hide show
  1. package/package.json +1 -1
  2. package/src/core/application.core.ts +19 -1
  3. package/src/index.ts +9 -8
  4. package/src/interfaces/application.interface.ts +4 -0
  5. package/src/interfaces/widget.interface.ts +4 -2
  6. package/src/ui/Icon.ui.ts +3 -9
  7. package/src/ui/IconButton.ui.ts +39 -3
  8. package/src/ui/accordion.ui.ts +71 -0
  9. package/src/ui/button.ui.ts +18 -1
  10. package/src/ui/buttonColor.ui.ts +24 -0
  11. package/src/ui/buttonmenu.ui.ts +59 -0
  12. package/src/ui/buttonstack.ui.ts +94 -0
  13. package/src/ui/checkbox.ui.ts +8 -0
  14. package/src/ui/datagrid.ui.ts +16 -1
  15. package/src/ui/draggable.ui.ts +22 -0
  16. package/src/ui/hpanel.ui.ts +127 -0
  17. package/src/ui/iconButtonMenu.ui.ts +59 -0
  18. package/src/ui/image.ui.ts +49 -0
  19. package/src/ui/index.ts +32 -2
  20. package/src/ui/loading.ui.ts +10 -0
  21. package/src/ui/menu.ui.ts +41 -47
  22. package/src/ui/progressbar.ui.ts +74 -0
  23. package/src/ui/radiobutton.ts +8 -0
  24. package/src/ui/scroll.ui.ts +1 -2
  25. package/src/ui/select.ui.ts +3 -0
  26. package/src/ui/styles/accordion.css +9 -0
  27. package/src/ui/styles/button.css +0 -3
  28. package/src/ui/styles/buttoncolor.css +8 -0
  29. package/src/ui/styles/datagrid.css +28 -2
  30. package/src/ui/styles/hpanel.css +12 -0
  31. package/src/ui/styles/image.css +19 -0
  32. package/src/ui/styles/loading.css +12 -0
  33. package/src/ui/styles/loading.svg +49 -0
  34. package/src/ui/styles/main.css +7 -0
  35. package/src/ui/styles/menu.css +0 -1
  36. package/src/ui/styles/progressbar.css +19 -0
  37. package/src/ui/styles/scroll.css +1 -1
  38. package/src/ui/styles/stackbutton.css +205 -0
  39. package/src/ui/styles/tabs.css +45 -0
  40. package/src/ui/styles/textarea.css +13 -0
  41. package/src/ui/styles/textbox.css +66 -0
  42. package/src/ui/styles/toolbar.css +19 -0
  43. package/src/ui/styles/valuebar.css +26 -0
  44. package/src/ui/styles/vpanel.css +12 -0
  45. package/src/ui/styles/vstackbutton.css +202 -0
  46. package/src/ui/switch.ui.ts +7 -0
  47. package/src/ui/tabs.ui.ts +79 -28
  48. package/src/ui/textarea.ui.ts +20 -0
  49. package/src/ui/textbox.ui.ts +9 -0
  50. package/src/ui/toggle.ui.ts +49 -0
  51. package/src/ui/toolbar.ui.ts +35 -7
  52. package/src/ui/valuebar.ui.ts +116 -0
  53. package/src/ui/vpanel.ui.ts +128 -0
  54. package/src/ui/widget.ui.ts +28 -3
@@ -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
+ }
@@ -144,6 +144,13 @@ export class Widget implements IWidget {
144
144
  window.w.set(this.id, this);
145
145
  }
146
146
 
147
+ public dispose(): void {
148
+ this.removeAllChilds();
149
+ const body = this.getBody();
150
+ const parent = body.parentNode;
151
+ parent?.removeChild(body);
152
+ }
153
+
147
154
  public run(eventId: WUIEvent): void {
148
155
  this.subscribers.forEach((callback) => {
149
156
  if (callback.event == eventId) {
@@ -259,7 +266,7 @@ export class Widget implements IWidget {
259
266
  });
260
267
  }
261
268
 
262
- public setFixedSize(s: number): void {
269
+ public setFixedSize(s: number | null): void {
263
270
  this.fixedSize = s;
264
271
  }
265
272
 
@@ -439,7 +446,16 @@ export class Widget implements IWidget {
439
446
  *
440
447
  * @return {number} The value of the 'left' property.
441
448
  */
442
- public getX(): number {
449
+ public getX(recursive: boolean = false): number {
450
+ if (!recursive) {
451
+ return this.left;
452
+ }
453
+
454
+ const parent = this.getParent();
455
+
456
+ if (parent) {
457
+ return this.left + parent.getX(true);
458
+ }
443
459
  return this.left;
444
460
  }
445
461
 
@@ -448,7 +464,16 @@ export class Widget implements IWidget {
448
464
  *
449
465
  * @return {number} The value of Y.
450
466
  */
451
- public getY(): number {
467
+ public getY(recursive: boolean = false): number {
468
+ if (!recursive) {
469
+ return this.top;
470
+ }
471
+
472
+ const parent = this.getParent();
473
+
474
+ if (parent) {
475
+ return this.top + parent.getY(true);
476
+ }
452
477
  return this.top;
453
478
  }
454
479