core icon indicating copy to clipboard operation
core copied to clipboard

Wrapping list text does not get enough width when updated repeatedly

Open kkoreilly opened this issue 1 year ago • 1 comments

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 avatar Sep 08 '24 16:09 kkoreilly

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.

kkoreilly avatar Sep 08 '24 22:09 kkoreilly