登录
首页 >  Golang >  Go问答

如何将 widget.NewMultiLineEntry() 滚动到底部?

来源:stackoverflow

时间:2024-02-07 10:15:11 327浏览 收藏

一分耕耘,一分收获!既然都打开这篇《如何将 widget.NewMultiLineEntry() 滚动到底部?》,就坚持看下去,学下去吧!本文主要会给大家讲到等等知识点,如果大家对本文有好的建议或者看到有不足之处,非常欢迎大家积极提出!在后续文章我会继续更新Golang相关的内容,希望对大家都有所帮助!

问题内容

我在 gui 应用程序中使用 widget.newmultilineentry() 来创建多行文本输入小部件。我正在寻找一种在添加新内容时自动或手动滚动到小部件底部的方法。我怎样才能实现这种行为?这可能吗?

logsBox := widget.NewMultiLineEntry()
logsBox.Wrapping = fyne.TextTruncate
logsBox.SetMinRowsVisible(3)
logsBox.SetPlaceHolder("Waiting for logs...")
logsBox.OnChanged = func(newMsg string) {
    // ...
}

logsBox.SetText("Row 1\nRow 2\nRow 3\nRow 4")
// TODO: Scroll to the bottom manually somehow?

正确答案


看起来我们可以使用 cursorrow 属性来解决这个问题:

focusedItem := logsWindow.Canvas().Focused()
// If the user is not focused on the text area then scroll to the end
if focusedItem == nil || focusedItem != logsBox {
    logsBox.CursorRow = len(logsBox.Text) - 1 // Sets the cursor to the end
}

文中关于的知识介绍,希望对你的学习有所帮助!若是受益匪浅,那就动动鼠标收藏这篇《如何将 widget.NewMultiLineEntry() 滚动到底部?》文章吧,也可关注golang学习网公众号了解相关技术文章。

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>