Skip to content

Commit

Permalink
Change Select so that it doesn't expand to fit
Browse files Browse the repository at this point in the history
Biggest change is that the drop-down can be larger than button.
Also button will not grow to fit selected item.

Fixes fyne-io#1247
  • Loading branch information
andydotxyz committed Sep 27, 2020
1 parent 2ccac85 commit 1fbf228
Show file tree
Hide file tree
Showing 27 changed files with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions widget/select.go
Expand Up @@ -17,7 +17,7 @@ type selectRenderer struct {
*widget.ShadowingRenderer

icon *Icon
label *canvas.Text
label *Label
bg *canvas.Rectangle
combo *Select
}
Expand All @@ -28,12 +28,7 @@ func (s *selectRenderer) MinSize() fyne.Size {
s.combo.propertyLock.RLock()
defer s.combo.propertyLock.RUnlock()

min := fyne.MeasureText(s.combo.PlaceHolder, s.label.TextSize, s.label.TextStyle)

for _, option := range s.combo.Options {
optionMin := fyne.MeasureText(option, s.label.TextSize, s.label.TextStyle)
min = min.Union(optionMin)
}
min := fyne.MeasureText(s.combo.PlaceHolder, theme.TextSize(), s.label.TextStyle)

min = min.Add(fyne.NewSize(theme.Padding()*6, theme.Padding()*4))
return min.Add(fyne.NewSize(theme.IconInlineSize()+theme.Padding(), 0))
Expand Down Expand Up @@ -90,9 +85,6 @@ func (s *selectRenderer) Refresh() {
}

func (s *selectRenderer) updateLabel() {
s.label.Color = theme.TextColor()
s.label.TextSize = theme.TextSize()

if s.combo.PlaceHolder == "" {
s.combo.PlaceHolder = defaultPlaceHolder
}
Expand Down Expand Up @@ -222,8 +214,9 @@ func (s *Select) CreateRenderer() fyne.WidgetRenderer {
s.propertyLock.RLock()
defer s.propertyLock.RUnlock()
icon := NewIcon(theme.MenuDropDownIcon())
text := canvas.NewText(s.Selected, theme.TextColor())
text := NewLabel(s.Selected)
text.TextStyle.Bold = true
text.Wrapping = fyne.TextTruncate

if s.PlaceHolder == "" {
s.PlaceHolder = defaultPlaceHolder
Expand Down
Binary file modified widget/testdata/select/layout_empty.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified widget/testdata/select/layout_empty_expanded.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified widget/testdata/select/layout_empty_expanded_placeholder.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified widget/testdata/select/layout_empty_placeholder.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified widget/testdata/select/layout_multiple.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified widget/testdata/select/layout_multiple_expanded.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified widget/testdata/select/layout_multiple_expanded_placeholder.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified widget/testdata/select/layout_multiple_expanded_selected.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified widget/testdata/select/layout_multiple_placeholder.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified widget/testdata/select/layout_multiple_selected.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified widget/testdata/select/layout_multiple_selected_placeholder.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified widget/testdata/select/layout_single.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified widget/testdata/select/layout_single_expanded.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified widget/testdata/select/layout_single_expanded_placeholder.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified widget/testdata/select/layout_single_expanded_selected.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified widget/testdata/select/layout_single_placeholder.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified widget/testdata/select/layout_single_selected.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified widget/testdata/select/layout_single_selected_placeholder.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified widget/testdata/select/move_initial.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified widget/testdata/select/move_moved.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified widget/testdata/select/move_tapped.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified widget/testdata/select/tapped.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified widget/testdata/select/theme_changed.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified widget/testdata/select/theme_initial.png

0 comments on commit 1fbf228

Please sign in to comment.