kaplay-ui 0.15.2 → 0.16.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 +18 -25
- package/{buttons → inputs}/index.js +39 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -24,38 +24,31 @@ npm install kaplay-ui
|
|
|
24
24
|
|
|
25
25
|
## Usage
|
|
26
26
|
|
|
27
|
-
###
|
|
27
|
+
### Inputs
|
|
28
28
|
|
|
29
29
|
#### Text Button
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
Makes a button with centered text that takes the following parameters:
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
| Parameter | Type | Default | Required | Description |
|
|
34
|
+
| ------------ | -------- | ------- | -------- | ---------------------------------- |
|
|
35
|
+
| `text` | `string` | N/A | ✅ Yes | The text to display on the button. |
|
|
36
|
+
| `x` | `number` | 0 | ❌ No | Button x position |
|
|
37
|
+
| `y` | `number` | 0 | ❌ No | Button y position |
|
|
38
|
+
| `width` | `number` | 100 | ❌ No | Button width |
|
|
39
|
+
| `height` | `number` | 50 | ❌ No | Button height |
|
|
40
|
+
| `btnRadius` | `number` | 8 | ❌ No | Button radius |
|
|
41
|
+
| `btnOutline` | `number` | 1 | ❌ No | Button outline |
|
|
42
|
+
| `txtSize` | `number` | 15 | ❌ No | Text size |
|
|
36
43
|
|
|
37
|
-
|
|
44
|
+
#### Toggle
|
|
38
45
|
|
|
39
|
-
|
|
46
|
+
Makes a toggle that takes the following parameters:
|
|
40
47
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
addTextButton("Start", () => go("game"));
|
|
46
|
-
|
|
47
|
-
// Add a text button with x and y position
|
|
48
|
-
addTextButton("Start", () => go("game"), 200, 200);
|
|
49
|
-
|
|
50
|
-
// Add a text button with width and height
|
|
51
|
-
addTextButton("Start", () => go("game"), 200, 200, 200, 70);
|
|
52
|
-
|
|
53
|
-
// Add a text button with text size
|
|
54
|
-
addTextButton("Start", () => go("game"), 200, 200, 200, 70, 20);
|
|
55
|
-
|
|
56
|
-
// Add a text button with disabled hover effect
|
|
57
|
-
addTextButton("Start", () => go("game"), 200, 200, 200, 70, 20, false);
|
|
58
|
-
```
|
|
48
|
+
| Parameter | Type | Default | Required | Description |
|
|
49
|
+
| --------- | -------- | ------- | -------- | ----------------- |
|
|
50
|
+
| `x` | `number` | 0 | ❌ No | Toggle x position |
|
|
51
|
+
| `y` | `number` | 0 | ❌ No | Toggle y position |
|
|
59
52
|
|
|
60
53
|
## License
|
|
61
54
|
|
|
@@ -45,3 +45,42 @@ export const makeTextButton = (
|
|
|
45
45
|
|
|
46
46
|
return btn;
|
|
47
47
|
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Makes toggle
|
|
51
|
+
* @param {number} x - The x postion to set (default is 0).
|
|
52
|
+
* @param {number} y - The x postion to set (default is 0)
|
|
53
|
+
* @returns {GameObj}
|
|
54
|
+
*/
|
|
55
|
+
export const makeToggle = (x = 0, y = 0) => {
|
|
56
|
+
// Toggle base
|
|
57
|
+
const toggle = make([
|
|
58
|
+
rect(50, 25, { radius: 25 }),
|
|
59
|
+
pos(x, y),
|
|
60
|
+
color(169, 169, 169),
|
|
61
|
+
area(),
|
|
62
|
+
{
|
|
63
|
+
toggled: false,
|
|
64
|
+
},
|
|
65
|
+
]);
|
|
66
|
+
|
|
67
|
+
// Toggle button
|
|
68
|
+
const toggleBtn = make([circle(10), color(WHITE), pos(12.5, 12.5)]);
|
|
69
|
+
|
|
70
|
+
// Add button to toggleBase
|
|
71
|
+
toggle.add(toggleBtn);
|
|
72
|
+
|
|
73
|
+
toggle.onClick(() => {
|
|
74
|
+
if (toggle.toggled) {
|
|
75
|
+
toggle.use(color(169, 169, 169));
|
|
76
|
+
toggleBtn.use(pos(12.5, 12.5));
|
|
77
|
+
toggle.toggled = false;
|
|
78
|
+
} else {
|
|
79
|
+
toggle.use(color(59, 130, 246));
|
|
80
|
+
toggleBtn.use(pos(37.5, 12.5));
|
|
81
|
+
toggle.toggled = true;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
return toggle;
|
|
86
|
+
};
|