Skip to content

Commit 2c5a2ad

Browse files
committed
Cleanup
1 parent 4d5b724 commit 2c5a2ad

File tree

3 files changed

+44
-6
lines changed

3 files changed

+44
-6
lines changed

src/pg/inputPixelEditor/README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import { PgInputPixelEditor } from '@pictogrammers/components/pgInputPixelEditor
1616
| Attributes | Tested | Description |
1717
| ----------- | -------- | ----------- |
1818
| name | | Unique name in `pg-form` |
19-
| value | | Field value |
2019
| width | | Pixel width. Default `10` |
2120
| height | | Pixel height. Default `10` |
2221
| size | | Pixel size, minimum value `4`. Default `10` |
@@ -28,3 +27,25 @@ import { PgInputPixelEditor } from '@pictogrammers/components/pgInputPixelEditor
2827
| ---------- | -------- | ----------- |
2928
| change | | `{ detail: { value }` |
3029
| input | | `{ detail: { value }` |
30+
31+
## Methods
32+
33+
See usage for each method below.
34+
35+
| Method | Tested | Description |
36+
| ---------- | -------- | ----------- |
37+
| `save(callback, options)` | - | Save file. |
38+
| `open(file, callback)` | - | Open file. |
39+
| undo() | - | Undo. |
40+
| hasUndo() | - | Has undo |
41+
| hasRedo() | - | Has redo |
42+
| redo() | - | Redo. |
43+
| selectLayer() | - | |
44+
| getLayers() | - | Get layer array. |
45+
| addLayer(option) | - | Add layer. |
46+
| removeLayer(index) | - | Remove layer. |
47+
| rotateClockwise() | - | Rotate. |
48+
| rotateCounterclockwise() | - | Rotate. |
49+
| move(x, y[, layer]) | - | Move canvas. |
50+
| flipHorizontal() |
51+
| flipVertical() |

src/pg/inputPixelEditor/__examples__/basic/basic.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
<div class="props">
33
<label>
44
Width
5-
<input part="width" type="range" min="10" max="22">
5+
<input part="width" type="range" min="4" max="22">
66
</label>
77
<label>
88
Height
9-
<input part="height" type="range" min="10" max="22">
9+
<input part="height" type="range" min="4" max="22">
1010
</label>
1111
<label>
1212
Size

src/pg/inputPixelEditor/inputPixelEditor.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,14 @@ export default class PgInputPixelEditor extends HTMLElement {
341341

342342
handleKeyDown(event: KeyboardEvent) {
343343
console.log(event.shiftKey, event.ctrlKey, event.altKey, event.key);
344-
if (event.key === ' ') {
345-
console.log('space!')
344+
switch(event.key) {
345+
case ' ':
346+
console.log('space');
347+
break;
348+
case 'Escape':
349+
console.log('escape');
350+
// Cancel editing
351+
break;
346352
}
347353
}
348354

@@ -590,6 +596,7 @@ export default class PgInputPixelEditor extends HTMLElement {
590596
});
591597
this.#data[this.#layer] = cloned;
592598
}
599+
593600
flipVertical() {
594601
const cloned = cloneGrid(this.#data[this.#layer]);
595602
const h = cloned.length - 1;
@@ -598,6 +605,7 @@ export default class PgInputPixelEditor extends HTMLElement {
598605
});
599606
this.#data[this.#layer] = cloned;
600607
}
608+
601609
move(translateX: number, translateY: number) {
602610
const cloned = fillGrid(this.width, this.height);
603611
for (let iy = 0; iy < this.height; iy++) {
@@ -658,7 +666,16 @@ export default class PgInputPixelEditor extends HTMLElement {
658666
// redraw canvas
659667
});*/
660668
}
661-
rotate(counterClockwise: boolean = false) {
669+
670+
rotateClockwise() {
671+
this.#rotate(false);
672+
}
673+
674+
rotateCounterclockwise() {
675+
this.#rotate(true);
676+
}
677+
678+
#rotate(counterClockwise: boolean = false) {
662679
const cloned = cloneGrid(this.#data[this.#layer]);
663680
if (counterClockwise) {
664681
const newData = this.#data[0].map((val, index) => this.#data.map(row => row[row.length - 1 - index]));

0 commit comments

Comments
 (0)