How to expand MultilineEntry vertically? #6077
-
|
Is there a natural way to have the MultilineEntry widget expand vertically to occupy the rest of the vertical space rather than staying with a few lines? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 5 replies
-
|
Widgets expand to fill the available space. Try calling Resize() on the dialog to give it more space. |
Beta Was this translation helpful? Give feedback.
-
|
I create my modal object this way: modal := NewModalEditor(g.w, "My title", "initial text", false)
modal.OnAccept = func(s string) {
println("Accepted", s)
}
modal.Resize(fyne.NewSize(380, 600))
modal.Show()I encapsulated the dialog this way: import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/widget"
)
type ModalEditor struct {
isReadOnly bool
isDismissed bool
modal *dialog.CustomDialog
// Callback when Accept button is pressed on an editable modal
OnAccept func(string)
}
func NewModalEditor(w fyne.Window, title, text string, readOnly bool) *ModalEditor {
me := &ModalEditor{
isReadOnly: readOnly,
isDismissed: false,
}
me.build(w, title, text)
return me
}
func (me *ModalEditor) Show() {
me.modal.Show()
}
func (me *ModalEditor) Resize(size fyne.Size) {
me.modal.Resize(size)
}
// build up the modal window containing the multi-line text box and
// the Accept & Cancel buttons at the bottom.
func (me *ModalEditor) build(w fyne.Window, title, initialText string) {
var dataWidget fyne.CanvasObject
var rtb *widget.RichText = nil
var mle *widget.Entry = nil
if me.isReadOnly {
rtb = widget.NewRichTextWithText(initialText)
dataWidget = rtb
} else {
mle = widget.NewMultiLineEntry()
mle.MultiLine = true
mle.PlaceHolder = "Edit your text here..."
mle.Text = initialText
mle.Wrapping = fyne.TextWrapOff
dataWidget = mle
}
// · The "Accept" button notifies the parent window of the
// new text value provided OnAccept has been set. This only
// happens if the modal is not read-only. The modal is dismissed.
var modal *dialog.CustomDialog
buttonAccept := widget.NewButton("Accept", func() {
if !me.isReadOnly {
println("Accepted", mle.Text)
// pass back the new text
if me.OnAccept != nil {
me.OnAccept(mle.Text)
}
} else {
println("Accepted", rtb.String())
}
me.isDismissed = true
modal.Dismiss()
})
// · The "Cancel" button indicates the user wants to discard any
// text modification. The modal window is dismissed.
buttonCancel := widget.NewButton("Cancel", func() {
me.isDismissed = true
modal.Dismiss()
})
editorContainer := container.NewBorder(nil, dataWidget, nil, nil)
modal = dialog.NewCustom(title, "", editorContainer, w)
modal.SetButtons([]fyne.CanvasObject{buttonAccept, buttonCancel})
me.modal = modal
} |
Beta Was this translation helpful? Give feedback.
-
|
This line:
Is squashing the item to the bottom of a border container - and you didn't mention an intermediate container in your description. |
Beta Was this translation helpful? Give feedback.
-
|
Following this I used my same code (BTW there is no intermediate container in the sample I posted), but I changed the editorContainer := container.NewBorder(nil,nil,nil,nil,dataWidget)And now it displays as desired. |
Beta Was this translation helpful? Give feedback.
Following this I used my same code (BTW there is no intermediate container in the sample I posted), but I changed the
editorContainerbto look like this:And now it displays as desired.