filling ui, stuck at removing center content dynamically

This commit is contained in:
Marcel Otte 2022-03-09 23:07:07 +01:00
parent a738650ca1
commit 01d7e36a3d
1 changed files with 57 additions and 3 deletions

View File

@ -14,8 +14,10 @@ var (
config backive.Configuration
db backive.Database
accord *widget.Accordion
center *fyne.Container
accord *widget.Accordion
center *fyne.Container
devBtnList []*widget.Button
bacBtnList []*widget.Button
)
func Init(a fyne.App, w fyne.Window, c backive.Configuration, d backive.Database) {
@ -28,7 +30,59 @@ func Init(a fyne.App, w fyne.Window, c backive.Configuration, d backive.Database
func SetupLayout() {
accord = widget.NewAccordion()
devBtnList := []*widget.Button{}
devLayout := container.NewVBox()
for _, obj := range config.Devices {
btn := widget.NewButton(obj.Name, nil)
devBtnList = append(devBtnList, btn)
devLayout.Add(btn)
}
devices := widget.NewAccordionItem("Devices", devLayout)
accord.Append(devices)
bacBtnList := []*widget.Button{}
bacLayout := container.NewVBox()
for _, obj := range config.Backups {
btn := widget.NewButton(obj.Name, nil)
bacBtnList = append(bacBtnList, btn)
bacLayout.Add(btn)
}
backups := widget.NewAccordionItem("Backups", bacLayout)
accord.Append(backups)
center := container.NewMax()
content := container.New(layout.NewBorderLayout(nil, nil, accord, nil), accord, center)
left := container.NewMax()
left.Add(accord)
window.Resize(fyne.NewSize(800, 600))
content := container.New(layout.NewBorderLayout(nil, nil, left, nil), left, center)
window.SetContent(content)
// setup btns
for _, obj := range devBtnList {
obj.OnTapped = func() {
DisplayDevice(obj.Text)
}
}
}
func ClearCenter() {
if len(center.Objects) > 0 {
center.Objects = []fyne.CanvasObject{}
}
}
func DisplayDevice(dev string) {
ClearCenter()
vbox := container.NewVBox()
dataForm := container.New(layout.NewFormLayout())
vbox.Add(dataForm)
device := config.Devices[dev]
dataForm.Add(widget.NewLabel("Name"))
dataForm.Add(widget.NewLabel(device.Name))
dataForm.Add(widget.NewLabel("UUID"))
dataForm.Add(widget.NewLabel(device.UUID))
dataForm.Add(widget.NewLabel("Owner"))
dataForm.Add(widget.NewLabel(device.OwnerUser))
}
func DisplayBackup(bac string) {
ClearCenter()
}