kaplay-ui 0.5.0 → 0.6.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/index.js +22 -8
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -3,15 +3,28 @@ import "kaplay/global";
|
|
|
3
3
|
/**
|
|
4
4
|
* Adds a clickable button with custom text
|
|
5
5
|
* @param {string} txt - Button text to display
|
|
6
|
-
* @param {
|
|
7
|
-
* @param {
|
|
8
|
-
* @param {
|
|
6
|
+
* @param {Function} [onClick] - Click event handler (default is () => {}))
|
|
7
|
+
* @param {number} x - The x postion to set (default is center().x).
|
|
8
|
+
* @param {y} y - The x postion to set (default is center().y)
|
|
9
|
+
* @param {w} w - Width of button (default is 120)
|
|
10
|
+
* @param {h} h - Height of button (default is 50)
|
|
11
|
+
* @param {txtSize} txtSize - Text size of button (default is 15)
|
|
9
12
|
* @param {boolean} [hover] - Add hover effect (default is true)
|
|
10
13
|
* @returns {GameObj}
|
|
11
14
|
*/
|
|
12
|
-
export const addTextButton = (
|
|
15
|
+
export const addTextButton = (
|
|
16
|
+
txt,
|
|
17
|
+
onClick = () => {},
|
|
18
|
+
x = center().x,
|
|
19
|
+
y = center().y,
|
|
20
|
+
w = 120,
|
|
21
|
+
h = 50,
|
|
22
|
+
txtSize = 15,
|
|
23
|
+
hover = true
|
|
24
|
+
) => {
|
|
25
|
+
// Button
|
|
13
26
|
const btn = add([
|
|
14
|
-
rect(
|
|
27
|
+
rect(w, h, { radius: 8 }),
|
|
15
28
|
pos(x, y),
|
|
16
29
|
area(),
|
|
17
30
|
anchor("center"),
|
|
@@ -19,10 +32,11 @@ export const addTextButton = (txt, x, y, f = () => {}, hover = true) => {
|
|
|
19
32
|
color(255, 255, 255),
|
|
20
33
|
]);
|
|
21
34
|
|
|
22
|
-
//
|
|
23
|
-
btn.add([text(txt), anchor("center"), color(0, 0, 0)]);
|
|
35
|
+
// Button text
|
|
36
|
+
btn.add([text(txt, { size: txtSize }), anchor("center"), color(0, 0, 0)]);
|
|
24
37
|
|
|
25
|
-
|
|
38
|
+
// On click handler
|
|
39
|
+
btn.onClick(onClick);
|
|
26
40
|
|
|
27
41
|
btn.onHoverUpdate(() => {
|
|
28
42
|
setCursor("pointer");
|