Skip to content

Commit

Permalink
Merge pull request fyne-io#2264 from andydotxyz/fix/consistentbasewidget
Browse files Browse the repository at this point in the history
Fix/consistentbasewidget
  • Loading branch information
andydotxyz authored Jun 3, 2021
2 parents fca4f9d + 11a6979 commit 72d5607
Show file tree
Hide file tree
Showing 17 changed files with 175 additions and 492 deletions.
2 changes: 1 addition & 1 deletion container/doctabs.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (t *DocTabs) CreateRenderer() fyne.WidgetRenderer {
buttonCache: make(map[*TabItem]*tabButton),
},
docTabs: t,
scroller: &Scroll{},
scroller: NewScroll(nil),
}
r.action = r.buildAllTabsButton()
r.create = r.buildCreateTabsButton()
Expand Down
75 changes: 7 additions & 68 deletions internal/driver/glfw/menu_bar.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ type MenuBar struct {
func NewMenuBar(mainMenu *fyne.MainMenu, canvas fyne.Canvas) *MenuBar {
items := make([]fyne.CanvasObject, len(mainMenu.Items))
b := &MenuBar{Items: items, canvas: canvas}
b.ExtendBaseWidget(b)
for i, menu := range mainMenu.Items {
items[i] = &menuBarItem{Menu: menu, Parent: b}
barItem := &menuBarItem{Menu: menu, Parent: b}
barItem.ExtendBaseWidget(barItem)
items[i] = barItem
}
return b
}
Expand All @@ -38,6 +41,7 @@ func (b *MenuBar) CreateRenderer() fyne.WidgetRenderer {
cont := fyne.NewContainerWithLayout(layout.NewHBoxLayout(), b.Items...)
background := canvas.NewRectangle(theme.ButtonColor())
underlay := &menuBarUnderlay{action: b.deactivate}
underlay.ExtendBaseWidget(underlay)
objects := []fyne.CanvasObject{underlay, background, cont}
for _, item := range b.Items {
objects = append(objects, item.(*menuBarItem).Child())
Expand All @@ -57,49 +61,6 @@ func (b *MenuBar) IsActive() bool {
return b.active
}

// Hide hides the menu bar.
//
// Implements: fyne.Widget
func (b *MenuBar) Hide() {
widget.HideWidget(&b.Base, b)
}

// MinSize returns the minimal size of the menu bar.
//
// Implements: fyne.Widget
func (b *MenuBar) MinSize() fyne.Size {
return widget.MinSizeOf(b)
}

// Move sets the position of the widget relative to its parent.
//
// Implements: fyne.Widget
func (b *MenuBar) Move(pos fyne.Position) {
widget.MoveWidget(&b.Base, b, pos)
}

// Refresh triggers a redraw of the menu bar.
//
// Implements: fyne.Widget
func (b *MenuBar) Refresh() {
widget.RefreshWidget(b)
}

// Resize resizes the menu bar.
// It only affects the width because menu bars are always displayed with their minimal height.
//
// Implements: fyne.Widget
func (b *MenuBar) Resize(size fyne.Size) {
widget.ResizeWidget(&b.Base, b, size)
}

// Show makes the menu bar visible.
//
// Implements: fyne.Widget
func (b *MenuBar) Show() {
widget.ShowWidget(&b.Base, b)
}

// Toggle changes the activation state of the menu bar.
// On activation, the first item will become active.
func (b *MenuBar) Toggle() {
Expand Down Expand Up @@ -128,6 +89,7 @@ func (b *MenuBar) activateChild(item *menuBarItem) {
return
}

item.Refresh()
item.Child().Show()
b.Refresh()
}
Expand Down Expand Up @@ -199,6 +161,7 @@ func (r *menuBarRenderer) Refresh() {
r.Layout(r.b.Size())
r.background.FillColor = theme.ButtonColor()
r.background.Refresh()
r.ShadowingRenderer.RefreshShadow()
canvas.Refresh(r.b)
}

Expand All @@ -217,14 +180,6 @@ func (u *menuBarUnderlay) CreateRenderer() fyne.WidgetRenderer {
return &menuUnderlayRenderer{}
}

func (u *menuBarUnderlay) Hide() {
widget.HideWidget(&u.Base, u)
}

func (u *menuBarUnderlay) MinSize() fyne.Size {
return widget.MinSizeOf(u)
}

func (u *menuBarUnderlay) MouseIn(*desktop.MouseEvent) {
}

Expand All @@ -234,22 +189,6 @@ func (u *menuBarUnderlay) MouseOut() {
func (u *menuBarUnderlay) MouseMoved(*desktop.MouseEvent) {
}

func (u *menuBarUnderlay) Move(pos fyne.Position) {
widget.MoveWidget(&u.Base, u, pos)
}

func (u *menuBarUnderlay) Refresh() {
widget.RefreshWidget(u)
}

func (u *menuBarUnderlay) Resize(size fyne.Size) {
widget.ResizeWidget(&u.Base, u, size)
}

func (u *menuBarUnderlay) Show() {
widget.ShowWidget(&u.Base, u)
}

func (u *menuBarUnderlay) Tapped(*fyne.PointEvent) {
u.action()
}
Expand Down
42 changes: 0 additions & 42 deletions internal/driver/glfw/menu_bar_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,6 @@ func (i *menuBarItem) Focused() bool {
return i.active
}

// Hide hides the menu bar item.
//
// Implements: fyne.Widget
func (i *menuBarItem) Hide() {
widget.HideWidget(&i.Base, i)
}

// MinSize returns the minimal size of the menu bar item.
//
// Implements: fyne.Widget
func (i *menuBarItem) MinSize() fyne.Size {
return widget.MinSizeOf(i)
}

// MouseIn activates the item and shows the menu if the bar is active.
// The menu that was displayed before will be hidden.
//
Expand Down Expand Up @@ -121,34 +107,6 @@ func (i *menuBarItem) MouseOut() {
i.Refresh()
}

// Move sets the position of the widget relative to its parent.
//
// Implements: fyne.Widget
func (i *menuBarItem) Move(pos fyne.Position) {
widget.MoveWidget(&i.Base, i, pos)
}

// Refresh triggers a redraw of the menu bar item.
//
// Implements: fyne.Widget
func (i *menuBarItem) Refresh() {
widget.RefreshWidget(i)
}

// Resize changes the size of the menu bar item.
//
// Implements: fyne.Widget
func (i *menuBarItem) Resize(size fyne.Size) {
widget.ResizeWidget(&i.Base, i, size)
}

// Show makes the menu bar item visible.
//
// Implements: fyne.Widget
func (i *menuBarItem) Show() {
widget.ShowWidget(&i.Base, i)
}

// Tapped toggles the activation state of the menu bar.
// It shows the item’s menu if the bar is activated and hides it if the bar is deactivated.
//
Expand Down
Loading

0 comments on commit 72d5607

Please sign in to comment.