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

Can not scroll to target row for long table. [bug] #678

Open
daiwhea opened this issue Jun 17, 2023 · 0 comments
Open

Can not scroll to target row for long table. [bug] #678

daiwhea opened this issue Jun 17, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@daiwhea
Copy link
Contributor

daiwhea commented Jun 17, 2023

What happend?

I want to display a long [up to 5000+rows] and complicated [more than 10+ columns] table, and jump to a target row. But the table content is not fixed, it is computed by some condition. And after it was computed and displayed, it should jump to that target row.

I have tried the code from here: #397 (comment)

It does work for existed and simple table. But if I increased rows up to 5000 and create table content dynamically, it won't jump to that row. And if you move mouse, it will jump after mouse moving. I think this may because I haven't ask giu Update correctly, but it won't work with g.Update() called.

Code example

main.go
// put your code here!

package main

import (
	g "github.com/AllenDang/giu"
	"github.com/AllenDang/imgui-go"
)

var (
	scrollTrigger bool
	scrollIndex   int
	lines         []*g.TableRowWidget
)

func loop() {
	g.SingleWindow().Layout(
		g.Button("Scroll to row 448").OnClick(func() {
			createLines(5000)
			scrollTrigger = true
			scrollIndex = 448
			// g.Update() // add this line doesn't work as wanted
		}),
		g.Table().Columns(g.TableColumn("Col1"), g.TableColumn("a"), g.TableColumn("b"), g.TableColumn("c"), g.TableColumn("d"), g.TableColumn("e"), g.TableColumn("f"), g.TableColumn("g"), g.TableColumn("h"), g.TableColumn("i")).Rows(lines...),
	)
}

func main() {
	wnd := g.NewMasterWindow("Hello world", 600, 200, 0)
	wnd.Run(loop)
}

func createLines(total int) {
	for i := 0; i < total; i++ {
		index := i
		lines = append(lines, g.TableRow(g.Custom(func() {
			g.Labelf("Label %d", index).Build()
			if scrollTrigger {
				if scrollIndex == index {
					imgui.SetScrollHereY(0.5)
					scrollTrigger = false
				}
			}
		}), g.Label("aa"), g.Label("bb"), g.Label("cc"), g.Label("d"), g.Label("e"), g.Label("f"), g.Label("g"), g.Label("h"), g.Label("i")))
	}
}

To Reproduce

  1. Run my demo
  2. You may see it haven't jump to the target. If your pc is very well, maybe you should increase rows to 10000.

Version

master

OS

macOS Monterey 12.6.5

@daiwhea daiwhea added the bug Something isn't working label Jun 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant