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

[Feature Request] Looking for a way to scroll Table to make a specific element in it visible #502

Open
rasteric opened this issue Apr 26, 2022 · 1 comment
Labels
question Further information is requested

Comments

@rasteric
Copy link

rasteric commented Apr 26, 2022

Related problem

The problem is that many lists have a selection and it is common to make this selection visible when the list is displayed. Unfortunately, I haven't found a way so far to do this programmatically. Ideally, I'd like to center my selection in the visible listbox

Your request

A way to programmatically scroll to the nth-row in a TableWidget, either with a semantics that this row n is centered in the display or such that row n is the topmost row in the display. Suggested API: ScrollToRow(n int)

List-Example

Alternative solution

I've read up on imgui and found that there are some ways to set scroll positions X and Y, but so far my attempts to change the scroll position in a TableWidget have just resulted in program crashes. No workaround known to me at this time.

Additional context

No response

@rasteric rasteric added the enhancement New feature or request label Apr 26, 2022
@gucio321
Copy link
Collaborator

gucio321 commented May 8, 2022

meh, I see the problemm. you need to use native imgui's implementation of table (imgui.BeginTable/imgui.EndTable) because you need to add your own scroll handling before imgui.EndTable call.
It is how I got that imgui.GetScrollY (and probably SetScrollY) working.

Here is my code that reports scrolling position
package main

import (
	"fmt"
	"strconv"

	"github.com/AllenDang/giu"
	"github.com/AllenDang/imgui-go"
)

const numTableRows = 50

func loop() {
	defaultFlags := giu.TableFlagsResizable | giu.TableFlagsBorders | giu.TableFlagsScrollY
	giu.SingleWindow().Layout(
		giu.Custom(func() {
			imgui.BeginTable("myTable", 1, imgui.TableFlags(defaultFlags), imgui.Vec2{-1, -1}, 0)
			for i := 0; i < numTableRows; i++ {
				giu.Label(strconv.Itoa(i)).Build()
				imgui.TableNextColumn()
			}

			imgui.EndTable()

			fmt.Println(imgui.ScrollY())
		}),
	)
}

func main() {
	wnd := giu.NewMasterWindow("Scroll table from code [Issue 502]", 640, 480, 0)
	wnd.Run(loop)
}

@gucio321 gucio321 added question Further information is requested and removed enhancement New feature or request labels May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants