Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ListBox: rows blank & OnSelect not working after toggling ListBox #22

Closed
Suremeo opened this issue Jun 27, 2024 · 1 comment
Closed
Assignees

Comments

@Suremeo
Copy link
Contributor

Suremeo commented Jun 27, 2024

Its kind of hard to explain, but here is an example of the issue

package main

import (
	"fmt"
	"github.com/roblillack/spot"
	"github.com/roblillack/spot/ui"
	"time"
)

func main() {
	ui.Init()
	spot.BuildFn(func(ctx *spot.RenderContext) spot.Component {
		toggle, setToggle := spot.UseState[bool](ctx, true)

		components := []spot.Component{
			&ui.Button{
				Width:  200,
				Height: 20,
				Title:  "toggle",
				OnClick: func() {
					setToggle(!toggle)
				},
			},
		}

		if toggle {
			components = append(components, &ui.ListBox{
				Y:         20,
				Width:     200,
				Height:    180,
				Values:    []string{"Item 1", "Item 2"},
				Selection: []int{0},
				OnSelect: func(ints []int) {
					fmt.Printf("Selected %v at %v\n", ints[0], time.Now().Unix())
				},
			})
		}

		return &ui.Window{
			Title:    "Issue #22",
			Width:    200,
			Height:   200,
			Children: components,
		}
	}).Mount()

	ui.Run()
}

When the program starts, it works fine, but when you press toggle, then press toggle again, the rows are all blank, and the OnSelect callback is broken, even though the values are being passed through the exact same way.

This is a problem because if you want to have a multi-page app it breaks functionality for the ListBox, other components seem to function as expected when doing the same type of test

@Suremeo Suremeo changed the title texteditor: rows blank & OnSelect not working after toggling texteditor ListBox: rows blank & OnSelect not working after toggling ListBox Jun 27, 2024
@roblillack
Copy link
Owner

Hey @Suremeo, thanks for reporting this issue (including the nice testcase). It should be working as expected, now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants