forked from Blendman974/faceclaw
Refactor to remove some duplicated functiosn
This commit is contained in:
1 parent
797682a386
commit
205d393415
17 files changed
+57
-223
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import { getDefaultSmallFont, type BdfFont } from "../../graphics/bdffont";
|
||||
import { truncateText } from "../../graphics/textwrap";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { renderIcon, type IconName } from "../../graphics/icons";
|
||||
import { clamp } from "../../util/numeric-util";
|
||||
@@ -119,7 +120,7 @@ class LauncherGridLayer implements Layer {
|
||||
}
|
||||
const labelY = Math.round(blockTop + ICON_SIZE + LABEL_GAP);
|
||||
if (labelY + font.lineHeight <= gridBottom) {
|
||||
const label = truncate(font, app.label, colW - 8);
|
||||
const label = truncateText(font, app.label, colW - 8);
|
||||
image.drawText(font, Math.round(centerX - font.measureText(label) / 2), labelY, label, 210);
|
||||
}
|
||||
}
|
||||
@@ -196,12 +197,3 @@ export function createLauncherWindow(options: LauncherOptions): ShellWindow {
|
||||
setSurfaceVisible: options.setSurfaceVisible,
|
||||
}).window;
|
||||
}
|
||||
|
||||
function truncate(font: BdfFont, text: string, maxWidth: number): string {
|
||||
if (font.measureText(text) <= maxWidth) return text;
|
||||
let out = text;
|
||||
while (out.length > 1 && font.measureText(`${out}...`) > maxWidth) {
|
||||
out = out.slice(0, -1);
|
||||
}
|
||||
return `${out}...`;
|
||||
}
|
||||
Reference in new issue
Block a user