Skip to content

Commit

Permalink
fyne-ioGH-4595: expose viewlayout publicly
Browse files Browse the repository at this point in the history
  • Loading branch information
maruu committed Feb 1, 2024
1 parent 85644c2 commit 0ea6caa
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
26 changes: 13 additions & 13 deletions dialog/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import (
"fyne.io/fyne/v2/widget"
)

type viewLayout int
type ViewLayout int

const (
gridView viewLayout = iota
listView
GridView ViewLayout = iota
ListView
)

const viewLayoutKey = "fyne:fileDialogViewLayout"
Expand Down Expand Up @@ -56,7 +56,7 @@ type fileDialog struct {
favoritesList *widget.List
showHidden bool

view viewLayout
view ViewLayout

data []fyne.URI
dataLock sync.RWMutex
Expand Down Expand Up @@ -138,9 +138,9 @@ func (f *fileDialog) makeUI() fyne.CanvasObject {
title = label + " Folder"
}

view := viewLayout(fyne.CurrentApp().Preferences().Int(viewLayoutKey))
if view != listView {
view = gridView
view := ViewLayout(fyne.CurrentApp().Preferences().Int(viewLayoutKey))
if view != ListView {
view = GridView
}

f.setView(view)
Expand Down Expand Up @@ -169,19 +169,19 @@ func (f *fileDialog) makeUI() fyne.CanvasObject {
})

var toggleViewButtonIcon fyne.Resource
if f.view == gridView {
if f.view == GridView {
toggleViewButtonIcon = theme.ListIcon()
} else {
toggleViewButtonIcon = theme.GridIcon()
}

var toggleViewButton *widget.Button
toggleViewButton = widget.NewButtonWithIcon("", toggleViewButtonIcon, func() {
if f.view == gridView {
f.setView(listView)
if f.view == GridView {
f.setView(ListView)
toggleViewButton.SetIcon(theme.GridIcon())
} else {
f.setView(gridView)
f.setView(GridView)
toggleViewButton.SetIcon(theme.ListIcon())
}
})
Expand Down Expand Up @@ -516,7 +516,7 @@ func (f *fileDialog) setSelected(file fyne.URI, id int) {
}
}

func (f *fileDialog) setView(view viewLayout) {
func (f *fileDialog) setView(view ViewLayout) {
f.view = view
fyne.CurrentApp().Preferences().SetInt(viewLayoutKey, int(view))

Expand All @@ -542,7 +542,7 @@ func (f *fileDialog) setView(view viewLayout) {
f.setSelected(file, id)
}
}
if f.view == gridView {
if f.view == GridView {
grid := widget.NewGridWrap(count, template, update)
grid.OnSelected = choose
f.files = grid
Expand Down
12 changes: 6 additions & 6 deletions dialog/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,22 +528,22 @@ func TestViewPreferences(t *testing.T) {
toggleViewButton := ui.Objects[1].(*fyne.Container).Objects[0].(*fyne.Container).Objects[1].(*widget.Button)

// viewLayout preference should be 'grid'
view := viewLayout(prefs.Int(viewLayoutKey))
assert.Equal(t, gridView, view)
view := ViewLayout(prefs.Int(viewLayoutKey))
assert.Equal(t, GridView, view)

// toggle view
test.Tap(toggleViewButton)

// viewLayout preference should be 'list'
view = viewLayout(prefs.Int(viewLayoutKey))
assert.Equal(t, listView, view)
view = ViewLayout(prefs.Int(viewLayoutKey))
assert.Equal(t, ListView, view)

// toggle view
test.Tap(toggleViewButton)

// viewLayout preference should be 'grid' again
view = viewLayout(prefs.Int(viewLayoutKey))
assert.Equal(t, gridView, view)
view = ViewLayout(prefs.Int(viewLayoutKey))
assert.Equal(t, GridView, view)
}

func TestFileFavorites(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions dialog/fileitem.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (i *fileDialogItem) setLocation(l fyne.URI, dir, up bool) {
i.location = l
i.name = l.Name()

if i.picker.view == gridView {
if i.picker.view == GridView {
ext := filepath.Ext(i.name[1:])
i.name = i.name[:len(i.name)-len(ext)]
}
Expand All @@ -63,7 +63,7 @@ func (f *fileDialog) newFileItem(location fyne.URI, dir, up bool) *fileDialogIte
dir: dir,
}

if f.view == gridView {
if f.view == GridView {
ext := filepath.Ext(item.name[1:])
item.name = item.name[:len(item.name)-len(ext)]
}
Expand All @@ -86,7 +86,7 @@ type fileItemRenderer struct {
}

func (s *fileItemRenderer) Layout(size fyne.Size) {
if s.item.picker.view == gridView {
if s.item.picker.view == GridView {
s.icon.Resize(fyne.NewSize(fileIconSize, fileIconSize))
s.icon.Move(fyne.NewPos((size.Width-fileIconSize)/2, 0))

Expand All @@ -105,7 +105,7 @@ func (s *fileItemRenderer) Layout(size fyne.Size) {
}

func (s *fileItemRenderer) MinSize() fyne.Size {
if s.item.picker.view == gridView {
if s.item.picker.view == GridView {
return fyne.NewSize(fileIconCellWidth, fileIconSize+s.fileTextSize)
}

Expand Down
4 changes: 2 additions & 2 deletions dialog/fileitem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestFileItem_Name(t *testing.T) {
assert.Equal(t, "noext", item.name)

// Test that the extension remains for the list view.
f.view = listView
f.view = ListView

item = f.newFileItem(storage.NewFileURI("/path/to/filename.txt"), false, false)
assert.Equal(t, "filename.txt", item.name)
Expand Down Expand Up @@ -57,7 +57,7 @@ func TestFileItem_FolderName(t *testing.T) {
assert.Equal(t, ".maybeHidden", item.name)

// Test that the extension remains for the list view.
f.view = listView
f.view = ListView
item = f.newFileItem(storage.NewFileURI("/path/to/myapp.app/"), true, false)
assert.Equal(t, "myapp.app", item.name)
}
Expand Down

0 comments on commit 0ea6caa

Please sign in to comment.