Skip to content

Commit a17098d

Browse files
committed
Button increment.
1 parent f2dbe7a commit a17098d

File tree

11 files changed

+147
-21
lines changed

11 files changed

+147
-21
lines changed

src/components/pg/button/button.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ export default class PgButton extends HTMLElement {
1919
@Prop(normalizeBoolean) end: boolean = false;
2020

2121
@Part() $button: HTMLButtonElement;
22-
@Part() $number: HTMLSpanElement;
23-
@Part() $bar: HTMLSpanElement;
2422

2523
connectedCallback() {
2624
this.$button.addEventListener('click', (e) => {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# `<pg-button-increment>`
2+
3+
The `pg-button-increment` is the `pg-button` component with an increment event for holding down.
4+
5+
```typescript
6+
import '@pictogrammers/components/pg/buttonIncrement';
7+
import PgButtonIncrement from '@pictogrammers/components/pg/buttonIncrement';
8+
```
9+
10+
## Usage
11+
12+
```typescript
13+
this.$button.incrementDelay = 300; // default
14+
this.$button.incrementStepDelay = 50; // default
15+
this.$button.addEventListener('increment', () => {
16+
// called on initial click and after every 50ms
17+
});
18+
```
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.example-flex {
2+
display: flex;
3+
gap: 0.5rem;
4+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<div class="example">
2+
<div class="example-flex">
3+
<pg-button-increment part="button1">
4+
<pg-icon path="M12,19.2C9.5,19.2 7.29,17.92 6,16C6.03,14 10,12.9 12,12.9C14,12.9 17.97,14 18,16C16.71,17.92 14.5,19.2 12,19.2M12,5A3,3 0 0,1 15,8A3,3 0 0,1 12,11A3,3 0 0,1 9,8A3,3 0 0,1 12,5M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12C22,6.47 17.5,2 12,2Z"></pg-icon>
5+
Clicked <span part="count1">0</span> Times
6+
</pg-button-increment>
7+
<pg-button-increment part="button2">
8+
<pg-icon path="M12,19.2C9.5,19.2 7.29,17.92 6,16C6.03,14 10,12.9 12,12.9C14,12.9 17.97,14 18,16C16.71,17.92 14.5,19.2 12,19.2M12,5A3,3 0 0,1 15,8A3,3 0 0,1 12,11A3,3 0 0,1 9,8A3,3 0 0,1 12,5M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12C22,6.47 17.5,2 12,2Z"></pg-icon>
9+
Clicked <span part="count2">0</span> Times, incrementStepDelay = 100
10+
</pg-button-increment>
11+
</div>
12+
</div>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { Component, Part } from '@pictogrammers/element';
2+
import PgButtonIncrement from '../../buttonIncrement';
3+
4+
import style from './basic.css';
5+
import template from './basic.html';
6+
7+
@Component({
8+
selector: 'x-pg-button-increment-basic',
9+
style,
10+
template,
11+
})
12+
export default class XPgButtonBasic extends HTMLElement {
13+
@Part() $button1: PgButtonIncrement;
14+
@Part() $count1: HTMLSpanElement;
15+
@Part() $button2: PgButtonIncrement;
16+
@Part() $count2: HTMLSpanElement;
17+
18+
connectedCallback() {
19+
this.$button1.addEventListener('increment', () => {
20+
const count = parseInt(this.$count1.textContent, 10);
21+
this.$count1.textContent = `${count + 1}`;
22+
});
23+
this.$button2.incrementStepDelay = 100;
24+
this.$button2.addEventListener('increment', () => {
25+
const count = parseInt(this.$count2.textContent, 10);
26+
this.$count2.textContent = `${count + 1}`;
27+
});
28+
}
29+
}

src/components/pg/buttonIncrement/buttonIncrement.css

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<parent />
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { Component, normalizeInt, Part, Prop } from '@pictogrammers/element';
2+
3+
import template from './buttonIncrement.html';
4+
import style from './buttonIncrement.css';
5+
import PgButton from '../button/button';
6+
7+
var timeout, interval;
8+
9+
function clearTimers() {
10+
clearTimeout(timeout);
11+
clearInterval(interval);
12+
}
13+
14+
@Component({
15+
selector: 'pg-button-increment',
16+
style,
17+
template
18+
})
19+
export default class PgButtonIncrement extends PgButton {
20+
@Prop(normalizeInt) incrementDelay = 300;
21+
@Prop(normalizeInt) incrementStepDelay = 50;
22+
23+
connectedCallback() {
24+
super.connectedCallback();
25+
this.$button.addEventListener('pointerdown', () => {
26+
const targetId = this.dataset.target;
27+
28+
this.dispatchEvent(new CustomEvent('increment'));
29+
30+
timeout = setTimeout(() => {
31+
interval = setInterval(() => {
32+
this.dispatchEvent(new CustomEvent('increment'));
33+
}, this.incrementStepDelay);
34+
}, this.incrementDelay);
35+
});
36+
this.$button.addEventListener('pointerup', clearTimers);
37+
this.$button.addEventListener('pointerleave', clearTimers);
38+
}
39+
40+
render(changes) {
41+
if (changes.incrementStepDelay) {
42+
console.log(this.incrementStepDelay, '<<<<');
43+
}
44+
}
45+
}

src/components/pg/inputPixelEditor/README.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -318,12 +318,12 @@ An example of a 9 segment grid for instance. Negative values offset from the rig
318318
{
319319
"grid": [{
320320
"vertical": [
321-
{ "start": 10, "color": 0 },
322-
{ "start": -10, "color": 0 }
321+
{ "offset": 10, "color": 0 },
322+
{ "offset": -10, "color": 0 }
323323
],
324324
"horizontal": [
325-
{ "start": 10, "color": 0 },
326-
{ "start": -10, "color": 0 }
325+
{ "offset": 10, "color": 0 },
326+
{ "offset": -10, "color": 0 }
327327
]
328328
}]
329329
}
@@ -340,13 +340,20 @@ Specific grid colors are configured on the editor level and do not persist in th
340340
### Repeating Grids
341341

342342
A repeating grid is useful for tilesets and can be represented as.
343-
- `start` can be optional or null when `step` is defined.
343+
- `offset` can be optional or null when `step` is defined.
344344
- `limit` can be optional or null. Null repeats for as many times as it can fit.
345345
- Similar to regular grids an error will throw if the first line is outside the `width` or `height`.
346346

347+
To create a repeating 20 pixel grid without an offset.
348+
349+
```json
350+
{ "step": 20, "color": 0 },
351+
```
352+
353+
To create a repeating 10 pixel grid with an offset `5` and limit `10`. The use case of this would be comps where a tileset does not evently sit in a viewport and needs to be centered.
354+
347355
```json
348-
{ "step": 10, "limit": null, "color": 0 },
349-
{ "start": 5, "step": 10, "limit": 10, "color": 0 },
356+
{ "offset": 5, "step": 10, "limit": 10, "color": 0 },
350357
```
351358

352359
## Export

src/components/pg/inputPixelEditor/utils/inputMode.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export const enum InputMode {
66
SelectMagicWand,
77
Stamp,
88
Pixel,
9+
Erase,
910
Line,
1011
Rectangle,
1112
RectangleOutline,

0 commit comments

Comments
 (0)