Skip to content

Commit

Permalink
Merge branch 'develop' into fix/cache-renderer-memleak
Browse files Browse the repository at this point in the history
  • Loading branch information
fpabl0 committed Jun 4, 2021
2 parents d0041e5 + e3a830d commit 8764345
Show file tree
Hide file tree
Showing 85 changed files with 575 additions and 880 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
This file lists the main changes with each version of the Fyne toolkit.
More detailed release notes can be found on the [releases page](https://github.com/fyne-io/fyne/releases).

## 2.1 - Ongoing

### Added

### Updated

* Focusable widgets are no longer focused on tap, add canvas.Focus(obj) in Tapped handler if required

### Fixed


## 2.0.3 - 30 April 2021

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion cmd/fyne/internal/mobile/binres/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (pl *Pool) UnmarshalBinary(bin []byte) error {
}

data := bin[offset : offset+nbytes]
if x := uint8(bin[offset+nbytes]); x != 0 {
if x := bin[offset+nbytes]; x != 0 {
return fmt.Errorf("expected zero terminator, got 0x%02X for nchars=%v nbytes=%v data=%q", x, nchars, nbytes, data)
}
pl.strings[i] = string(data)
Expand Down
32 changes: 16 additions & 16 deletions cmd/fyne/internal/mobile/binres/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,8 @@ func (spec *TypeSpec) UnmarshalBinary(bin []byte) error {
if spec.typ != ResTableTypeSpec {
return errWrongType(spec.typ, ResTableTypeSpec)
}
spec.id = uint8(bin[8])
spec.res0 = uint8(bin[9])
spec.id = bin[8]
spec.res0 = bin[9]
spec.res1 = btou16(bin[10:])
spec.entryCount = btou32(bin[12:])

Expand All @@ -425,7 +425,7 @@ func (spec *TypeSpec) MarshalBinary() ([]byte, error) {
putu16(bin[2:], 16)
putu32(bin[4:], uint32(len(bin)))

bin[8] = byte(spec.id)
bin[8] = spec.id
// [9] = 0
// [10:12] = 0
putu32(bin[12:], uint32(len(spec.entries)))
Expand Down Expand Up @@ -507,8 +507,8 @@ func (typ *Type) UnmarshalBinary(bin []byte) error {
return errWrongType(typ.typ, ResTableType)
}

typ.id = uint8(bin[8])
typ.res0 = uint8(bin[9])
typ.id = bin[8]
typ.res0 = bin[9]
typ.res1 = btou16(bin[10:])
typ.entryCount = btou32(bin[12:])
typ.entriesStart = btou32(bin[16:])
Expand All @@ -522,19 +522,19 @@ func (typ *Type) UnmarshalBinary(bin []byte) error {
typ.config.imsi.mnc = btou16(bin[26:])
typ.config.locale.language = btou16(bin[28:])
typ.config.locale.country = btou16(bin[30:])
typ.config.screenType.orientation = uint8(bin[32])
typ.config.screenType.touchscreen = uint8(bin[33])
typ.config.screenType.orientation = bin[32]
typ.config.screenType.touchscreen = bin[33]
typ.config.screenType.density = btou16(bin[34:])
typ.config.input.keyboard = uint8(bin[36])
typ.config.input.navigation = uint8(bin[37])
typ.config.input.inputFlags = uint8(bin[38])
typ.config.input.inputPad0 = uint8(bin[39])
typ.config.input.keyboard = bin[36]
typ.config.input.navigation = bin[37]
typ.config.input.inputFlags = bin[38]
typ.config.input.inputPad0 = bin[39]
typ.config.screenSize.width = btou16(bin[40:])
typ.config.screenSize.height = btou16(bin[42:])
typ.config.version.sdk = btou16(bin[44:])
typ.config.version.minor = btou16(bin[46:])
typ.config.screenConfig.layout = uint8(bin[48])
typ.config.screenConfig.uiMode = uint8(bin[49])
typ.config.screenConfig.layout = bin[48]
typ.config.screenConfig.uiMode = bin[49]
typ.config.screenConfig.smallestWidthDP = btou16(bin[50:])
typ.config.screenSizeDP.width = btou16(bin[52:])
typ.config.screenSizeDP.height = btou16(bin[54:])
Expand Down Expand Up @@ -572,7 +572,7 @@ func (typ *Type) MarshalBinary() ([]byte, error) {
putu16(bin, uint16(ResTableType))
putu16(bin[2:], 56)

bin[8] = byte(typ.id)
bin[8] = typ.id
// [9] = 0
// [10:12] = 0
putu32(bin[12:], uint32(len(typ.entries)))
Expand Down Expand Up @@ -755,7 +755,7 @@ type Data struct {
// UnmarshalBinary creates the data item from binary data
func (d *Data) UnmarshalBinary(bin []byte) error {
d.ByteSize = btou16(bin)
d.Res0 = uint8(bin[2])
d.Res0 = bin[2]
d.Type = DataType(bin[3])
d.Value = btou32(bin[4:])
return nil
Expand All @@ -765,7 +765,7 @@ func (d *Data) UnmarshalBinary(bin []byte) error {
func (d *Data) MarshalBinary() ([]byte, error) {
bin := make([]byte, 8)
putu16(bin, 8)
bin[2] = byte(d.Res0)
bin[2] = d.Res0
bin[3] = byte(d.Type)
putu32(bin[4:], d.Value)
return bin, nil
Expand Down
9 changes: 5 additions & 4 deletions container/apptabs.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ func (t *AppTabs) CreateRenderer() fyne.WidgetRenderer {
},
appTabs: t,
}
r.action = r.buildOverflowTabsButton()

// Initially setup the tab bar to only show one tab, all others will be in overflow.
// When the widget is laid out, and we know the size, the tab bar will be updated to show as many as can fit.
r.updateTabs(1)
Expand Down Expand Up @@ -407,13 +409,12 @@ func (r *appTabsRenderer) updateTabs(max int) {

// Set overflow action
if tabCount <= max {
r.action = nil
r.action.Hide()
r.bar.Layout = layout.NewMaxLayout()
} else {
tabCount = max
if r.action == nil {
r.action = r.buildOverflowTabsButton()
}
r.action.Show()

// Set layout of tab bar containing tab buttons and overflow action
if r.appTabs.location == TabLocationLeading || r.appTabs.location == TabLocationTrailing {
r.bar.Layout = layout.NewBorderLayout(nil, r.action, nil, nil)
Expand Down
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
19 changes: 17 additions & 2 deletions internal/driver/glfw/menu_bar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestMenuBar(t *testing.T) {

menuBar := glfw.NewMenuBar(menu, c)
themeCounter := 0
button := widget.NewButton("Button", func() {
button := newNotFocusableButton("Button", func() {
switch themeCounter % 2 {
case 0:
test.ApplyTheme(t, test.NewTheme())
Expand Down Expand Up @@ -327,7 +327,7 @@ func TestMenuBar(t *testing.T) {

menuBar := glfw.NewMenuBar(menu, c)
themeCounter := 0
button := widget.NewButton("Button", func() {
button := newNotFocusableButton("Button", func() {
switch themeCounter % 2 {
case 0:
test.ApplyTheme(t, test.NewTheme())
Expand Down Expand Up @@ -526,3 +526,18 @@ func TestMenuBar_Toggle(t *testing.T) {
test.AssertRendersToMarkup(t, "menu_bar_toggle_deactivated.xml", c)
})
}

type notFocusableButton struct {
widget.Label
f func()
}

func newNotFocusableButton(l string, f func()) *notFocusableButton {
n := &notFocusableButton{f: f}
n.Label.Text = l
return n
}

func (n *notFocusableButton) Tapped(e *fyne.PointEvent) {
n.f()
}
Binary file modified internal/driver/glfw/testdata/menu_bar_active_edit.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified internal/driver/glfw/testdata/menu_bar_active_file.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified internal/driver/glfw/testdata/menu_bar_active_help.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified internal/driver/glfw/testdata/menu_bar_hovered_content.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified internal/driver/glfw/testdata/menu_bar_hovered_file_new.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified internal/driver/glfw/testdata/menu_bar_hovered_file_open.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified internal/driver/glfw/testdata/menu_bar_hovered_file_recent.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified internal/driver/glfw/testdata/menu_bar_inactive_file.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified internal/driver/glfw/testdata/menu_bar_initial.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 2 additions & 14 deletions internal/driver/glfw/testdata/menu_bar_kbdctrl_close_submenu_1.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
<canvas size="300x300">
<content>
<container size="300x300">
<widget pos="100,50" size="77x37" type="*widget.Button">
<widget pos="2,2" size="73x33" type="*widget.Shadow">
<radialGradient centerOffset="0.5,0.5" pos="-2,-2" size="2x2" startColor="shadow"/>
<linearGradient endColor="shadow" pos="0,-2" size="73x2"/>
<radialGradient centerOffset="-0.5,0.5" pos="73,-2" size="2x2" startColor="shadow"/>
<linearGradient angle="270" pos="73,0" size="2x33" startColor="shadow"/>
<radialGradient centerOffset="-0.5,-0.5" pos="73,33" size="2x2" startColor="shadow"/>
<linearGradient pos="0,33" size="73x2" startColor="shadow"/>
<radialGradient centerOffset="0.5,-0.5" pos="-2,33" size="2x2" startColor="shadow"/>
<linearGradient angle="270" endColor="shadow" pos="-2,0" size="2x33"/>
</widget>
<rectangle fillColor="button" pos="2,2" size="73x33"/>
<rectangle size="0x0"/>
<text bold pos="12,8" size="53x21">Button</text>
<widget pos="100,50" size="65x37" type="*glfw_test.notFocusableButton">
<text pos="8,8" size="49x21">Button</text>
</widget>
<widget size="300x29" type="*glfw.MenuBar">
<widget size="300x29" type="*widget.Shadow">
Expand Down

0 comments on commit 8764345

Please sign in to comment.