From ca436b1fcdc27e304e2b98055954a30dfb7473d9 Mon Sep 17 00:00:00 2001 From: Hawtian Wang Date: Thu, 7 Dec 2023 23:38:34 +0800 Subject: [PATCH] ... --- src/graphics/widgets/text/text.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/graphics/widgets/text/text.ts b/src/graphics/widgets/text/text.ts index ceef1f86..e3efe066 100644 --- a/src/graphics/widgets/text/text.ts +++ b/src/graphics/widgets/text/text.ts @@ -1,7 +1,13 @@ import { BuildContext, Widget, _WidgetOption } from "@glib/widget"; import { AnyColor, Color, normalizeColor } from "../_utils"; import { FlexibleSize, PixelPosition } from "@glib/base"; -import { Box, InputItem, adjustmentRatios, breakLines } from "./line-break"; +import { + Box, + Glue, + InputItem, + adjustmentRatios, + breakLines, +} from "./line-break"; import { FontExtents } from "ht.clib.cairo"; import { info } from "@core/utils/logger"; @@ -201,8 +207,14 @@ class _Text extends Widget { p !== start && p !== breakpoints[b + 1] ) { - let te = context.renderer.ctx.text_extents(" "); - x += te.x_advance + te.x_advance * ratios[b]; + let item = inputItems[p] as Glue; + let gap; + if (ratios[b] < 0) { + gap = item.width + ratios[b] * item.shrink; + } else { + gap = item.width + ratios[b] * item.stretch; + } + x += gap; } } x = initPosition.x;