0

I am coding in Go and using Fyne to display a window. I have tasks that log info to this window. When I make the tasks log strings to the window at high volume the window is no longer readable and gets scaled weird. I also get the error:

UNSUPPORTED (log once): POSSIBLE ISSUE: unit 0 GLD_TEXTURE_INDEX_2D is unloadable and bound to sampler type (Float) - using zero texture because texture unloadable

I am on a MacBook Air. However I want to have a window that supports any computer, thats why I picked Fyne. How can I simply have a window with a scrollview that I can log short strings to? I added images of the broken UI and how it looks with a small amount of logs.

image

images

func appendLog(message string) {
    // I want the new text to appear at the top
    // Window is of type: *widget.Label
    process.Window.SetText(message + "\n" + Window.Text)
}

func openNewDialog(a fyne.App, taskgroup string) {
    w := a.NewWindow("Hi")

    // Set the window size
    w.Resize(fyne.NewSize(400, 300))

    // Create label and buttons
    hello := widget.NewLabel("Hello User!")
    stopButton := widget.NewButtonWithIcon("Stop tasks", theme.CancelIcon(), func() {
        
    })
    stopButton.Importance = widget.HighImportance

    // Create a checkout label
    checkoutCount := widget.NewLabel("0 checkouts")
    checkoutCount.TextStyle = fyne.TextStyle{Bold: true}
    checkoutCount.Alignment = fyne.TextAlignCenter

    // Arrange content in a vertical box layout
    content := container.NewVBox(
        container.NewHBox(stopButton, checkoutCount),
        hello,
    )

    // Wrap the content in a scroll view
    scrollableContent := container.NewVScroll(content)

    w.SetCloseIntercept(func() {
        
    })

    // Set the scrollable content as the window's content and show the window
    w.SetContent(scrollableContent)
    w.Show()
    Window = hello
}
2

2 Answers 2

1

Use the List widget, that is designed for performance. It looks like you have so much data that if you try to render it all at once in a Scroll the system can’t cope - but a List widget renders only what is on screen.

0

Thanks to @Andy.xyz for the suggestion. Here's the working code:

func openNewDialog(a fyne.App, cp *Models.ChildProcess, taskgroup string) {
    title := fmt.Sprintf("Task Group: %s", taskgroup)
    w := a.NewWindow(title)

    w.Resize(fyne.NewSize(400, 300))

    hello := widget.NewLabel("Hello User!")
    stopButton := widget.NewButtonWithIcon("Stop tasks", theme.CancelIcon(), func() {
        Models.Kill(cp)
        RemoveChildProcess(taskgroup)
    })
    stopButton.Importance = widget.HighImportance

    checkoutCount := widget.NewLabel("0 checkouts")
    checkoutCount.TextStyle = fyne.TextStyle{Bold: true}
    checkoutCount.Alignment = fyne.TextAlignCenter

    items := []fyne.CanvasObject{
        hello,
    }

    list := widget.NewList(
        func() int {
            return len(items)
        },
        func() fyne.CanvasObject {
            return widget.NewLabel("")
        },
        func(id widget.ListItemID, item fyne.CanvasObject) {
            label := item.(*widget.Label)
            label.SetText(items[id].(*widget.Label).Text)
        },
    )

    scrollableList := container.NewVScroll(list)
    scrollableList.SetMinSize(fyne.NewSize(0, 200))

    content := container.NewBorder(
        container.NewVBox(
            container.NewHBox(stopButton, checkoutCount),
        ),
        nil,
        nil,
        nil,
        scrollableList,
    )

    w.SetCloseIntercept(func() {
        Models.Kill(cp)
        RemoveChildProcess(taskgroup)
    })

    w.SetContent(content)
    w.Show()

    cp.Window = hello
    cp.Dialog = w
    cp.Items = &items
    cp.List = list
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.