Skip to content

Commit

Permalink
Merge branch 'feature/remove_hover_from_menus' of git://github.com/to…
Browse files Browse the repository at this point in the history
…aster/fyne
  • Loading branch information
andydotxyz committed Jan 17, 2021
2 parents d16129f + 814c579 commit a899f7f
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions internal/driver/glfw/menu_bar_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ type menuBarItem struct {
Menu *fyne.Menu
Parent *MenuBar

active bool
child *publicWidget.Menu
active bool
child *publicWidget.Menu
hovered bool
}

func (i *menuBarItem) Child() *publicWidget.Menu {
Expand Down Expand Up @@ -81,33 +82,43 @@ func (i *menuBarItem) MinSize() fyne.Size {
return widget.MinSizeOf(i)
}

// MouseIn shows the menu if the bar is active.
// MouseIn activates the item and shows the menu if the bar is active.
// The menu that was displayed before will be hidden.
//
// If the bar is not active, the item will be hovered.
//
// Implements: desktop.Hoverable
func (i *menuBarItem) MouseIn(_ *desktop.MouseEvent) {
i.hovered = true
if i.Parent.active {
i.Parent.canvas.Focus(i)
}
i.Refresh()
}

// MouseMoved shows the menu if the bar is active.
// MouseMoved activates the item and shows the menu if the bar is active.
// The menu that was displayed before will be hidden.
// This might have an effect when mouse and keyboard control are mixed.
// Changing the active menu with the keyboard will make the hovered menu bar item inactive.
// On the next mouse move the hovered item is activated again.
//
// If the bar is not active, this will do nothing.
//
// Implements: desktop.Hoverable
func (i *menuBarItem) MouseMoved(_ *desktop.MouseEvent) {
if i.Parent.active {
i.Parent.canvas.Focus(i)
}
}

// MouseOut does nothing.
// MouseOut does nothing if the bar is active.
//
// IF the bar is not active, it changes the item to not be hovered.
//
// Implements: desktop.Hoverable
func (i *menuBarItem) MouseOut() {
i.hovered = false
i.Refresh()
}

// Move sets the position of the widget relative to its parent.
Expand Down Expand Up @@ -194,6 +205,9 @@ func (r *menuBarItemRenderer) Refresh() {
if r.i.active && r.i.Parent.active {
r.background.FillColor = theme.FocusColor()
r.background.Show()
} else if r.i.hovered && !r.i.Parent.active {
r.background.FillColor = theme.HoverColor()
r.background.Show()
} else {
r.background.Hide()
}
Expand Down

0 comments on commit a899f7f

Please sign in to comment.