diff --git a/settings.go b/settings.go index 145337c408..4398e69355 100644 --- a/settings.go +++ b/settings.go @@ -2,6 +2,7 @@ package fyne // SettingsScaleAuto is a specific scale value that indicates a canvas should // scale according to the DPI of the window that contains it. +// Deprecated: Automatic scaling is now handled in the drivers and is not a user setting. const SettingsScaleAuto = float32(-1.0) // Settings describes the application configuration available. diff --git a/widget/button.go b/widget/button.go index 92b82089dc..bdeae4c8b2 100644 --- a/widget/button.go +++ b/widget/button.go @@ -3,6 +3,7 @@ package widget import ( "image/color" "strings" + "time" "fyne.io/fyne" "fyne.io/fyne/canvas" @@ -12,6 +13,8 @@ import ( "fyne.io/fyne/theme" ) +const buttonTapDuration = 250 + type buttonRenderer struct { *widget.ShadowingRenderer @@ -117,7 +120,7 @@ func (b *buttonRenderer) BackgroundColor() color.Color { return theme.DisabledButtonColor() case b.button.Style == PrimaryButton: return theme.PrimaryColor() - case b.button.hovered: + case b.button.hovered, b.button.tapped: // TODO tapped will be different to hovered when we have animation return theme.HoverColor() default: return theme.ButtonColor() @@ -166,8 +169,9 @@ type Button struct { IconPlacement ButtonIconPlacement OnTapped func() `json:"-"` - hovered bool HideShadow bool + + hovered, tapped bool } // ButtonStyle determines the behaviour and rendering of a button. @@ -204,6 +208,14 @@ const ( // Tapped is called when a pointer tapped event is captured and triggers any tap handler func (b *Button) Tapped(*fyne.PointEvent) { + b.tapped = true + defer func() { // TODO move to a real animation + time.Sleep(time.Millisecond * buttonTapDuration) + b.tapped = false + b.Refresh() + }() + b.Refresh() + if b.OnTapped != nil && !b.Disabled() { b.OnTapped() } diff --git a/widget/select.go b/widget/select.go index 0425ee32cd..7304c54c09 100644 --- a/widget/select.go +++ b/widget/select.go @@ -2,6 +2,7 @@ package widget import ( "image/color" + "time" "fyne.io/fyne" "fyne.io/fyne/canvas" @@ -58,7 +59,7 @@ func (s *selectRenderer) Layout(size fyne.Size) { } func (s *selectRenderer) BackgroundColor() color.Color { - if s.combo.hovered { + if s.combo.hovered || s.combo.tapped { // TODO tapped will be different to hovered when we have animation return theme.HoverColor() } return theme.ButtonColor() @@ -106,8 +107,8 @@ type Select struct { PlaceHolder string OnChanged func(string) `json:"-"` - hovered bool - popUp *PopUpMenu + hovered, tapped bool + popUp *PopUpMenu } var _ fyne.Widget = (*Select)(nil) @@ -150,6 +151,13 @@ func (s *Select) optionTapped(text string) { // Tapped is called when a pointer tapped event is captured and triggers any tap handler func (s *Select) Tapped(*fyne.PointEvent) { c := fyne.CurrentApp().Driver().CanvasForObject(s.super()) + s.tapped = true + defer func() { // TODO move to a real animation + time.Sleep(time.Millisecond * buttonTapDuration) + s.tapped = false + s.Refresh() + }() + s.Refresh() var items []*fyne.MenuItem for _, option := range s.Options { @@ -243,7 +251,7 @@ func (s *Select) updateSelected(text string) { // NewSelect creates a new select widget with the set list of options and changes handler func NewSelect(options []string, changed func(string)) *Select { - s := &Select{BaseWidget{}, "", options, defaultPlaceHolder, changed, false, nil} + s := &Select{BaseWidget{}, "", options, defaultPlaceHolder, changed, false, false, nil} s.ExtendBaseWidget(s) return s }