Skip to content

Commit b669a0a

Browse files
authored
docs: A new font fot Jelly Slider percentage (#1871)
1 parent 299d0b8 commit b669a0a

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

apps/typegpu-docs/src/examples/rendering/jelly-slider/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ const bezierTexture = slider.bezierTexture.createView();
7575
const bezierBbox = slider.bbox;
7676

7777
const digitsProvider = new NumberProvider(root);
78+
await digitsProvider.fillAtlas();
7879
const digitsTextureView = digitsProvider.digitTextureAtlas.createView(
7980
d.texture2dArray(d.f32),
8081
);

apps/typegpu-docs/src/examples/rendering/jelly-slider/numbers.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,15 @@ export class NumberProvider {
2121
size: [PERCENTAGE_WIDTH, PERCENTAGE_HEIGHT, PERCENTAGE_COUNT],
2222
format: 'rgba8unorm',
2323
}).$usage('sampled', 'render');
24-
25-
this.#fillAtlas();
2624
}
2725

28-
#fillAtlas() {
26+
async fillAtlas() {
27+
// Ensure the font is loaded before drawing
28+
await Promise.all([
29+
document.fonts.load('180px "Reddit Mono"'),
30+
document.fonts.load('140px "JetBrains Mono"'),
31+
]);
32+
2933
const canvas = document.createElement('canvas');
3034
canvas.width = PERCENTAGE_WIDTH;
3135
canvas.height = PERCENTAGE_HEIGHT;
@@ -34,8 +38,8 @@ export class NumberProvider {
3438
throw new Error('Failed to get 2D context');
3539
}
3640

37-
ctx.font =
38-
'160px "SF Mono", "Monaco", "Consolas", "Liberation Mono", "Courier New", monospace';
41+
const regularFont = '180px "Reddit Mono", monospace';
42+
const percentageFont = '140px "JetBrains Mono", monospace';
3943
ctx.textAlign = 'right';
4044
ctx.textBaseline = 'middle';
4145
ctx.fillStyle = 'white';
@@ -45,11 +49,14 @@ export class NumberProvider {
4549
for (let i = 0; i <= 100; i++) {
4650
ctx.clearRect(0, 0, PERCENTAGE_WIDTH, PERCENTAGE_HEIGHT);
4751

48-
const text = `${i}%`;
4952
const x = PERCENTAGE_WIDTH - 20;
5053
const y = PERCENTAGE_HEIGHT / 2;
5154

52-
ctx.fillText(text, x, y);
55+
ctx.font = regularFont;
56+
ctx.fillText(`${i} `, x, y);
57+
58+
ctx.font = percentageFont;
59+
ctx.fillText(`%`, x, y + 10);
5360

5461
percentageImages.push(
5562
ctx.getImageData(0, 0, PERCENTAGE_WIDTH, PERCENTAGE_HEIGHT),

apps/typegpu-docs/src/layouts/PageLayout.astro

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ const { title, theme = 'light' } = Astro.props;
1212
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
1313
<link rel="icon" href="/TypeGPU/favicon.svg" />
1414
<link rel="sitemap" href="/TypeGPU/sitemap-index.xml" />
15+
<link rel="preconnect" href="https://fonts.googleapis.com">
16+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
17+
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono&family=Reddit+Mono&display=swap" rel="stylesheet">
1518
<script is:inline src="/TypeGPU/coi-serviceworker.js"></script>
1619
<style is:global>
1720
.bg-blurred-radial-purple {

0 commit comments

Comments
 (0)