diff --git a/ui/output_tab.go b/ui/output_tab.go new file mode 100644 index 0000000000000000000000000000000000000000..f8dbdc7b6c8bd58976db421ecd5237390eeb35e6 --- /dev/null +++ b/ui/output_tab.go @@ -0,0 +1,72 @@ +// 17 Feb 2022 +// Handle the output tab stuff + +// There should be three states. +// 1. initial, nothing happened yet +// 2. thinking +// 3. show results + +package ui + +import ( + "bytes" + + "fyne.io/fyne/v2" + "fyne.io/fyne/v2/canvas" + "fyne.io/fyne/v2/container" + "fyne.io/fyne/v2/widget" +) + +type status uint8 + +const ( + initial status = iota + calculating + resultsReady +) + +type workstatus struct { + fdata, xdata []byte + status status +} + +func showIniTab(cntr *fyne.Container) { + cntr.Add(widget.NewCard("No results yet", "go back to the input", nil)) +} + +func showCalcTab(cntr *fyne.Container) { + for _, c := range cntr.Objects { + cntr.Remove(c) + } + cntr.Add(widget.NewCard("calculating", "busy", nil)) + cntr.Refresh() +} + +// showResultsTab show the two plots + +func showResultsTab(cntr *fyne.Container, fdata, xdata []byte) { + for _, c := range cntr.Objects { + cntr.Remove(c) + } + fImage := canvas.NewImageFromReader(bytes.NewReader(fdata), "func.png") + fImage.FillMode = canvas.ImageFillContain + fImage.SetMinSize( fyne.Size{500, 300}) + xImage := canvas.NewImageFromReader(bytes.NewReader(xdata), "xdata.png") + xImage.FillMode = canvas.ImageFillContain + xImage.SetMinSize( fyne.Size{500, 300}) + content := container.NewGridWithRows(2, fImage, xImage) + cntr.Add(content) + +} + +func outputTab(chn chan workstatus, cntr *fyne.Container) { + showIniTab(cntr) + for s := range chn { + switch s.status { + case calculating: + showCalcTab(cntr) + case resultsReady: + showResultsTab(cntr, s.fdata, s.xdata) + } + } +}