/
main.go
167 lines (144 loc) · 3.56 KB
/
main.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
package main
import (
"fmt"
"net/url"
"os"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/data/binding"
"fyne.io/fyne/v2/driver/desktop"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
)
type enterEntry struct {
widget.Entry
enterFunc func(s string)
}
func (e *enterEntry) TypedKey(key *fyne.KeyEvent) {
switch key.Name {
case fyne.KeyReturn:
e.enterFunc(e.Text)
default:
e.Entry.TypedKey(key)
}
}
func newEnterEntry() *enterEntry {
entry := &enterEntry{}
entry.ExtendBaseWidget(entry)
return entry
}
type editingSlider struct {
widget.Slider
dragEndFunc func(float64)
}
func (e *editingSlider) DragEnd() {
e.dragEndFunc(e.Value)
}
func newEditingSlider(min, max float64) *editingSlider {
editSlider := &editingSlider{}
editSlider.Max = max
editSlider.Min = min
editSlider.ExtendBaseWidget(editSlider)
return editSlider
}
// newEditingOption creates a new VBox, that includes an info text and a widget to edit the parameter
func newEditingOption(infoText string, slider *editingSlider, defaultValue float64) *fyne.Container {
data := binding.BindFloat(&defaultValue)
text := widget.NewLabel(infoText)
value := widget.NewLabelWithData(binding.FloatToStringWithFormat(data, "%.0f"))
slider.Bind(data)
slider.Step = 1
return container.NewVBox(
container.NewHBox(
text,
layout.NewSpacer(),
value,
),
slider,
)
}
func parseURL(urlStr string) *url.URL {
link, err := url.Parse(urlStr)
if err != nil {
fyne.LogError("Could not parse URL", err)
}
return link
}
// App represents the whole application with all its windows, widgets and functions
type App struct {
app fyne.App
mainWin fyne.Window
img Img
mainModKey desktop.Modifier
focus bool
lastOpened []string
image *canvas.Image
sliderBrightness *editingSlider
sliderContrast *editingSlider
sliderHue *editingSlider
sliderSaturation *editingSlider
sliderColorBalanceR *editingSlider
sliderColorBalanceG *editingSlider
sliderColorBalanceB *editingSlider
sliderSepia *editingSlider
sliderBlur *editingSlider
resetBtn *widget.Button
split *container.Split
widthLabel *widget.Label
heightLabel *widget.Label
imgSize *widget.Label
imgLastMod *widget.Label
statusBar *fyne.Container
leftArrow *widget.Button
rightArrow *widget.Button
deleteBtn *widget.Button
renameBtn *widget.Button
zoomIn *widget.Button
zoomOut *widget.Button
zoomLabel *widget.Label
resetZoomBtn *widget.Button
fullscreenWin fyne.Window
}
func reverseArray(arr []string) []string {
for i := 0; i < len(arr)/2; i++ {
j := len(arr) - i - 1
arr[i], arr[j] = arr[j], arr[i]
}
return arr
}
func (a *App) init() {
a.img = Img{}
a.img.init()
// theme
switch a.app.Preferences().StringWithFallback("Theme", "Dark") {
case "Light":
a.app.Settings().SetTheme(theme.LightTheme())
case "Dark":
a.app.Settings().SetTheme(theme.DarkTheme())
}
// show/hide statusbar
if a.app.Preferences().BoolWithFallback("statusBarVisible", true) == false {
a.statusBar.Hide()
}
}
func main() {
a := app.NewWithID("io.github.palexer.image-viewer")
w := a.NewWindow("Image Viewer")
a.SetIcon(resourceIconPng)
w.SetIcon(resourceIconPng)
ui := &App{app: a, mainWin: w}
ui.init()
w.SetContent(ui.loadMainUI())
if len(os.Args) > 1 {
file, err := os.Open(os.Args[1])
if err != nil {
fmt.Printf("error while opening the file: %v\n", err)
}
ui.open(file, true)
}
w.Resize(fyne.NewSize(1200, 750))
w.ShowAndRun()
}