Skip to content

Commit 40f38f8

Browse files
committed
feat(ili9341): flip support (horizontal/vertical)
1 parent 60e66af commit 40f38f8

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

src/ili9341-element.stories.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ import './ili9341-element';
55
export default {
66
title: 'ILI9341',
77
component: 'wokwi-ili9341',
8+
argTypes: {
9+
flipHorizontal: { control: { type: 'boolean' } },
10+
flipVertical: { control: { type: 'boolean' } },
11+
},
12+
args: {
13+
flipHorizontal: false,
14+
flipVertical: false,
15+
},
816
};
917

1018
function drawLogo(canvas: HTMLCanvasElement) {
@@ -21,5 +29,11 @@ function drawLogo(canvas: HTMLCanvasElement) {
2129

2230
export const Default = () => html` <wokwi-ili9341></wokwi-ili9341> `;
2331

24-
export const Logo = () =>
25-
html` <wokwi-ili9341 @canvas-ready=${(e) => drawLogo(e.target.canvas)}></wokwi-ili9341> `;
32+
export const Logo = ({ flipHorizontal, flipVertical }) =>
33+
html`
34+
<wokwi-ili9341
35+
@canvas-ready=${(e) => drawLogo(e.target.canvas)}
36+
.flipHorizontal=${flipHorizontal}
37+
.flipVertical=${flipVertical}
38+
></wokwi-ili9341>
39+
`;

src/ili9341-element.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import { css, html, LitElement } from 'lit';
2-
import { customElement } from 'lit/decorators.js';
2+
import { customElement, property } from 'lit/decorators.js';
33
import { ElementPin, spi } from './pin';
44

55
@customElement('wokwi-ili9341')
66
export class ILI9341Element extends LitElement {
77
readonly screenWidth = 240;
88
readonly screenHeight = 320;
99

10+
@property() flipHorizontal = false;
11+
@property() flipVertical = false;
12+
1013
readonly pinInfo: ElementPin[] = [
1114
{ name: 'VCC', x: 48.3, y: 287.2, signals: [{ type: 'power', signal: 'VCC' }] },
1215
{ name: 'GND', x: 57.9012, y: 287.2, signals: [{ type: 'power', signal: 'GND' }] },
@@ -49,7 +52,11 @@ export class ILI9341Element extends LitElement {
4952
}
5053

5154
render() {
52-
const { screenWidth, screenHeight } = this;
55+
const { screenWidth, screenHeight, flipHorizontal, flipVertical } = this;
56+
const flip = flipHorizontal || flipVertical;
57+
const scaleX = flipHorizontal ? -1 : 1;
58+
const scaleY = flipVertical ? -1 : 1;
59+
const canvasStyle = flip ? `transform: scaleX(${scaleX}) scaleY(${scaleY});` : '';
5360
return html`
5461
<div class="container">
5562
<svg
@@ -112,7 +119,12 @@ export class ILI9341Element extends LitElement {
112119
<tspan x="14.2" y="4.3" font-size="4.6px">ILI9341</tspan>
113120
</text>
114121
</svg>
115-
<canvas width="${screenWidth}" height="${screenHeight}" class="pixelated"></canvas>
122+
<canvas
123+
width="${screenWidth}"
124+
height="${screenHeight}"
125+
class="pixelated"
126+
style=${canvasStyle}
127+
></canvas>
116128
</div>
117129
`;
118130
}

0 commit comments

Comments
 (0)