Auto adjust textbox width

This commit is contained in:
ckcz123 2018-12-07 16:08:21 +08:00
parent eba4aafbfd
commit 3155dcbfc5
2 changed files with 4 additions and 2 deletions

View File

@ -318,7 +318,7 @@ floorId指定的是目标楼层的唯一标识符ID
另外一点是V2.5.2以后,对话框`\b`可以根据文字长度来自动控制文本框宽度,其基本控制原理如下:
- 如果用户存在手动换行`\n`,则选取**最长的一段话**作为文本框宽度。
- 如果用户不存在手动换行,则会将文本框宽度调整为**尽量刚好达到三行**的最佳宽度。
- 如果用户不存在手动换行,则会将文本框宽度调整为X行半的最佳宽度。
- 文本框宽度存在上下界,最终宽度一定会控制在该范围内。
该自动调整仅对`\b`的对话框效果有效。非对话框仍然会绘制整个界面的宽度。

View File

@ -404,7 +404,9 @@ ui.prototype.calTextBoxWidth = function (canvas, content, min_width, max_width)
// 如果不存在手动换行,则二分自动换行
if (allLines.length == 1) {
var w = core.canvas[canvas].measureText(allLines[0]).width;
return core.clamp(w / 2.4, min_width, max_width);
if (w<min_width*2.3) return core.clamp(w / 1.4, min_width, max_width);
if (w<max_width*2.2) return core.clamp(w / 2.4, min_width, max_width);
return core.clamp(w / 3.4, min_width, max_width);
/*
var prefer_lines = 3;
var start = Math.floor(min_width), end = Math.floor(max_width);