Skip to content

Commit

Permalink
Parent should not be exposed in the menu items
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Dec 2, 2024
1 parent b1a2077 commit 3afb077
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions widget/menu_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@ var _ fyne.Widget = (*menuItem)(nil)
// menuItem is a widget for displaying a fyne.menuItem.
type menuItem struct {
widget.Base
Item *fyne.MenuItem
Parent *Menu
Item *fyne.MenuItem

alignment fyne.TextAlign
child *Menu
alignment fyne.TextAlign
child, parent *Menu
}

// newMenuItem creates a new menuItem.
func newMenuItem(item *fyne.MenuItem, parent *Menu) *menuItem {
i := &menuItem{Item: item, Parent: parent}
i := &menuItem{Item: item, parent: parent}
i.alignment = parent.alignment
i.ExtendBaseWidget(i)
return i
Expand All @@ -35,7 +34,7 @@ func (i *menuItem) Child() *Menu {
if i.Item.ChildMenu != nil && i.child == nil {
child := NewMenu(i.Item.ChildMenu)
child.Hide()
child.OnDismiss = i.Parent.Dismiss
child.OnDismiss = i.parent.Dismiss
i.child = child
}
return i.child
Expand All @@ -45,7 +44,7 @@ func (i *menuItem) Child() *Menu {
//
// Implements: fyne.Widget
func (i *menuItem) CreateRenderer() fyne.WidgetRenderer {
th := i.Parent.Theme()
th := i.parent.Theme()
v := fyne.CurrentApp().Settings().ThemeVariant()

background := canvas.NewRectangle(th.Color(theme.ColorNameHover, v))
Expand Down Expand Up @@ -139,7 +138,7 @@ func (i *menuItem) activate() {
if i.Child() != nil {
i.Child().Show()
}
i.Parent.activateItem(i)
i.parent.activateItem(i)
}

func (i *menuItem) activateLastSubmenu() bool {
Expand All @@ -158,7 +157,7 @@ func (i *menuItem) deactivate() {
if i.Child() != nil {
i.Child().Hide()
}
i.Parent.DeactivateChild()
i.parent.DeactivateChild()
}

func (i *menuItem) deactivateLastSubmenu() bool {
Expand All @@ -173,15 +172,15 @@ func (i *menuItem) deactivateLastSubmenu() bool {
}

func (i *menuItem) isActive() bool {
return i.Parent.activeItem == i
return i.parent.activeItem == i
}

func (i *menuItem) isSubmenuOpen() bool {
return i.Child() != nil && i.Child().Visible()
}

func (i *menuItem) trigger() {
i.Parent.Dismiss()
i.parent.Dismiss()
if i.Item.Action != nil {
i.Item.Action()
}
Expand Down Expand Up @@ -209,7 +208,7 @@ type menuItemRenderer struct {
}

func (r *menuItemRenderer) Layout(size fyne.Size) {
th := r.i.Parent.Theme()
th := r.i.parent.Theme()
innerPad := th.Size(theme.SizeNameInnerPadding)
inlineIcon := th.Size(theme.SizeNameInlineIcon)

Expand Down Expand Up @@ -258,7 +257,7 @@ func (r *menuItemRenderer) MinSize() fyne.Size {
return r.minSize
}

th := r.i.Parent.Theme()
th := r.i.parent.Theme()
innerPad := th.Size(theme.SizeNameInnerPadding)
inlineIcon := th.Size(theme.SizeNameInlineIcon)
innerPad2 := innerPad * 2
Expand All @@ -282,7 +281,7 @@ func (r *menuItemRenderer) MinSize() fyne.Size {
}

func (r *menuItemRenderer) updateVisuals() {
th := r.i.Parent.Theme()
th := r.i.parent.Theme()
v := fyne.CurrentApp().Settings().ThemeVariant()
r.background.CornerRadius = th.Size(theme.SizeNameSelectionRadius)
if fyne.CurrentDevice().IsMobile() {
Expand Down Expand Up @@ -316,14 +315,14 @@ func (r *menuItemRenderer) Refresh() {
}

func (r *menuItemRenderer) checkSpace() float32 {
if r.i.Parent.containsCheck {
if r.i.parent.containsCheck {
return theme.IconInlineSize() + theme.InnerPadding()
}
return 0
}

func (r *menuItemRenderer) minSizeUnchanged() bool {
th := r.i.Parent.Theme()
th := r.i.parent.Theme()

return !r.minSize.IsZero() &&
r.text.TextSize == th.Size(theme.SizeNameText) &&
Expand All @@ -343,7 +342,7 @@ func (r *menuItemRenderer) updateIcon(img *canvas.Image, rsc fyne.Resource) {
}

func (r *menuItemRenderer) refreshText(text *canvas.Text, shortcut bool) {
th := r.i.Parent.Theme()
th := r.i.parent.Theme()
v := fyne.CurrentApp().Settings().ThemeVariant()

text.TextSize = th.Size(theme.SizeNameText)
Expand Down

0 comments on commit 3afb077

Please sign in to comment.