swing-ui 1.1.0 → 1.1.4

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/classes/Shape.js CHANGED
@@ -57,6 +57,14 @@ export class Shape
57
57
  this.#prop.y = Number.isFinite(y) ? y : 0;
58
58
  }
59
59
 
60
+ /**
61
+ * @internal
62
+ */
63
+ setParent(p)
64
+ {
65
+ this.#prop.parent = p;
66
+ }
67
+
60
68
  /**
61
69
  * Add this shape to a container.
62
70
  *
@@ -52,15 +52,16 @@ export class ShapeContainer extends ComponentContainer
52
52
  if(!(args[0][i] instanceof Shape)) throw new TypeError(`Invalid "shape" at index ${i} in the array argument passed to Panel.shapes(shapes).`);
53
53
  });
54
54
 
55
- const update = this.prop.update !== false;
56
- if(update) this.update(false);
55
+ if(Array.isArray(this._shapes)) this._shapes.forEach(shape => shape.setParent(null) );
56
+ this._shapes = [...args[0]];
57
57
 
58
- // remove existing shapes
59
- for(let i = this._shapes.length - 1; i >= 0; i--) this._shapes[i].remove();
60
-
61
- args[0].forEach(shape => shape.addTo(this));
58
+ const _objects = [];
59
+ this._shapes.forEach(shape => {
60
+ shape.setParent(this);
61
+ _objects.push(shape.toObject("all"));
62
+ });
62
63
 
63
- if(update) this.update(true);
64
+ this.property('set_shapes', [_objects])
64
65
  }
65
66
 
66
67
  return this;
@@ -144,7 +145,7 @@ export class ShapeContainer extends ComponentContainer
144
145
  * Removes a specified Shape, then the removed Shape is returned.
145
146
  *
146
147
  * @param {number|Shape} index_or_shape - Shape or index of the Shape to be removed.
147
- * @return {Shape|boolean} Returns removed Shape, or `false` in case when index is invalid or out of bounds.
148
+ * @return {Shape|null} Returns removed Shape, or `null` in case when index is invalid or out of bounds.
148
149
  * @see Shape#remove
149
150
  */
150
151
  removeShape(index)
@@ -156,12 +157,12 @@ export class ShapeContainer extends ComponentContainer
156
157
  {
157
158
  shape = index;
158
159
  index = this._shapes.indexOf(index);
159
- if(index < 0) return false;
160
+ if(index < 0) return null;
160
161
  }
161
162
  else
162
163
  {
163
164
  shape = this._shapes[index];
164
- if(shape === undefined) return false;
165
+ if(shape === undefined) return null;
165
166
  }
166
167
 
167
168
  if(shape.parent === this) // remove shape parent first, then come back
package/icon.png CHANGED
Binary file
package/jar/gui-11.jar CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swing-ui",
3
- "version": "1.1.0",
3
+ "version": "1.1.4",
4
4
  "description": "Cross-platform Graphic User Interface for Node.js, Bun and Deno 2+",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -729,5 +729,16 @@ export class SwingUI {
729
729
  * @see SwingUI#exit
730
730
  */
731
731
  onExit(callback?: (arg0: Object) => any | null | undefined, remove?: boolean): SwingUI | Function[];
732
+ /**
733
+ * Registers, unregisters and retrieves event handler for event emitted by changes to screens on the computer, such as connecting a screen, disconnecting a screen, or changes to screen resolution.
734
+ *
735
+ * @param {function(Object):any|null|undefined} [callback] - Function to handle the event, `null` to remove all handlers, or omit to retrieve an array of handlers.
736
+ * @param {boolean} remove - Removed the callback from this event
737
+ * @return {SwingUI|function[]} If called without parameters, an array of registered callbacks is returned; otherwise `this` instance of SwingUI class is returned.
738
+ * @example <h2>Registering screens change event handler:</h2>
739
+ * ui.onScreensChange(e => {console.log(e.screens});
740
+ * @see ui#screens
741
+ */
742
+ onScreensChange(callback?: (arg0: Object) => any | null | undefined, remove?: boolean): SwingUI | Function[];
732
743
  #private;
733
744
  }
@@ -20,7 +20,8 @@ export class ShapeContainer extends ComponentContainer {
20
20
  * @throws {TypeError} When one of passed array elements is not of Shape type.
21
21
  * @see Shape
22
22
  */
23
- shapes(...args: any[]): this | any[];
23
+ shapes(...args: any[]): any[] | this;
24
+ _shapes: any[] | undefined;
24
25
  /**
25
26
  * Gets a Shape at a specified index.
26
27
  *
@@ -51,10 +52,10 @@ export class ShapeContainer extends ComponentContainer {
51
52
  * Removes a specified Shape, then the removed Shape is returned.
52
53
  *
53
54
  * @param {number|Shape} index_or_shape - Shape or index of the Shape to be removed.
54
- * @return {Shape|boolean} Returns removed Shape, or `false` in case when index is invalid or out of bounds.
55
+ * @return {Shape|null} Returns removed Shape, or `null` in case when index is invalid or out of bounds.
55
56
  * @see Shape#remove
56
57
  */
57
- removeShape(index: any): Shape | boolean;
58
+ removeShape(index: any): Shape | null;
58
59
  /**
59
60
  * Registers, unregisters and gets a list of handler functions for Shape events (such as when mouse enters, leaves, mouse button clicks, etc.).
60
61
  *