fix(image-annotate): v1.9.1 文字输入框贴住点击点、选区图标归位、底色一选就生效
1) 输入框偏到左上:showTextInput 用 canvasStack 的矩形换算,但 stack 尺寸是
(imgW + 2*overlayPad)*scale、图片在 stack 内还偏移 pad*scale(图层 canvas 的
left/top)。比例偏小又漏偏移,两个误差同向叠加。改用 textCanvas 的矩形
(与图层 canvas 同基准,精确等于图片显示区域),并按 textarea 的边框 2px +
内边距 8/4px 反向偏移,让输入框里的文字起点正压在点击点上;提交后
drawTextObject 也从 t.x/t.y 起画,所见即所得。
2) 选「选择」工具后三个选区图标不见了:两处叠加。
- selCmdHTML 排在 hint 之后,而 .iwb-opt-hint 带 margin-left:auto;
- 更关键的是 .iwb-opt-sep 写成 margin: 0 4px 0 auto,分隔线自带 auto,
会把分隔线之后的内容整组推到最右,选项栏排满时直接滚出可视区。
修法:分隔线只分组(margin: 0 2px),留白交给末尾 hint;选区按钮排在 hint 之前。
现在「文字」「选择」两个工具下都是同一组三个图标,未选中元素时也在。
3) 设了底色看不到:底色一直在画,只是「只改颜色没点开关」时 bgFill 仍是 false。
- 改 bgColor 时自动打开 bgFill,按钮 active 同步;
- 顺带修掉更硬的 bug:「底色」按钮只能开不能关 —— data-value 在生成 HTML 时
写死,状态变了没人更新,每次点都传「开启」。改由 syncOptionBar 按当前状态翻面;
- 默认底色透明度 0.55 → 0.68(浅色/花色底图上 0.55 太透,容易被当成没生效)。
harness 158 → 162 条全通(新增输入框落点误差 ≤3px、Esc 不留空对象、
选择工具未选中仍有 3 个图标、只选颜色即自动开底色);validate 9/9。
This commit is contained in:
1 parent
e699c22fa0
commit
73a29715d3
9 files changed
+169
-28
No files matched your search
@@ -589,12 +589,20 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
||||
// ============ 文字输入框 ============
|
||||
export function showTextInput(x, y, layer) {
|
||||
const input = runtime.el.querySelector('.iwb-editor-text-input')
|
||||
const rect = S.canvasStack.getBoundingClientRect()
|
||||
const wrapRect = S.canvasWrap.getBoundingClientRect()
|
||||
const sx = rect.width / S.imgW
|
||||
const sy = rect.height / S.imgH
|
||||
input.style.left = (rect.left - wrapRect.left + x * sx) + 'px'
|
||||
input.style.top = (rect.top - wrapRect.top + y * sy) + 'px'
|
||||
// 不能用 canvasStack 的矩形换算:stack 的尺寸是 (imgW + 2*overlayPad) * scale,
|
||||
// 图片在 stack 内部还额外偏移了 pad*scale(图层 canvas 的 left/top)。
|
||||
// 拿它算比例会偏小、又漏掉这段偏移,输入框就整体跑到点击点的左上方。
|
||||
// textCanvas 与图层 canvas 同基准,矩形精确等于「图片显示区域」。
|
||||
const box = (S.textCanvas || S.canvasStack).getBoundingClientRect()
|
||||
const sx = S.imgW ? box.width / S.imgW : 1
|
||||
const sy = S.imgH ? box.height / S.imgH : 1
|
||||
// textarea 有 2px 边框 + 8/4px 内边距,反向抵消后「输入框里的字起点」正压在点击点上,
|
||||
// 与提交后 drawTextObject 从 t.x/t.y 起画的位置完全一致(所见即所得)。
|
||||
const INSET_X = 10
|
||||
const INSET_Y = 6
|
||||
input.style.left = (box.left - wrapRect.left + x * sx - INSET_X) + 'px'
|
||||
input.style.top = (box.top - wrapRect.top + y * sy - INSET_Y) + 'px'
|
||||
input.style.display = 'block'
|
||||
if (layer) {
|
||||
input.value = layer.text
|
||||
|
||||
Reference in new issue
Block a user