fyne的几种multiLine

fyne的几种multiLine

创建一个MultiLine有一个专门的函数:

widget.NewMultiLineEntry()

进入方法看看源码:

// NewMultiLineEntry creates a new entry that allows multiple lines
func NewMultiLineEntry() *Entry {
	e := &Entry{MultiLine: true, Wrapping: fyne.TextTruncate}
	e.ExtendBaseWidget(e)
	return e
}

可以看到实际上返回的还是Entry,只不过是将MultiLine变量设置为了true,然后有一个wrapping变量。

这样我们可以自己设置wrapping的值。

wrappings是一个TextWrap类型,代表了长度超过widget宽度的文本将如何换行。

type TextWrap int

wrapping有如下几个值:

const (
	// TextWrapOff extends the widget's width to fit the text, no wrapping is applied.
    // 暂时不考虑这个值
	TextWrapOff TextWrap = iota
	// TextTruncate trims the text to the widget's width, no wrapping is applied.
	// If an entry is asked to truncate it will provide scrolling capabilities.
	//
	// Deprecated: Use `TextTruncateClip` value of the widget `Truncation` field instead
    // 不换行,会产生滚动条,已废弃
	TextTruncate
	// TextWrapBreak trims the line of characters to the widget's width adding the excess as new line.
	// An Entry with text wrapping will scroll vertically if there is not enough space for all the text.
    // 换行,如果空间不够,产生垂直滚动条
	TextWrapBreak
	// TextWrapWord trims the line of words to the widget's width adding the excess as new line.
	// An Entry with text wrapping will scroll vertically if there is not enough space for all the text.
    // 单词是一个整体换行
	TextWrapWord
)

代码:

package main

import (
	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/widget"
)

func main() {
	a := app.New()
	w := a.NewWindow("Base64 Encoder / Decoder")
	w.SetContent(makeUI())
	w.Resize(fyne.NewSize(400, 300))
	w.CenterOnScreen()
	w.ShowAndRun()
}

func makeUI() fyne.CanvasObject {

	text1 := widget.NewMultiLineEntry()
	text1.SetPlaceHolder("text1")

	text2 := widget.NewEntry()
	text2.MultiLine = true
	text2.Wrapping = fyne.TextWrapBreak
	text2.SetPlaceHolder("text2")

	text3 := widget.NewEntry()
	text3.MultiLine = true
	text3.Wrapping = fyne.TextWrapWord
	text3.SetPlaceHolder("text3")

	return container.NewVBox(text1, text2, text3)
}

在这里插入图片描述

第一个未换行,第二个换行了,但是单词不是一个整体,第三个是单词整体换行。

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

shulu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值