Refactor application structure and initialize core components
I decided to rewrite the program taking into account the experience gained.
This commit is contained in:
33
internal/gui/view/convertor.go
Normal file
33
internal/gui/view/convertor.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package view
|
||||
|
||||
import (
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/lang"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
)
|
||||
|
||||
func Convertor() fyne.CanvasObject {
|
||||
form := newFormConvertor()
|
||||
|
||||
converterVideoFilesTitle := lang.L("converterVideoFilesTitle")
|
||||
return widget.NewCard(converterVideoFilesTitle, "", container.NewVScroll(form.getForm()))
|
||||
}
|
||||
|
||||
type formConvertor struct {
|
||||
form *widget.Form
|
||||
items []*widget.FormItem
|
||||
}
|
||||
|
||||
func newFormConvertor() *formConvertor {
|
||||
f := widget.NewForm()
|
||||
f.SubmitText = lang.L("converterVideoFilesSubmitTitle")
|
||||
|
||||
return &formConvertor{
|
||||
form: f,
|
||||
}
|
||||
}
|
||||
|
||||
func (f *formConvertor) getForm() *widget.Form {
|
||||
return f.form
|
||||
}
|
39
internal/gui/view/error.go
Normal file
39
internal/gui/view/error.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package view
|
||||
|
||||
import (
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/lang"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/application/setting"
|
||||
)
|
||||
|
||||
func StartWithError(err error, languages []setting.Lang, funcSelected func(lang setting.Lang)) fyne.CanvasObject {
|
||||
messageHead := lang.L("error")
|
||||
|
||||
listView := widget.NewList(
|
||||
func() int {
|
||||
return len(languages)
|
||||
},
|
||||
func() fyne.CanvasObject {
|
||||
return widget.NewLabel("template")
|
||||
},
|
||||
func(i widget.ListItemID, o fyne.CanvasObject) {
|
||||
block := o.(*widget.Label)
|
||||
block.SetText(languages[i].Title)
|
||||
})
|
||||
listView.OnSelected = func(id widget.ListItemID) {
|
||||
funcSelected(languages[id])
|
||||
}
|
||||
|
||||
return container.NewBorder(
|
||||
container.NewVBox(
|
||||
widget.NewLabel(messageHead),
|
||||
widget.NewLabel(err.Error()),
|
||||
),
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
listView,
|
||||
)
|
||||
}
|
28
internal/gui/view/start_without_support_lang.go
Normal file
28
internal/gui/view/start_without_support_lang.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package view
|
||||
|
||||
import (
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/lang"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/application/setting"
|
||||
)
|
||||
|
||||
func StartWithoutSupportLang(languages []setting.Lang, funcSelected func(lang setting.Lang)) fyne.CanvasObject {
|
||||
listView := widget.NewList(
|
||||
func() int {
|
||||
return len(languages)
|
||||
},
|
||||
func() fyne.CanvasObject {
|
||||
return widget.NewLabel("template")
|
||||
},
|
||||
func(i widget.ListItemID, o fyne.CanvasObject) {
|
||||
block := o.(*widget.Label)
|
||||
block.SetText(languages[i].Title)
|
||||
})
|
||||
listView.OnSelected = func(id widget.ListItemID) {
|
||||
funcSelected(languages[id])
|
||||
}
|
||||
|
||||
messageHead := lang.L("languageSelectionHead")
|
||||
return widget.NewCard(messageHead, "", listView)
|
||||
}
|
140
internal/gui/window/main.go
Normal file
140
internal/gui/window/main.go
Normal file
@@ -0,0 +1,140 @@
|
||||
package window
|
||||
|
||||
import (
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/lang"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/application"
|
||||
)
|
||||
|
||||
type MainWindowContract interface {
|
||||
SetContent(content fyne.CanvasObject)
|
||||
Show()
|
||||
InitLayout()
|
||||
}
|
||||
|
||||
type mainWindow struct {
|
||||
fyneWindow fyne.Window
|
||||
layout *fyne.Container
|
||||
progressBarService application.ProgressBarContract
|
||||
}
|
||||
|
||||
func NewMainWindow(fyneWindow fyne.Window, progressBarService application.ProgressBarContract) MainWindowContract {
|
||||
fyneWindow.Resize(fyne.Size{Width: 1039, Height: 599})
|
||||
fyneWindow.CenterOnScreen()
|
||||
|
||||
return &mainWindow{
|
||||
fyneWindow: fyneWindow,
|
||||
progressBarService: progressBarService,
|
||||
}
|
||||
}
|
||||
|
||||
func (w *mainWindow) InitLayout() {
|
||||
fyne.Do(func() {
|
||||
rContainer := newRightContainer(w.progressBarService.GetContainer())
|
||||
layout := container.NewAdaptiveGrid(2, widget.NewLabel(""), rContainer.GetCanvasObject())
|
||||
w.fyneWindow.SetContent(layout)
|
||||
|
||||
w.layout = layout
|
||||
})
|
||||
}
|
||||
|
||||
func (w *mainWindow) SetContent(content fyne.CanvasObject) {
|
||||
fyne.Do(func() {
|
||||
if w.layout == nil {
|
||||
w.fyneWindow.SetContent(content)
|
||||
return
|
||||
}
|
||||
|
||||
w.layout.Objects[0] = content
|
||||
w.fyneWindow.SetContent(w.layout)
|
||||
})
|
||||
}
|
||||
|
||||
func (w *mainWindow) Show() {
|
||||
w.fyneWindow.Show()
|
||||
}
|
||||
|
||||
type RightMainContainerContract interface {
|
||||
GetCanvasObject() fyne.CanvasObject
|
||||
GetTabs() *container.AppTabs
|
||||
GetAddedFilesContainer() *fyne.Container
|
||||
GetFileQueueContainer() *fyne.Container
|
||||
SelectFileQueueTab()
|
||||
SelectAddedFilesTab()
|
||||
}
|
||||
|
||||
type rightMainContainer struct {
|
||||
container fyne.CanvasObject
|
||||
|
||||
tabs *container.AppTabs
|
||||
|
||||
addedFilesContainer *fyne.Container
|
||||
addedFilesTab *container.TabItem
|
||||
|
||||
fileQueueContainer *fyne.Container
|
||||
fileQueueTab *container.TabItem
|
||||
}
|
||||
|
||||
func newRightContainer(blockProgressbar *fyne.Container) RightMainContainerContract {
|
||||
|
||||
addedFilesContainer := container.NewVBox()
|
||||
addedFilesTab := container.NewTabItem(lang.L("addedFilesTitle"), addedFilesContainer)
|
||||
|
||||
fileQueueContainer := container.NewVBox()
|
||||
fileQueueTab := container.NewTabItem(lang.L("fileQueueTitle"), fileQueueContainer)
|
||||
|
||||
tabs := container.NewAppTabs(
|
||||
addedFilesTab,
|
||||
fileQueueTab,
|
||||
)
|
||||
|
||||
rightContainer := container.NewBorder(
|
||||
container.NewVBox(
|
||||
blockProgressbar,
|
||||
widget.NewSeparator(),
|
||||
),
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
tabs,
|
||||
)
|
||||
|
||||
return &rightMainContainer{
|
||||
container: rightContainer,
|
||||
tabs: tabs,
|
||||
addedFilesContainer: addedFilesContainer,
|
||||
addedFilesTab: addedFilesTab,
|
||||
fileQueueContainer: fileQueueContainer,
|
||||
fileQueueTab: fileQueueTab,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *rightMainContainer) GetCanvasObject() fyne.CanvasObject {
|
||||
return r.container
|
||||
}
|
||||
|
||||
func (r *rightMainContainer) GetTabs() *container.AppTabs {
|
||||
return r.tabs
|
||||
}
|
||||
|
||||
func (r *rightMainContainer) GetAddedFilesContainer() *fyne.Container {
|
||||
return r.addedFilesContainer
|
||||
}
|
||||
|
||||
func (r *rightMainContainer) GetFileQueueContainer() *fyne.Container {
|
||||
return r.fileQueueContainer
|
||||
}
|
||||
|
||||
func (r *rightMainContainer) SelectFileQueueTab() {
|
||||
fyne.Do(func() {
|
||||
r.tabs.Select(r.fileQueueTab)
|
||||
})
|
||||
}
|
||||
|
||||
func (r *rightMainContainer) SelectAddedFilesTab() {
|
||||
fyne.Do(func() {
|
||||
r.tabs.Select(r.addedFilesTab)
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user