Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:fyne-io/fyne into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Jun 3, 2020
2 parents 81ac346 + 59d0108 commit 64e5a44
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
1 change: 1 addition & 0 deletions settings.go
Expand Up @@ -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.
Expand Down
16 changes: 14 additions & 2 deletions widget/button.go
Expand Up @@ -3,6 +3,7 @@ package widget
import (
"image/color"
"strings"
"time"

"fyne.io/fyne"
"fyne.io/fyne/canvas"
Expand All @@ -12,6 +13,8 @@ import (
"fyne.io/fyne/theme"
)

const buttonTapDuration = 250

type buttonRenderer struct {
*widget.ShadowingRenderer

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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()
}
Expand Down
16 changes: 12 additions & 4 deletions widget/select.go
Expand Up @@ -2,6 +2,7 @@ package widget

import (
"image/color"
"time"

"fyne.io/fyne"
"fyne.io/fyne/canvas"
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

0 comments on commit 64e5a44

Please sign in to comment.