Skip to content

Commit

Permalink
Updates Entry widget minimum size computation
Browse files Browse the repository at this point in the history
This PR updates the entry widget minimum size computation using the widget.MinSize that ensure to have the correct padding.
Fixes #81
  • Loading branch information
lucor authored and andydotxyz committed Jan 15, 2019
1 parent 6317aca commit 3fe3b61
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
15 changes: 5 additions & 10 deletions widget/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,19 @@ type entryRenderer struct {
// This is based on the contained text with a standard amount of padding added.
// If MultiLine is true then we will reserve space for at leasts 3 lines
func (e *entryRenderer) MinSize() fyne.Size {
minTextSize := e.text.charMinSize()
textSize := minTextSize

if e.placeholder.len() > 0 {
textSize = e.placeholder.MinSize()
}
minSize := e.placeholder.MinSize()

if e.text.len() > 0 {
textSize = e.text.MinSize()
minSize = e.text.MinSize()
}

if e.entry.MultiLine == true {
if textSize.Height < minTextSize.Height*multiLineRows {
textSize.Height = minTextSize.Height * multiLineRows
}
// ensure multiline height is at least charMinSize * multilineRows
minSize.Height = fyne.Max(minSize.Height, e.text.charMinSize().Height*multiLineRows)
}

return textSize.Add(fyne.NewSize(theme.Padding()*4, theme.Padding()*2))
return minSize.Add(fyne.NewSize(theme.Padding()*4, theme.Padding()*2))
}

func (e *entryRenderer) moveCursor() {
Expand Down
7 changes: 7 additions & 0 deletions widget/entry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ import (
func TestEntry_MinSize(t *testing.T) {
entry := NewEntry()
min := entry.MinSize()
entry.SetPlaceHolder("")
assert.Equal(t, min, entry.MinSize())
entry.SetText("")
assert.Equal(t, min, entry.MinSize())
entry.SetPlaceHolder("Hi")
assert.True(t, entry.MinSize().Width > min.Width)
assert.Equal(t, entry.MinSize().Height, min.Height)

assert.True(t, min.Width > theme.Padding()*2)
assert.True(t, min.Height > theme.Padding()*2)
Expand Down

0 comments on commit 3fe3b61

Please sign in to comment.