kaplay-ui 0.20.15 → 0.20.16
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 +105 -93
- package/docs/_includes/nav.html +8 -6
- package/docs/about.md +0 -3
- package/docs/api/components.md +255 -0
- package/docs/api/plugin.md +117 -0
- package/docs/assets/style.css +32 -0
- package/docs/index.md +25 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,12 +11,25 @@ Kaplay UI provides a game‑oriented **UI plugin** designed specifically for KAP
|
|
|
11
11
|
For now it helps you build Game Objects like text buttons and labels — without reinventing the wheel.
|
|
12
12
|
|
|
13
13
|
> ⚠️ **Note**
|
|
14
|
-
> The currently published stable version (`0.20.
|
|
14
|
+
> The currently published stable version (`0.20.16`) is being replaced by a complete redesign.
|
|
15
15
|
>
|
|
16
16
|
> A new **v1** version is under active development and can be installed in prerelease form (see below).
|
|
17
17
|
|
|
18
18
|
---
|
|
19
19
|
|
|
20
|
+
## ✨ _What this plugin currently provides_
|
|
21
|
+
|
|
22
|
+
When installed, this plugin extends the KAPLAY context (`k`) with:
|
|
23
|
+
|
|
24
|
+
- `k.addTextButton()` – interactive buttons with centered text
|
|
25
|
+
- `k.addLabel()` – lightweight, non-interactive text labels
|
|
26
|
+
|
|
27
|
+
Each helper returns a regular KAPLAY game object enhanced with
|
|
28
|
+
**convenience methods** for changing size, position, colors, text, and more
|
|
29
|
+
after creation.
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
20
33
|
## 📦 Installation
|
|
21
34
|
|
|
22
35
|
### Prerelease (new v1 work)
|
|
@@ -29,11 +42,9 @@ This gives you the latest `1.0.0‑alpha.*` builds.
|
|
|
29
42
|
|
|
30
43
|
---
|
|
31
44
|
|
|
32
|
-
## 🚀
|
|
33
|
-
|
|
34
|
-
**Kaplay UI** exports a plugin for adding UI Game Objects.
|
|
45
|
+
## 🚀 Quick start (_1.0.0-alpha.\*_)
|
|
35
46
|
|
|
36
|
-
The
|
|
47
|
+
The **Kaplay-UI** plugin is exported as `kaplayUI` from the package root:
|
|
37
48
|
|
|
38
49
|
```ts
|
|
39
50
|
import kaplay from "kaplay";
|
|
@@ -47,143 +58,144 @@ const k = kaplay({
|
|
|
47
58
|
You now have access to the UI helpers via your `k` instance:
|
|
48
59
|
|
|
49
60
|
```ts
|
|
50
|
-
const btn = k.addTextButton("
|
|
51
|
-
|
|
61
|
+
const btn = k.addTextButton("Start");
|
|
62
|
+
btn.onClick(() => {
|
|
63
|
+
k.go("game");
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const lbl = k.addLabel("Score: 0");
|
|
67
|
+
lbl.setLabelText("Score: 1");
|
|
52
68
|
```
|
|
53
69
|
|
|
54
70
|
---
|
|
55
71
|
|
|
56
72
|
## 🧩 Game Objects (_**1.0.0‑alpha.\***_)
|
|
57
73
|
|
|
58
|
-
### 🔤
|
|
74
|
+
### 🔤 Text Button — `addTextButton()`
|
|
75
|
+
|
|
76
|
+
Creates a clickable button with centered text and default visuals.
|
|
59
77
|
|
|
60
|
-
|
|
78
|
+
```ts
|
|
79
|
+
const btn = k.addTextButton("Start", {
|
|
80
|
+
width: 200,
|
|
81
|
+
height: 80,
|
|
82
|
+
});
|
|
83
|
+
```
|
|
61
84
|
|
|
62
|
-
|
|
85
|
+
Buttons support runtime updates such as:
|
|
63
86
|
|
|
64
87
|
```ts
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
)
|
|
88
|
+
btn.setSize(300, 100);
|
|
89
|
+
btn.setButtonColor([255, 120, 120]);
|
|
90
|
+
btn.setButtonText("Go!");
|
|
91
|
+
btn.setButtonTextSize(24);
|
|
69
92
|
```
|
|
70
93
|
|
|
71
|
-
|
|
94
|
+
Perfect for menus, dialogs, and in‑game actions.
|
|
72
95
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
| `height` | `100` |
|
|
77
|
-
| `radius` | `10` |
|
|
78
|
-
| `posX` | `0` |
|
|
79
|
-
| `posY` | `0` |
|
|
80
|
-
| `outline` | `3` |
|
|
81
|
-
| `txtSize` | `22` |
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
### 🏷️ Label — `addLabel()`
|
|
82
99
|
|
|
83
|
-
|
|
100
|
+
Creates a lightweight background + text container for HUD elements or titles.
|
|
84
101
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
| `button base color` | `200, 200, 200` |
|
|
89
|
-
| `button base outline color` | `92, 91, 91` |
|
|
90
|
-
| `button text anchor` | `"center"` |
|
|
91
|
-
| `buttontext color` | `0, 0, 0` |
|
|
102
|
+
```ts
|
|
103
|
+
const label = k.addLabel("Score: 0");
|
|
104
|
+
```
|
|
92
105
|
|
|
93
|
-
|
|
106
|
+
Update it dynamically:
|
|
94
107
|
|
|
95
108
|
```ts
|
|
96
|
-
|
|
97
|
-
|
|
109
|
+
label.setLabelText("Score: 10");
|
|
110
|
+
label.setLabelTextColor([255, 255, 0]);
|
|
111
|
+
label.setOpacity(0.9);
|
|
112
|
+
```
|
|
98
113
|
|
|
99
|
-
|
|
100
|
-
const btn2 = k.addTextButton("Play!", { posX: 300, posY: 200 });
|
|
114
|
+
Ideal for HUDs, counters, status text, and overlays.
|
|
101
115
|
|
|
102
|
-
|
|
103
|
-
btn2.use(k.color(150, 150, 150));
|
|
116
|
+
---
|
|
104
117
|
|
|
105
|
-
|
|
106
|
-
btn2.children[0].text = "Go!";
|
|
118
|
+
## 🎨 Customization
|
|
107
119
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
120
|
+
kaplay-ui is designed to be **customized imperatively**, without hiding
|
|
121
|
+
or abstracting away KAPLAY’s core APIs.
|
|
122
|
+
|
|
123
|
+
### ✅ Option-based customization (at creation)
|
|
124
|
+
|
|
125
|
+
Both helpers accept an optional `opts` object for common configuration:
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
const btn = k.addTextButton("Options", {
|
|
129
|
+
width: 250,
|
|
130
|
+
height: 70,
|
|
131
|
+
posX: 100,
|
|
132
|
+
posY: 200,
|
|
133
|
+
radius: 8,
|
|
111
134
|
});
|
|
112
135
|
```
|
|
113
136
|
|
|
114
137
|
---
|
|
115
138
|
|
|
116
|
-
###
|
|
117
|
-
|
|
118
|
-
A lightweight text-based UI element — ideal for HUD counters, tooltips, status text, or titles.
|
|
139
|
+
### ✅ Runtime customization (after creation)
|
|
119
140
|
|
|
120
|
-
|
|
141
|
+
Each UI element exposes helper methods for updating its appearance and layout:
|
|
121
142
|
|
|
122
143
|
```ts
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
)
|
|
144
|
+
btn.setPosition(150, 220);
|
|
145
|
+
btn.setButtonColor([80, 160, 255]);
|
|
146
|
+
btn.setButtonTextColor([255, 255, 255]);
|
|
127
147
|
```
|
|
128
148
|
|
|
129
|
-
|
|
149
|
+
This makes it easy to animate, react to state changes, or reuse UI elements.
|
|
130
150
|
|
|
131
|
-
|
|
132
|
-
| --------- | ------- |
|
|
133
|
-
| `width` | `160` |
|
|
134
|
-
| `height` | `96` |
|
|
135
|
-
| `posX` | `0` |
|
|
136
|
-
| `posY` | `0` |
|
|
137
|
-
| `opacity` | `0.7` |
|
|
138
|
-
| `txtSize` | `22` |
|
|
139
|
-
|
|
140
|
-
#### _**Default styling**_
|
|
151
|
+
---
|
|
141
152
|
|
|
142
|
-
|
|
143
|
-
| ------------------- | :-------------- |
|
|
144
|
-
| `label base color` | `0, 0,0 ` |
|
|
145
|
-
| `label base anchor` | `"topleft"` |
|
|
146
|
-
| `label text color` | `255, 255, 255` |
|
|
147
|
-
| `label text anchor` | `"center"` |
|
|
153
|
+
### ✅ Full KAPLAY access
|
|
148
154
|
|
|
149
|
-
|
|
155
|
+
UI elements are **regular KAPLAY game objects**, so you can still use all
|
|
156
|
+
standard KAPLAY features:
|
|
150
157
|
|
|
151
158
|
```ts
|
|
152
|
-
|
|
153
|
-
|
|
159
|
+
btn.use(k.opacity(0.8));
|
|
160
|
+
btn.onHover(() => btn.setScale(1.1));
|
|
161
|
+
label.use(k.rotate(5));
|
|
162
|
+
```
|
|
154
163
|
|
|
155
|
-
|
|
156
|
-
const lbl2 = k.addLabel("Start", { width: 100, height: 50 });
|
|
164
|
+
kaplay-ui never locks you into a restricted UI model.
|
|
157
165
|
|
|
158
|
-
|
|
159
|
-
lbl2.use(k.color(150, 150, 150));
|
|
166
|
+
---
|
|
160
167
|
|
|
161
|
-
|
|
162
|
-
lbl2.children[0].text = "Coins: 100";
|
|
168
|
+
## 🧠 Design philosophy
|
|
163
169
|
|
|
164
|
-
|
|
165
|
-
let score = 0;
|
|
166
|
-
const scoreLabel = k.addLabel(`Score: ${score}`);
|
|
170
|
+
**kaplay-ui** is intentionally simple:
|
|
167
171
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
```
|
|
172
|
+
- ✅ No retained UI trees
|
|
173
|
+
- ✅ No layout engine
|
|
174
|
+
- ✅ No reactive framework
|
|
175
|
+
- ✅ Just KAPLAY game objects + helpers
|
|
173
176
|
|
|
174
|
-
|
|
177
|
+
You stay in control of how and when UI updates happen.
|
|
175
178
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
-
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
## 📚 Documentation
|
|
182
|
+
|
|
183
|
+
- Full API documentation is available via **JSDocs**
|
|
184
|
+
- All helpers are strongly typed and editor-friendly
|
|
185
|
+
- Hover over methods in your editor to explore options
|
|
181
186
|
|
|
182
187
|
---
|
|
183
188
|
|
|
184
189
|
## 🛣️ Roadmap
|
|
185
190
|
|
|
186
|
-
|
|
191
|
+
Future components may include:
|
|
192
|
+
|
|
193
|
+
- Toggles
|
|
194
|
+
- Sliders
|
|
195
|
+
- Panels / containers
|
|
196
|
+
|
|
197
|
+
See the roadmap here:
|
|
198
|
+
👉 <https://github.com/jbakchr/kaplay-ui/blob/v1/ROADMAP.md>
|
|
187
199
|
|
|
188
200
|
---
|
|
189
201
|
|
package/docs/_includes/nav.html
CHANGED
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
|
|
22
22
|
/* Brand */
|
|
23
23
|
.nav-brand {
|
|
24
|
-
font-size: 1.
|
|
25
|
-
font-weight:
|
|
24
|
+
font-size: 1.4rem;
|
|
25
|
+
font-weight: 800;
|
|
26
26
|
text-decoration: none;
|
|
27
27
|
color: var(--text-dark-green);
|
|
28
28
|
}
|
|
@@ -105,7 +105,9 @@
|
|
|
105
105
|
<nav class="navbar">
|
|
106
106
|
<div class="nav-inner">
|
|
107
107
|
<!-- Logo / Title -->
|
|
108
|
-
<a class="nav-brand" href="
|
|
108
|
+
<a class="nav-brand" href="https://jbakchr.github.io/kaplay-ui/index"
|
|
109
|
+
>kaplay‑ui</a
|
|
110
|
+
>
|
|
109
111
|
|
|
110
112
|
<!-- Hamburger -->
|
|
111
113
|
<input type="checkbox" id="nav-toggle" class="nav-toggle" />
|
|
@@ -117,9 +119,9 @@
|
|
|
117
119
|
|
|
118
120
|
<!-- Menu -->
|
|
119
121
|
<ul class="nav-menu">
|
|
120
|
-
<li><a href="
|
|
121
|
-
<li><a href="
|
|
122
|
-
<li><a href="
|
|
122
|
+
<li><a href="https://jbakchr.github.io/kaplay-ui/api/plugin">API</a></li>
|
|
123
|
+
<li><a href="https://jbakchr.github.io/kaplay-ui/faq">FAQ</a></li>
|
|
124
|
+
<li><a href="https://jbakchr.github.io/kaplay-ui/about">About</a></li>
|
|
123
125
|
</ul>
|
|
124
126
|
</div>
|
|
125
127
|
</nav>
|
package/docs/about.md
CHANGED
|
@@ -37,9 +37,6 @@ Thanks for being here — and happy creating! 🦖✨
|
|
|
37
37
|
|
|
38
38
|
_— [Jonas Bak Phillipson](https://github.com/jbakchr) (2026)_ 💚 🇩🇰 🏴☠️
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
_(And oh .. "ps": I'm actually **not** a 'gamer' myself - but I'd **love** it if KAPLAY and my KAPLAY-UI plugin could help kids and others code their own games!)_
|
|
42
|
-
|
|
43
40
|
---
|
|
44
41
|
|
|
45
42
|
<p align="center">
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
# 🧱 UI Components
|
|
2
|
+
|
|
3
|
+
KAPLAY‑UI provides a small set of lightweight, game‑ready UI components.
|
|
4
|
+
|
|
5
|
+
All components behave like native KAPLAY objects, integrating naturally with scenes, layers, positions, and events.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 🔤 TextButton
|
|
10
|
+
|
|
11
|
+
A clickable button with centered text.
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
const btn = k.addTextButton("Play");
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
### Signature
|
|
20
|
+
|
|
21
|
+
The `addTextButton` method takes a required `string` and an optional `object`.
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
k.addTextButton(txt: string, opts?: {});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
### Options
|
|
30
|
+
|
|
31
|
+
All fields are optional. Defaults are shown below.
|
|
32
|
+
|
|
33
|
+
| Option | Type | Default |
|
|
34
|
+
| ------------ | ----------------------- | --------------- |
|
|
35
|
+
| width | number | 150 |
|
|
36
|
+
| height | number | 60 |
|
|
37
|
+
| posX | number | 0 |
|
|
38
|
+
| posY | number | 0 |
|
|
39
|
+
| radius | number | 10 |
|
|
40
|
+
| outline | number | 3 |
|
|
41
|
+
| txtSize | number | 22 |
|
|
42
|
+
| btnColor | [number, number, nuber] | [200, 200, 200] |
|
|
43
|
+
| outlineColor | string | #5c5b5b |
|
|
44
|
+
| txtColor | [number, number, nuber] | [0, 0, 0] |
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
### Default Styling
|
|
49
|
+
|
|
50
|
+
These are the built‑in visual defaults applied automatically.
|
|
51
|
+
|
|
52
|
+
The **button object** is created with:
|
|
53
|
+
|
|
54
|
+
- `k.anchor("topleft")`
|
|
55
|
+
- `k.area()`
|
|
56
|
+
|
|
57
|
+
The **button text** is created with:
|
|
58
|
+
|
|
59
|
+
- `k.anchor("center")`
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
### Text Button Instance Methods
|
|
64
|
+
|
|
65
|
+
The returned `ButtonComponent` exposes the following mutator methods,
|
|
66
|
+
allowing the button to be updated after creation:
|
|
67
|
+
|
|
68
|
+
#### Layout & Geometry
|
|
69
|
+
|
|
70
|
+
- `setSize(w: number, h: number): void`
|
|
71
|
+
_Update the button width and height._
|
|
72
|
+
|
|
73
|
+
- `setPosition(x: number, y: number): void`
|
|
74
|
+
_Move the button to a new position._
|
|
75
|
+
|
|
76
|
+
- `setAnchor(a: Anchor): void`
|
|
77
|
+
_Change the anchor used for positioning._
|
|
78
|
+
|
|
79
|
+
- `setRadius(r: number): void`
|
|
80
|
+
_Update the corner radius._
|
|
81
|
+
|
|
82
|
+
- `setOutline(t: number): void`
|
|
83
|
+
_Set the outline thickness._
|
|
84
|
+
|
|
85
|
+
#### Text
|
|
86
|
+
|
|
87
|
+
- `setButtonText(txt: string): void`
|
|
88
|
+
_Replace the button label._
|
|
89
|
+
|
|
90
|
+
- `setButtonTextSize(size: number): void`
|
|
91
|
+
_Change the font size of the button text._
|
|
92
|
+
|
|
93
|
+
- `setButtonTextColor(color: KaplayColor): void`
|
|
94
|
+
_Update the text color._
|
|
95
|
+
|
|
96
|
+
#### Colors
|
|
97
|
+
|
|
98
|
+
- `setButtonColor(color: KaplayColor): void`
|
|
99
|
+
_Change the button fill color._
|
|
100
|
+
|
|
101
|
+
- `setButtonOutlineColor(color: KaplayRGB): void`
|
|
102
|
+
_Change the outline stroke color._
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
### Examples
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
// Basic usage
|
|
110
|
+
const btn1 = addTextButton("Play");
|
|
111
|
+
btn1.onClick(() => k.go("game"));
|
|
112
|
+
|
|
113
|
+
// Runtime mutation
|
|
114
|
+
const btn2 = addTextButton("Start");
|
|
115
|
+
btn2.setSize(300, 120);
|
|
116
|
+
btn2.setButtonColor([255, 100, 100]);
|
|
117
|
+
btn2.setButtonText("Go!");
|
|
118
|
+
|
|
119
|
+
// Visual-only updates
|
|
120
|
+
const btn3 = addTextButton("Options", {
|
|
121
|
+
radius: 2,
|
|
122
|
+
});
|
|
123
|
+
btn3.setButtonOutlineColor([0, 0, 0]);
|
|
124
|
+
btn3.setButtonTextSize(24);
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## 🏷️ Label
|
|
130
|
+
|
|
131
|
+
A small, fast text element ideal for HUDs, overlays, and lightweight UI.
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
const score = k.addLabel("Score: 0");
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
### Signature
|
|
140
|
+
|
|
141
|
+
The `addLabel` method takes a required `string` and an optional `object`.
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
k.addLabel(txt: string, opts?: {});
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
### Options
|
|
150
|
+
|
|
151
|
+
All fields are optional. Defaults are shown below.
|
|
152
|
+
|
|
153
|
+
| Option | Type | Default |
|
|
154
|
+
| -------- | ------------------------ | --------------- |
|
|
155
|
+
| widht | number | 160 |
|
|
156
|
+
| height | number | 96 |
|
|
157
|
+
| posX | number | 0 |
|
|
158
|
+
| posY | number | 0 |
|
|
159
|
+
| opacity | number | 0.7 |
|
|
160
|
+
| txtSize | number | 22 |
|
|
161
|
+
| lblColor | [number, number, number] | [0, 0, 0] |
|
|
162
|
+
| txtColor | [number, number, number] | [255, 255, 255] |
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
### Default Styling
|
|
167
|
+
|
|
168
|
+
| Style | Value |
|
|
169
|
+
| ----------------- | --------- |
|
|
170
|
+
| label anchor | "topleft" |
|
|
171
|
+
| label text anchor | "center" |
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
### Label Instance Methods
|
|
176
|
+
|
|
177
|
+
The returned `LabelComponent` exposes helper methods that allow the label to be updated dynamically at runtime.
|
|
178
|
+
|
|
179
|
+
#### Layout & Geometry
|
|
180
|
+
|
|
181
|
+
- `setSize(w: number, h: number): void`
|
|
182
|
+
_Update the label width and height._
|
|
183
|
+
|
|
184
|
+
- `setPosition(x: number, y: number): void`
|
|
185
|
+
_Move the label to a new position._
|
|
186
|
+
|
|
187
|
+
- `setRadius(r: number): void`
|
|
188
|
+
_Update the background corner radius._
|
|
189
|
+
|
|
190
|
+
- `setLabelAnchor(anchor: Anchor): void`
|
|
191
|
+
_Change the anchor used for positioning the label._
|
|
192
|
+
|
|
193
|
+
#### Appearance
|
|
194
|
+
|
|
195
|
+
- `setOpacity(o: number): void`
|
|
196
|
+
_Set label background opacity (0–1)._
|
|
197
|
+
|
|
198
|
+
- `setLabelColor(c: KaplayColor): void`
|
|
199
|
+
_Change the background color of the label._
|
|
200
|
+
|
|
201
|
+
#### Text
|
|
202
|
+
|
|
203
|
+
- `setLabelText(txt: string): void`
|
|
204
|
+
_Replace the label text._
|
|
205
|
+
|
|
206
|
+
- `setLabelTextSize(size: number): void`
|
|
207
|
+
_Change the font size of the label text._
|
|
208
|
+
|
|
209
|
+
- `setLabelTextColor(c: KaplayColor): void`
|
|
210
|
+
_Update the label text color._
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
### Example
|
|
215
|
+
|
|
216
|
+
```ts
|
|
217
|
+
// Basic usage
|
|
218
|
+
const lbl = addLabel("Score: 0");
|
|
219
|
+
lbl.setPosition(20, 20);
|
|
220
|
+
|
|
221
|
+
// Dynamic text updates (e.g. score counter)
|
|
222
|
+
let score = 0;
|
|
223
|
+
const scoreLbl = addLabel(`Score: ${score}`);
|
|
224
|
+
|
|
225
|
+
k.wait(2, () => {
|
|
226
|
+
score++;
|
|
227
|
+
scoreLbl.setLabelText(`Score: ${score}`);
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
// Runtime appearance updates
|
|
231
|
+
const title = addLabel("Game Over", {
|
|
232
|
+
txtSize: 36,
|
|
233
|
+
});
|
|
234
|
+
title.setLabelColor([40, 40, 40]);
|
|
235
|
+
title.setLabelTextColor([255, 80, 80]);
|
|
236
|
+
title.setOpacity(0.9);
|
|
237
|
+
|
|
238
|
+
// Layout adjustment after creation
|
|
239
|
+
const hudLabel = addLabel("Paused");
|
|
240
|
+
hudLabel.setSize(200, 60);
|
|
241
|
+
hudLabel.setLabelAnchor("center");
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
---
|
|
245
|
+
|
|
246
|
+
## 📦 More Components Coming Soon
|
|
247
|
+
|
|
248
|
+
Planned UI components include:
|
|
249
|
+
|
|
250
|
+
- Sliders
|
|
251
|
+
- Toggles
|
|
252
|
+
- Panels / Containers
|
|
253
|
+
- Layout helpers (stacks, grids)
|
|
254
|
+
|
|
255
|
+
These will be added here as the library grows.
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# Plugin API
|
|
2
|
+
|
|
3
|
+
The KAPLAY‑UI plugin extends your `kaplay()` instance with a small set of UI‑focused helper methods.
|
|
4
|
+
|
|
5
|
+
Once added, the plugin injects new functions on your KAPLAY context for creating UI components.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 🧩 Adding the Plugin
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import kaplay from "kaplay";
|
|
13
|
+
import kaplayUI from "kaplay-ui";
|
|
14
|
+
|
|
15
|
+
const k = kaplay({
|
|
16
|
+
plugins: [kaplayUI],
|
|
17
|
+
});
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
After this, your `k` instance includes:
|
|
21
|
+
|
|
22
|
+
- `k.addTextButton(txt, opts?)`
|
|
23
|
+
- `k.addLabel(txt, opts?)`
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## 🟦 `k.addTextButton(txt, opts?)`
|
|
28
|
+
|
|
29
|
+
Creates a clickable UI button with built‑in hitbox, outline, and text alignment.
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
const btn = k.addTextButton("Play");
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Parameters
|
|
36
|
+
|
|
37
|
+
<table>
|
|
38
|
+
<tr>
|
|
39
|
+
<th>Name</th>
|
|
40
|
+
<th>Type</th>
|
|
41
|
+
<th>Description</th>
|
|
42
|
+
</tr>
|
|
43
|
+
<tr>
|
|
44
|
+
<td>txt</td>
|
|
45
|
+
<td>string</td>
|
|
46
|
+
<td>The button label</td>
|
|
47
|
+
</tr>
|
|
48
|
+
<tr>
|
|
49
|
+
<td>opts</td>
|
|
50
|
+
<td>object (optional)</td>
|
|
51
|
+
<td>Styling & behavior options</td>
|
|
52
|
+
</tr>
|
|
53
|
+
</table>
|
|
54
|
+
|
|
55
|
+
### Returns
|
|
56
|
+
|
|
57
|
+
A `TextButton` game object.
|
|
58
|
+
|
|
59
|
+
For full option details and defaults, see:
|
|
60
|
+
➡️ **[./components#textbutton](https://jbakchr.github.io/kaplay-ui/api/components#-textbutton)**
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## 🟨 `k.addLabel(txt, opts?)`
|
|
65
|
+
|
|
66
|
+
Creates a lightweight text element ideal for HUDs and overlays.
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
const lbl = k.addLabel("Score: 0");
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Parameters
|
|
73
|
+
|
|
74
|
+
<table>
|
|
75
|
+
<tr>
|
|
76
|
+
<th>Name</th>
|
|
77
|
+
<th>Type</th>
|
|
78
|
+
<th>Description</th>
|
|
79
|
+
</tr>
|
|
80
|
+
<tr>
|
|
81
|
+
<td>txt</td>
|
|
82
|
+
<td>string</td>
|
|
83
|
+
<td>The displayed text</td>
|
|
84
|
+
</tr>
|
|
85
|
+
<tr>
|
|
86
|
+
<td>opts</td>
|
|
87
|
+
<td>object (optional)</td>
|
|
88
|
+
<td>Styling options.</td>
|
|
89
|
+
</tr>
|
|
90
|
+
</table>
|
|
91
|
+
|
|
92
|
+
### Returns
|
|
93
|
+
|
|
94
|
+
A `Label` game object.
|
|
95
|
+
|
|
96
|
+
For full option details and defaults, see:
|
|
97
|
+
➡️ **[./components.md#label](https://jbakchr.github.io/kaplay-ui/api/components#-label)**
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## ✅ Notes
|
|
102
|
+
|
|
103
|
+
- All UI components behave like standard KAPLAY game objects.
|
|
104
|
+
- They support transforms, events, layers, and plugin composition.
|
|
105
|
+
- UI elements are intentionally minimal, predictable, and easy to theme.
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## 📦 More Plugin Coming Soon
|
|
110
|
+
|
|
111
|
+
Future versions of KAPLAY‑UI will extend the plugin with:
|
|
112
|
+
|
|
113
|
+
- Additional UI creation helpers
|
|
114
|
+
- Built‑in layout utilities
|
|
115
|
+
- Themable presets (light/dark UI packs)
|
|
116
|
+
|
|
117
|
+
These will be added here as the library grows.
|
package/docs/assets/style.css
CHANGED
|
@@ -217,3 +217,35 @@ a:hover {
|
|
|
217
217
|
color: var(--text-box-black);
|
|
218
218
|
transform: translateY(-2px);
|
|
219
219
|
}
|
|
220
|
+
|
|
221
|
+
/* --------------------------------------------------
|
|
222
|
+
API Tables (Parameters)
|
|
223
|
+
-------------------------------------------------- */
|
|
224
|
+
.page-content table {
|
|
225
|
+
width: 100%;
|
|
226
|
+
border-collapse: collapse;
|
|
227
|
+
margin: 1.2rem 0 2rem 0;
|
|
228
|
+
background: var(--bg-box);
|
|
229
|
+
border-radius: 10px;
|
|
230
|
+
overflow: hidden; /* ensures rounded corners clip */
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
.page-content th,
|
|
234
|
+
.page-content td {
|
|
235
|
+
padding: 0.6rem 0.8rem;
|
|
236
|
+
border: 1px solid #3a3a3a;
|
|
237
|
+
text-align: left;
|
|
238
|
+
vertical-align: top;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
.page-content th {
|
|
242
|
+
background: #2f2f2f;
|
|
243
|
+
color: var(--kaplay-yellow);
|
|
244
|
+
font-weight: 600;
|
|
245
|
+
font-size: 0.95rem;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
.page-content td {
|
|
249
|
+
color: var(--text-light);
|
|
250
|
+
font-size: 0.95rem;
|
|
251
|
+
}
|
package/docs/index.md
CHANGED
|
@@ -14,7 +14,7 @@ Perfect for menus, HUDs, mobile UI, prototypes, and small-to-medium games.
|
|
|
14
14
|
|
|
15
15
|
---
|
|
16
16
|
|
|
17
|
-
## 🚀 Why KAPLAY
|
|
17
|
+
## 🚀 Why KAPLAY-UI?
|
|
18
18
|
|
|
19
19
|
- 🧩 Works exactly like native KAPLAY
|
|
20
20
|
- 🎛️ Easy, declarative API
|
|
@@ -57,24 +57,24 @@ _**That’s it** — you’re ready to build UI!_
|
|
|
57
57
|
|
|
58
58
|
## 🧱 Core Components
|
|
59
59
|
|
|
60
|
-
### 🔤 Text Button
|
|
60
|
+
### 🔤 [Text Button](https://jbakchr.github.io/kaplay-ui/api/components#-textbutton)
|
|
61
61
|
|
|
62
62
|
Create an interactive button with centered text and built‑in outline & area detection.
|
|
63
63
|
|
|
64
64
|
```ts
|
|
65
65
|
const tb = k.addTextButton("Play");
|
|
66
66
|
|
|
67
|
-
tb.onClick(() =>
|
|
68
|
-
console.log("Let's play!");
|
|
69
|
-
});
|
|
67
|
+
tb.onClick(() => k.go("game"));
|
|
70
68
|
```
|
|
71
69
|
|
|
72
|
-
### 🏷️ Label
|
|
70
|
+
### 🏷️ [Label](https://jbakchr.github.io/kaplay-ui/api/components#-label)
|
|
73
71
|
|
|
74
72
|
A small, flexible text element — perfect for HUDs.
|
|
75
73
|
|
|
76
74
|
```ts
|
|
77
75
|
const lbl = k.addLabel("Score: 0");
|
|
76
|
+
|
|
77
|
+
lbl.setLabelText("Score: 1");
|
|
78
78
|
```
|
|
79
79
|
|
|
80
80
|
_More components are being added soon as the plugin grows._ 🎉
|
|
@@ -83,15 +83,27 @@ _More components are being added soon as the plugin grows._ 🎉
|
|
|
83
83
|
|
|
84
84
|
## 📚 Documentation
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
You can find more details here:
|
|
87
|
+
|
|
88
|
+
- [x] 🔌 **[plugin API](api/plugin)**
|
|
89
|
+
— _How the plugin integrates into KAPLAY_
|
|
90
|
+
|
|
91
|
+
- [x] 🧱 **[Components API](api/components)**
|
|
92
|
+
— _All UI components and their options_
|
|
93
|
+
|
|
94
|
+
- [x] 📄 **[faq.md](https://jbakchr.github.io/kaplay-ui/faq)**
|
|
95
|
+
— _Questions and answers_
|
|
96
|
+
|
|
97
|
+
_And soon also:_
|
|
98
|
+
|
|
99
|
+
- [ ] 🧪 **Examples**
|
|
100
|
+
— _Learn by doing!_
|
|
87
101
|
|
|
88
|
-
- [
|
|
89
|
-
|
|
90
|
-
- [ ] 🔘 **API Pages** — _The What & How?_
|
|
91
|
-
- [ ] 🧪 **Examples** — _Learn by doing!_
|
|
92
|
-
- [ ] 🪧 **Demos** — _See it in action .._
|
|
102
|
+
- [ ] 🪧 **Demos**
|
|
103
|
+
— _See it in action .._
|
|
93
104
|
|
|
94
|
-
|
|
105
|
+
- [ ] 🧠 **design-decisions**
|
|
106
|
+
— _The Whys?_
|
|
95
107
|
|
|
96
108
|
---
|
|
97
109
|
|