kaplay-ui 0.16.0 → 0.17.0
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/README.md +2 -0
- package/inputs/index.js +13 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -49,6 +49,8 @@ Makes a toggle that takes the following parameters:
|
|
|
49
49
|
| --------- | -------- | ------- | -------- | ----------------- |
|
|
50
50
|
| `x` | `number` | 0 | ❌ No | Toggle x position |
|
|
51
51
|
| `y` | `number` | 0 | ❌ No | Toggle y position |
|
|
52
|
+
| `width` | `number` | 50 | ❌ No | Toggle width |
|
|
53
|
+
| `height` | `number` | 25 | ❌ No | Toggle height |
|
|
52
54
|
|
|
53
55
|
## License
|
|
54
56
|
|
package/inputs/index.js
CHANGED
|
@@ -48,14 +48,16 @@ export const makeTextButton = (
|
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
50
|
* Makes toggle
|
|
51
|
-
* @param {number} x - The x postion to set (default is 0)
|
|
51
|
+
* @param {number} x - The x postion to set (default is 0)
|
|
52
52
|
* @param {number} y - The x postion to set (default is 0)
|
|
53
|
+
* @param {number} width - Toggle width (default is 50)
|
|
54
|
+
* @param {number} height - Toggle height (default is 25)
|
|
53
55
|
* @returns {GameObj}
|
|
54
56
|
*/
|
|
55
|
-
export const makeToggle = (x = 0, y = 0) => {
|
|
57
|
+
export const makeToggle = (x = 0, y = 0, width = 50, height = 25) => {
|
|
56
58
|
// Toggle base
|
|
57
59
|
const toggle = make([
|
|
58
|
-
rect(
|
|
60
|
+
rect(width, height, { radius: height / 2 }),
|
|
59
61
|
pos(x, y),
|
|
60
62
|
color(169, 169, 169),
|
|
61
63
|
area(),
|
|
@@ -65,7 +67,11 @@ export const makeToggle = (x = 0, y = 0) => {
|
|
|
65
67
|
]);
|
|
66
68
|
|
|
67
69
|
// Toggle button
|
|
68
|
-
const toggleBtn = make([
|
|
70
|
+
const toggleBtn = make([
|
|
71
|
+
circle(height * 0.4),
|
|
72
|
+
color(WHITE),
|
|
73
|
+
pos(height / 2, height / 2),
|
|
74
|
+
]);
|
|
69
75
|
|
|
70
76
|
// Add button to toggleBase
|
|
71
77
|
toggle.add(toggleBtn);
|
|
@@ -73,11 +79,11 @@ export const makeToggle = (x = 0, y = 0) => {
|
|
|
73
79
|
toggle.onClick(() => {
|
|
74
80
|
if (toggle.toggled) {
|
|
75
81
|
toggle.use(color(169, 169, 169));
|
|
76
|
-
toggleBtn.use(pos(
|
|
82
|
+
toggleBtn.use(pos(height / 2, height / 2));
|
|
77
83
|
toggle.toggled = false;
|
|
78
84
|
} else {
|
|
79
|
-
toggle.use(color(
|
|
80
|
-
toggleBtn.use(pos(
|
|
85
|
+
toggle.use(color(171, 221, 100));
|
|
86
|
+
toggleBtn.use(pos(width - height / 2, height / 2));
|
|
81
87
|
toggle.toggled = true;
|
|
82
88
|
}
|
|
83
89
|
});
|