kaplay-ui 0.19.0 → 0.20.1
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 +38 -0
- package/inputs/index.js +41 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -114,6 +114,8 @@ A switch can take the following parameters:
|
|
|
114
114
|
| `width` | `number` | 50 | ❌ No | Switch width |
|
|
115
115
|
| `height` | `number` | 25 | ❌ No | Switch height |
|
|
116
116
|
|
|
117
|
+
<br>
|
|
118
|
+
|
|
117
119
|
#### Text Button
|
|
118
120
|
|
|
119
121
|
To make a text button, one must use the exported <code>makeTextButton()</code> function.
|
|
@@ -152,6 +154,42 @@ A text button can take the following parameters:
|
|
|
152
154
|
|
|
153
155
|
<br>
|
|
154
156
|
|
|
157
|
+
#### Text input
|
|
158
|
+
|
|
159
|
+
To make a toggle, one must use the exported <code>makeTextInput()</code> function.
|
|
160
|
+
|
|
161
|
+
##### Example
|
|
162
|
+
|
|
163
|
+
An example usage of a toggle.
|
|
164
|
+
|
|
165
|
+
```javascript
|
|
166
|
+
import kaplay from "kaplay";
|
|
167
|
+
import "kaplay/global";
|
|
168
|
+
|
|
169
|
+
import { makeTextInput } from "kaplay-ui/inputs";
|
|
170
|
+
|
|
171
|
+
kaplay();
|
|
172
|
+
|
|
173
|
+
const txtInput = makeTextInput();
|
|
174
|
+
|
|
175
|
+
add(txtInput);
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
##### Parameters
|
|
179
|
+
|
|
180
|
+
A text input can take the following parameters:
|
|
181
|
+
|
|
182
|
+
| Parameter | Type | Default | Required | Description |
|
|
183
|
+
| ---------- | --------- | ------- | -------- | ------------------------------ |
|
|
184
|
+
| `x` | `number` | 0 | ❌ No | x position |
|
|
185
|
+
| `y` | `number` | 0 | ❌ No | y position |
|
|
186
|
+
| `width` | `number` | 400 | ❌ No | width |
|
|
187
|
+
| `txtSize` | `number` | 15 | ❌ No | Input text size |
|
|
188
|
+
| `pad` | `number` | 10 | ❌ No | Padding |
|
|
189
|
+
| `hasFocus` | `boolean` | true | ❌ No | If text input has focus or not |
|
|
190
|
+
|
|
191
|
+
<br>
|
|
192
|
+
|
|
155
193
|
#### Toggle
|
|
156
194
|
|
|
157
195
|
To make a toggle, one must use the exported <code>makeToggle()</code> function.
|
package/inputs/index.js
CHANGED
|
@@ -133,7 +133,7 @@ export const makeCheckbox = (x = 0, y = 0, width = 25, height = 25) => {
|
|
|
133
133
|
};
|
|
134
134
|
|
|
135
135
|
/**
|
|
136
|
-
* Makes
|
|
136
|
+
* Makes switch
|
|
137
137
|
* @param {number} x - Switch x postion (default is 0)
|
|
138
138
|
* @param {number} y - Switch y postion (default is 0)
|
|
139
139
|
* @param {number} width - Switch width (default is 50)
|
|
@@ -184,3 +184,43 @@ export const makeSwitch = (x = 0, y = 0, width = 50, height = 25) => {
|
|
|
184
184
|
|
|
185
185
|
return switchBase;
|
|
186
186
|
};
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Makes text input
|
|
190
|
+
* @param {number} x - Text input x postion (default is 0)
|
|
191
|
+
* @param {number} y - Text input y postion (default is 0)
|
|
192
|
+
* @param {number} width - Text input width (default is 400)
|
|
193
|
+
* @param {number} txtSize - Text input text size (default is 15)
|
|
194
|
+
* @param {number} pad - Text input padding (default is 10)
|
|
195
|
+
* @param {boolean} hasFocus - Text input focus (default is true)
|
|
196
|
+
* @returns {GameObj}
|
|
197
|
+
*/
|
|
198
|
+
export const makeTextInput = (
|
|
199
|
+
x = 0,
|
|
200
|
+
y = 0,
|
|
201
|
+
width = 400,
|
|
202
|
+
txtSize = 15,
|
|
203
|
+
pad = 10,
|
|
204
|
+
hasFocus = true
|
|
205
|
+
) => {
|
|
206
|
+
// Text input container
|
|
207
|
+
const inputBase = make([
|
|
208
|
+
rect(width, txtSize + pad * 2),
|
|
209
|
+
pos(x, y),
|
|
210
|
+
area(),
|
|
211
|
+
outline(1),
|
|
212
|
+
]);
|
|
213
|
+
|
|
214
|
+
// Text input
|
|
215
|
+
const input = make([
|
|
216
|
+
text("", { width: width - pad * 2, size: txtSize }),
|
|
217
|
+
textInput(hasFocus),
|
|
218
|
+
color(BLACK),
|
|
219
|
+
pos(pad, pad),
|
|
220
|
+
area(),
|
|
221
|
+
]);
|
|
222
|
+
|
|
223
|
+
inputBase.add(input);
|
|
224
|
+
|
|
225
|
+
return inputBase;
|
|
226
|
+
};
|