kaplay-ui 0.11.0 → 0.13.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.
Files changed (2) hide show
  1. package/buttons/index.js +25 -45
  2. package/package.json +1 -1
package/buttons/index.js CHANGED
@@ -1,65 +1,45 @@
1
1
  import "kaplay/global";
2
2
 
3
3
  /**
4
- * Adds a clickable button with custom text
4
+ * Makes button with centered text
5
5
  * @param {string} txt - Button text to display
6
- * @param {number} x - The x postion to set (default is center().x).
7
- * @param {number} y - The x postion to set (default is center().y)
8
- * @param {number} w - Width of button (default is 120)
9
- * @param {number} h - Height of button (default is 50)
6
+ * @param {number} x - The x postion to set (default is 0).
7
+ * @param {number} y - The x postion to set (default is 0)
8
+ * @param {number} width - Width of button (default is 100)
9
+ * @param {number} height - Height of button (default is 50)
10
+ * @param {number} btnRadius - Border radius of button (default is 8)
10
11
  * @param {number} txtSize - Text size of button (default is 15)
11
- * @param {boolean} [hoverFx] - Add hover effect (default is true)
12
12
  * @returns {GameObj}
13
13
  */
14
- export const addTextButton = (
14
+ export const makeTextButton = (
15
15
  txt,
16
- x = center().x,
17
- y = center().y,
18
- w = 120,
19
- h = 50,
20
- txtSize = 15,
21
- hoverFx = true
16
+ x = 0,
17
+ y = 0,
18
+ width = 100,
19
+ height = 50,
20
+ btnRadius = 8,
21
+ txtSize = 15
22
22
  ) => {
23
- // Shadow effect
24
- const shadow = add([
25
- rect(w, h, { radius: 8 }),
26
- pos(x + 2, y + 2),
27
- area(),
28
- scale(1),
29
- anchor("center"),
30
- outline(1),
31
- color(128, 128, 128),
32
- ]);
33
-
34
- // Button
35
- const btn = add([
36
- rect(w, h, { radius: 8 }),
23
+ // Make button
24
+ const btn = make([
25
+ rect(width, height, { radius: btnRadius }),
37
26
  pos(x, y),
38
27
  area(),
39
28
  scale(1),
40
- anchor("center"),
41
29
  outline(1),
42
30
  color(255, 255, 255),
43
31
  ]);
44
32
 
45
- // Button text
46
- btn.add([text(txt, { size: txtSize }), anchor("center"), color(0, 0, 0)]);
47
-
48
- btn.onHover(() => {
49
- setCursor("pointer");
50
- if (hoverFx) {
51
- btn.scale = vec2(1.03);
52
- shadow.scale = vec2(1.03);
53
- }
54
- });
33
+ // Make button text
34
+ const btnText = make([
35
+ text(txt, { size: txtSize }),
36
+ pos(width / 2, height / 2),
37
+ anchor("center"),
38
+ color(0, 0, 0),
39
+ ]);
55
40
 
56
- btn.onHoverEnd(() => {
57
- setCursor("default");
58
- if (hoverFx) {
59
- btn.scale = vec2(1);
60
- shadow.scale = vec2(1);
61
- }
62
- });
41
+ // Add text to button
42
+ btn.add(btnText);
63
43
 
64
44
  return btn;
65
45
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kaplay-ui",
3
- "version": "0.11.0",
3
+ "version": "0.13.0",
4
4
  "description": "UI components for KAPLAY",
5
5
  "main": "index.js",
6
6
  "repository": {