giu icon indicating copy to clipboard operation
giu copied to clipboard

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

Open rasteric opened this issue 2 years ago • 1 comments

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 avatar Apr 26 '22 09:04 rasteric

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 avatar May 08 '22 10:05 gucio321