1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-27 07:03:14 -04:00

Improve text layout

This commit is contained in:
Emil Ernerfeldt
2018-12-27 23:55:16 +01:00
parent a4fc56b441
commit 1c6fd220b2
7 changed files with 80 additions and 134 deletions

Binary file not shown.

View File

@@ -63,8 +63,7 @@ function paint_command(canvas, cmd) {
case "text":
ctx.fillStyle = styleFromColor(cmd.fill_color);
ctx.font = cmd.font_size + "px " + cmd.font_name;
ctx.textAlign = cmd.text_align;
ctx.textBaseline = "top";
ctx.textBaseline = "middle";
ctx.fillText(cmd.text, cmd.pos.x, cmd.pos.y);
return;
}

View File

@@ -56,7 +56,6 @@ interface Text {
pos: Vec2;
stroke_color: Color | null;
text: string;
text_align: "start" | "center" | "end";
}
type PaintCmd = Circle | Clear | Line | Rect | Text;
@@ -132,8 +131,7 @@ function paint_command(canvas, cmd: PaintCmd) {
case "text":
ctx.fillStyle = styleFromColor(cmd.fill_color);
ctx.font = `${cmd.font_size}px ${cmd.font_name}`;
ctx.textAlign = cmd.text_align;
ctx.textBaseline = "top";
ctx.textBaseline = "middle";
ctx.fillText(cmd.text, cmd.pos.x, cmd.pos.y);
return;
}