Repository navigation
fix(base): keep a text that fits exactly when float32 rounding falls short - #77
Closed
xiaoyumuxi wants to merge 1 commit into
Closed
xiaoyumuxi wants to merge 1 commit into
xiaoyumuxi wants to merge 1 commit into
Conversation
…short A row placed at the width it measured sums the same sizes again when it shares them out, in another order, and float32 can leave it a few ulps short. solveFlow took that shortfall from the children that shrink, so an ellipsized label that fit exactly lost an ulp and was cut to an ellipsis (about one label width in eleven). A shortfall within float32 rounding of the container's size is now no shortfall, and a text's fit check sums its padding the way its preferred width did.
This was referenced Nov 28, 2026
Author
|
上游已以 vivaui#507(a3eda457)合入,并多处理了容器与排版方向垂直时的取整误差;#78 把它同步进 fork main(7a73f1ba),关闭。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
关联:上游 PR vivaui#507(同一改动,基于上游
mainb036c88;本 PR 基于 forkmain1247fbd)改了什么
一个容器按它自己测出来的宽度排版时,放得下的文字不再被截成省略号。
base/layout.gosolveFlow:剩余空间free为负,但不超过 float32 对容器尺寸的舍入误差(新函数roundingSlack:每项按容器尺寸的 2 个 ulp 计)时,按 0 处理,不再从可收缩的子节点里扣。n.Natural+n.PadX() <= n.Rect.Width,和测量首选宽度的加法一致;原来先减内边距再比,带内边距的文字会差一个 ulp。base/flex_test.go:新增TestARowAtItsMeasuredWidthKeepsAnEllipsizedLabelWhole,2000 种字宽 × 内边距 0 / 3,要求刚好放得下的“High”完整显示。为什么
首选宽度和
solveFlow分配空间时按不同顺序把同样的尺寸加了两遍,float32 下free会差几个 ulp 变成负数,被从可收缩的文字上扣掉,精确的放得下判断随即判定放不下,显示省略号。大约每 11 个字宽就有一个会被截。Lithe 的 Agent 输入框底部,推理等级胶囊“High”因此显示成“Hi…”。修复前新测试输出:
怎么验证的
macOS 27.3(Apple Silicon)、go1.27.4:
gofmt -l .:没有输出go vet ./...:没有 vet 报告(只有 cgo 的 Metal 弃用警告)go test ./... -count=1(在上游分支上跑):除两类既有失败外全部通过,两类都在不带本改动的 b036c88 上一样出现:ui/inputnumber、internal/gallery、internal/componentdemo的暖绘制零分配测试:go1.27 下strconv.FormatFloat会分配,go1.26.0 下通过,上游 Issue ui/inputnumber:Go 1.27 下暖绘制每帧分配一次(decimals 里的 strconv.FormatFloat) vivaui/viva#506cmd/viva打包测试:本机部署目标和测试的min_system不一致,属于环境问题TestVisualAgents(-tags 'vivahead lithevisual'):编辑区标签页的“High”胶囊完整显示,浅色、深色一致边界在哪
框架缺陷修复,和具体应用无关。
Cost
没有。只在
free < 0时多一次乘法和比较,没有新增分配。