kaplay-ui 0.16.1 → 0.18.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/assets/cb-icon.png +0 -0
- package/inputs/index.js +53 -6
- 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
|
|
|
Binary file
|
package/inputs/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import "kaplay/global";
|
|
2
2
|
|
|
3
|
+
import cbIcon from "../assets/cb-icon.png";
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* Makes button with centered text
|
|
5
7
|
* @param {string} txt - Button text to display
|
|
@@ -48,14 +50,16 @@ export const makeTextButton = (
|
|
|
48
50
|
|
|
49
51
|
/**
|
|
50
52
|
* Makes toggle
|
|
51
|
-
* @param {number} x - The x postion to set (default is 0)
|
|
53
|
+
* @param {number} x - The x postion to set (default is 0)
|
|
52
54
|
* @param {number} y - The x postion to set (default is 0)
|
|
55
|
+
* @param {number} width - Toggle width (default is 50)
|
|
56
|
+
* @param {number} height - Toggle height (default is 25)
|
|
53
57
|
* @returns {GameObj}
|
|
54
58
|
*/
|
|
55
|
-
export const makeToggle = (x = 0, y = 0) => {
|
|
59
|
+
export const makeToggle = (x = 0, y = 0, width = 50, height = 25) => {
|
|
56
60
|
// Toggle base
|
|
57
61
|
const toggle = make([
|
|
58
|
-
rect(
|
|
62
|
+
rect(width, height, { radius: height / 2 }),
|
|
59
63
|
pos(x, y),
|
|
60
64
|
color(169, 169, 169),
|
|
61
65
|
area(),
|
|
@@ -65,7 +69,11 @@ export const makeToggle = (x = 0, y = 0) => {
|
|
|
65
69
|
]);
|
|
66
70
|
|
|
67
71
|
// Toggle button
|
|
68
|
-
const toggleBtn = make([
|
|
72
|
+
const toggleBtn = make([
|
|
73
|
+
circle(height * 0.4),
|
|
74
|
+
color(WHITE),
|
|
75
|
+
pos(height / 2, height / 2),
|
|
76
|
+
]);
|
|
69
77
|
|
|
70
78
|
// Add button to toggleBase
|
|
71
79
|
toggle.add(toggleBtn);
|
|
@@ -73,14 +81,53 @@ export const makeToggle = (x = 0, y = 0) => {
|
|
|
73
81
|
toggle.onClick(() => {
|
|
74
82
|
if (toggle.toggled) {
|
|
75
83
|
toggle.use(color(169, 169, 169));
|
|
76
|
-
toggleBtn.use(pos(
|
|
84
|
+
toggleBtn.use(pos(height / 2, height / 2));
|
|
77
85
|
toggle.toggled = false;
|
|
78
86
|
} else {
|
|
79
87
|
toggle.use(color(171, 221, 100));
|
|
80
|
-
toggleBtn.use(pos(
|
|
88
|
+
toggleBtn.use(pos(width - height / 2, height / 2));
|
|
81
89
|
toggle.toggled = true;
|
|
82
90
|
}
|
|
83
91
|
});
|
|
84
92
|
|
|
85
93
|
return toggle;
|
|
86
94
|
};
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Makes checkbox
|
|
98
|
+
* @param {number} x - The x postion to set (default is 0)
|
|
99
|
+
* @param {number} y - The x postion to set (default is 0)
|
|
100
|
+
* @param {number} width - Checkbox width (default is 50)
|
|
101
|
+
* @param {number} height - Checkbox height (default is 50)
|
|
102
|
+
* @returns {GameObj}
|
|
103
|
+
*/
|
|
104
|
+
export const makeCheckbox = (x = 0, y = 0, width = 50, height = 50) => {
|
|
105
|
+
loadSprite("cb", cbIcon);
|
|
106
|
+
|
|
107
|
+
const checkbox = make([
|
|
108
|
+
rect(width, height, { radius: 4 }),
|
|
109
|
+
pos(x, y),
|
|
110
|
+
color(255, 255, 255),
|
|
111
|
+
outline(1),
|
|
112
|
+
area(),
|
|
113
|
+
{
|
|
114
|
+
checked: false,
|
|
115
|
+
},
|
|
116
|
+
]);
|
|
117
|
+
|
|
118
|
+
const checkedIcon = make([sprite("cb", { width, height }), area()]);
|
|
119
|
+
|
|
120
|
+
checkbox.onClick(() => {
|
|
121
|
+
if (checkbox.checked) {
|
|
122
|
+
checkbox.use(color(255, 255, 255));
|
|
123
|
+
checkbox.remove(checkedIcon);
|
|
124
|
+
checkbox.checked = false;
|
|
125
|
+
} else {
|
|
126
|
+
checkbox.use(color(148, 188, 236));
|
|
127
|
+
checkbox.add(checkedIcon);
|
|
128
|
+
checkbox.checked = true;
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
return checkbox;
|
|
133
|
+
};
|