Skip to content

Commit 89f9da3

Browse files
committed
feat(lcd1602): screen only render mode
Useful for taking screen shots during automated tests
1 parent e9aa3a7 commit 89f9da3

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

src/lcd1602-element.stories.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ interface LCD1602Args {
1616
cursorY: number;
1717
pins: string;
1818
text: string;
19+
screenOnly: boolean;
1920
}
2021

2122
const meta: Meta<LCD1602Args> = {
@@ -31,6 +32,7 @@ const meta: Meta<LCD1602Args> = {
3132
color: 'black',
3233
cursor: false,
3334
pins: 'full',
35+
screenOnly: false,
3436
} satisfies LCD1602Args,
3537
parameters: {
3638
docs: {
@@ -55,6 +57,7 @@ const Template = (args: LCD1602Args) => html`
5557
.color=${args.color}
5658
.background=${args.background}
5759
.pins=${args.pins}
60+
.screenOnly=${args.screenOnly}
5861
></wokwi-lcd1602>
5962
`;
6063

@@ -119,3 +122,9 @@ NoPins.args = {
119122
text: 'Look ma! I got no pins',
120123
pins: 'none',
121124
};
125+
126+
export const ScreenOnly: Story = Template.bind({});
127+
ScreenOnly.args = {
128+
text: 'Screen Only',
129+
screenOnly: true,
130+
};

src/lcd1602-element.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export class LCD1602Element extends LitElement {
2424
@property() cursorY = 0;
2525
@property() backlight = true;
2626
@property() pins: 'full' | 'i2c' | 'none' = 'full';
27+
@property() screenOnly = false;
2728

2829
protected numCols = 16;
2930
protected numRows = 2;
@@ -221,8 +222,14 @@ export class LCD1602Element extends LitElement {
221222
background in backgroundColors ? backgroundColors[background] : backgroundColors;
222223

223224
const panelWidth = cols * 3.5125;
224-
const width = panelWidth + 23.8;
225-
const height = panelHeight + 24.5;
225+
const width = this.screenOnly ? panelWidth : panelWidth + 23.8;
226+
const height = this.screenOnly ? panelHeight : panelHeight + 24.5;
227+
228+
const panelX = 12.45;
229+
const panelY = 12.55;
230+
const viewBox = this.screenOnly
231+
? `${panelX} ${panelY} ${panelWidth} ${panelHeight}`
232+
: `0 0 ${width} ${height}`;
226233

227234
// Dimensions according to:
228235
// https://www.winstar.com.tw/products/character-lcd-display-module/16x2-lcd.html
@@ -231,7 +238,7 @@ export class LCD1602Element extends LitElement {
231238
width="${width}mm"
232239
height="${height}mm"
233240
version="1.1"
234-
viewBox="0 0 ${width} ${height}"
241+
viewBox="${viewBox}"
235242
style="font-size: 1.5px; font-family: monospace"
236243
xmlns="http://www.w3.org/2000/svg"
237244
>
@@ -277,13 +284,17 @@ export class LCD1602Element extends LitElement {
277284
${pins === 'i2c' ? this.renderI2CPins() : null}
278285
${pins === 'full' ? this.renderPins(panelHeight) : null}
279286
<rect
280-
x="12.45"
281-
y="12.55"
287+
x="${panelX}"
288+
y="${panelY}"
282289
width="${panelWidth}"
283290
height="${panelHeight}"
284291
fill="url(#characters)"
285292
/>
286-
<path d="${this.path(characters)}" transform="translate(12.45, 12.55)" fill="${color}" />
293+
<path
294+
d="${this.path(characters)}"
295+
transform="translate(${panelX}, ${panelY})"
296+
fill="${color}"
297+
/>
287298
${this.renderCursor()}
288299
</svg>
289300
`;

src/lcd2004-element.stories.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ export const BlueBackground = () =>
2020
export const I2cPins = () =>
2121
html`<wokwi-lcd2004 pins="i2c" text="I²C Pins" .font=${fontA02}></wokwi-lcd2004>`;
2222
I2cPins.storyName = 'I2C Pins';
23+
24+
export const ScreenOnly = () =>
25+
html`<wokwi-lcd2004 .screenOnly=${true} text="Screen Only"></wokwi-lcd2004>`;

0 commit comments

Comments
 (0)