-
Notifications
You must be signed in to change notification settings - Fork 5
/
m_appui.go
203 lines (180 loc) · 5.59 KB
/
m_appui.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
package main
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/data/binding"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
)
// List folder URI
var rootURI fyne.ListableURI
// List of photos
var list []*Photo
// Frame with photos
var frame *Frame
// application App
type App struct {
fyne.App
// Main window
topWindow fyne.Window
topWindowTitle binding.String
// Current folder state
state State
// Top toolbar row
topRow *fyne.Container
// Toolbar
toolBar *widget.Toolbar
// Toolbar actions
actAbout *widget.ToolbarAction
actOpenFolder *widget.ToolbarAction
actSaveList *widget.ToolbarAction
actSettings *widget.ToolbarAction
actAddPhoto *widget.ToolbarAction
actRemovePhoto *widget.ToolbarAction
actToggleView *widget.ToolbarAction
actToggleFullScreen *widget.ToolbarAction
actEditPhoto *widget.ToolbarAction
actNoAction *widget.ToolbarAction
statusInfo *StatusInfo
// Frame view
frameView *fyne.Container
// List view
listView *fyne.Container
// List table
listTable *widget.Table
// List columns settings
listColumns []*ListColumn
// Shortcuts
ControlShortCuts []ShortCutInfo
AltShortCuts []ShortCutInfo
}
var a *App
// make main window newLayout
func (a *App) newLayout() {
a.newToolbar()
a.newFrame()
a.showFrameToolbar()
a.frameView = frame.newFrameView()
a.listView = a.newListView()
a.listView.Hide()
a.topRow = container.NewStack(a.toolBar)
content := container.NewStack(newFixedSpacer(fyne.NewSize(640, 360)), a.frameView, a.listView)
a.topWindow.SetContent(container.NewBorder(a.topRow, nil, nil, nil, content))
}
func (a *App) newToolbar() {
a.actAbout = widget.NewToolbarAction(theme.InfoIcon(), a.aboutDialog)
a.actOpenFolder = widget.NewToolbarAction(theme.FolderOpenIcon(), a.openFolderDialog)
a.actSaveList = widget.NewToolbarAction(theme.DocumentSaveIcon(), a.savePhotoListDialog)
a.actSettings = widget.NewToolbarAction(theme.SettingsIcon(), a.settingsDialog)
a.actAddPhoto = widget.NewToolbarAction(theme.ContentAddIcon(), func() { frame.AddItem() })
a.actRemovePhoto = widget.NewToolbarAction(theme.ContentRemoveIcon(), func() { frame.RemoveItem() })
a.actToggleView = widget.NewToolbarAction(theme.ListIcon(), a.toggleView)
a.actToggleFullScreen = widget.NewToolbarAction(theme.ViewFullScreenIcon(), a.toggleFullScreen)
a.actEditPhoto = widget.NewToolbarAction(theme.NewThemedResource(iconAdjust), func() { a.editDialog() })
a.actNoAction = widget.NewToolbarAction(theme.NewThemedResource(iconBlank), func() {})
a.statusInfo = newStatusInfo()
a.toolBar = widget.NewToolbar()
}
func (a *App) toggleView() {
if a.frameView.Hidden {
a.statusInfo.ShowProgress()
defer a.statusInfo.HideProgress()
a.showFrameToolbar()
a.frameView.Show()
a.listView.Hide()
a.actToggleView.SetIcon(theme.ListIcon())
pos := a.state.FramePos + a.state.FrameSize
if pos > len(list)-a.state.FrameSize {
frame.Last()
} else {
frame.At(a.state.FramePos)
}
a.frameView.Refresh()
} else {
a.showListToolbar()
a.syncListViewScroll()
a.frameView.Hide()
a.listView.Refresh()
a.listView.Show()
a.actToggleView.SetIcon(theme.GridIcon())
}
a.toolBar.Refresh()
frame.ItemEndingAt(a.state.ItemPos)
}
func (a *App) syncListViewScroll() {
col := 0
row := a.state.FramePos
switch {
case row < a.state.FrameSize:
a.listTable.ScrollToTop()
case row >= len(list)-a.state.FrameSize:
a.listTable.ScrollToBottom()
default:
a.listTable.ScrollTo(widget.TableCellID{Col: col, Row: row})
}
a.listTable.ScrollToLeading()
}
func (a *App) toggleFullScreen() {
if a.topWindow.FullScreen() {
a.topWindow.SetFullScreen(false)
a.actToggleFullScreen.SetIcon(theme.ViewFullScreenIcon())
} else {
a.topWindow.SetFullScreen(true)
a.actToggleFullScreen.SetIcon(theme.ViewRestoreIcon())
}
a.showFrameToolbar() // TODO: remove this after fix crop
a.toolBar.Refresh()
}
func (a *App) showFrameToolbar() {
a.toolBar.Items = []widget.ToolbarItem{}
if len(list) > 0 {
a.toolBar.Prepend(a.actAbout)
a.toolBar.Prepend(a.actSettings)
a.toolBar.Prepend(widget.NewToolbarSeparator())
a.toolBar.Prepend(a.actToggleFullScreen)
a.toolBar.Prepend(a.actToggleView)
a.toolBar.Prepend(widget.NewToolbarSeparator())
a.toolBar.Prepend(widget.NewToolbarSpacer())
a.toolBar.Prepend(a.statusInfo)
a.toolBar.Prepend(widget.NewToolbarSpacer())
if !a.state.Simple && !a.topWindow.FullScreen() {
a.toolBar.Prepend(widget.NewToolbarSeparator())
a.toolBar.Prepend(a.actEditPhoto)
}
a.toolBar.Prepend(widget.NewToolbarSeparator())
if a.state.FrameSize < MaxFrameSize && a.state.FrameSize < len(list) {
a.toolBar.Prepend(a.actAddPhoto)
} else {
a.toolBar.Prepend(a.actNoAction)
}
if a.state.FrameSize > MinFrameSize {
a.toolBar.Prepend(a.actRemovePhoto)
} else {
a.toolBar.Prepend(a.actNoAction)
}
} else {
a.toolBar.Prepend(a.actOpenFolder)
}
a.toolBar.Refresh()
}
func (a *App) showListToolbar() {
a.toolBar.Items = []widget.ToolbarItem{}
a.toolBar.Append(a.actOpenFolder)
a.toolBar.Append(a.actSaveList)
a.toolBar.Append(widget.NewToolbarSeparator())
a.toolBar.Append(widget.NewToolbarSpacer())
a.toolBar.Append(a.statusInfo)
a.toolBar.Append(widget.NewToolbarSpacer())
a.toolBar.Append(widget.NewToolbarSeparator())
a.toolBar.Append(a.actToggleView)
a.toolBar.Append(a.actToggleFullScreen)
a.toolBar.Append(widget.NewToolbarSeparator())
a.toolBar.Append(a.actSettings)
a.toolBar.Append(a.actAbout)
}
func (a *App) toggleMode() {
a.statusInfo.ShowProgress()
defer a.statusInfo.HideProgress()
a.state.Simple = !a.state.Simple
frame.At(a.state.FramePos)
}