leafer-ui
leafer-ui copied to clipboard
修改 Text 元素的内容时,Text的宽度没有重新计算,导致获取Text的宽度还是初始化的时候的宽度
文本的宽度应该是主动设置了,需要设置一下text.width = undefined,才会变成自动宽度
文本的宽度应该是主动设置了,需要设置一下text.width = undefined,才会变成自动宽度
设置了,没有用,目前解决方法是,每次输入内容的时候 forceUpdate 一下才能解决
建议提供可以复现的示例代码,我们通过以下的例子测试不出来(可以正常更新文本的宽度):
import { App, Text } from 'leafer-ui'
import '@leafer-in/editor' // 导入图形编辑器插件
import '@leafer-in/viewport' // 导入视口插件(可选)
import '@leafer-in/text-editor' // 导入文本编辑插件
const app = new App({
view: window,
editor: {}
})
const text = Text.one({
text: 'Action is the proper fruit of knowledge.',
editable: true,
fill: '#FFE04B',
fontSize: 16,
autoSizeAlign: false,
textAlign: 'center'
}, 100, 100)
app.tree.add(text)
text.text += Math.round(text.width).toString()
setTimeout(()=>{
text.text += ' -- hello --'
text.text += Math.round(text.width).toString()
}, 2000)