cogentcore / core

A free and open source framework for building powerful, fast, elegant 2D and 3D apps that run on macOS, Windows, Linux, iOS, Android, and the web with a single Go codebase, allowing you to Code Once, Run Everywhere.
http://cogentcore.org/core
BSD 3-Clause "New" or "Revised" License
1.74k stars 82 forks source link

Wrapping list text does not get enough width when updated repeatedly #1209

Open kkoreilly opened 1 month ago

kkoreilly commented 1 month ago

Describe the bug

With the example code provided and lines 383-387 (ListBase.StyleValue) commented out in core/list.go, the list text gets very little width and stretches far vertically as a result. It goes back and forth between the right width and the wrong width when you resize the window.

Also, if you comment out the entire goroutine updating block of the example code, then things are rendered correctly, but the number of visible rows is computed erroneously based on the same vertically stretched layout, so it only shows four rows at a time even when more space is available. It also occasionally shows the vertically stretched version as you resize the window.

This situation arose in Cogent Mail.

How to reproduce

See above.

Example code

func main() {
    core.AddValueType[string, core.Text]()
    b := core.NewBody()
    sl := []string{}
    for range 10 {
        sl = append(sl, "Hello world this is a long sentence")
    }
    ls := core.NewList(b).SetSlice(&sl)
    ls.SetReadOnly(true)
    go func() {
        for range time.Tick(time.Second / 30) {
            ls.AsyncLock()
            ls.SetSlice(&sl).Update()
            ls.AsyncUnlock()
        }
    }()
    b.RunMainWindow()
}

Relevant output

No response

Platform

macOS

kkoreilly commented 1 month ago

This is a relatively hard problem to solve, and there are no real use cases in which this matters; for Cogent Mail, we don't want the text to wrap anyway (see https://github.com/cogentcore/cogent/commit/74ad9f332efc5cc228da0be4c78f97cb46c8807e). Therefore, this is a low priority.