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

Synced tables with a scrollbar have different column's width #5920

Closed
the-goodies opened this issue Nov 25, 2022 · 2 comments
Closed

Synced tables with a scrollbar have different column's width #5920

the-goodies opened this issue Nov 25, 2022 · 2 comments

Comments

@the-goodies
Copy link

the-goodies commented Nov 25, 2022

Two synced tables with a ImGuiTableFlags_SizingStretchSame and ImGuiTableFlags_ScrollY flags set, have different columns widths if the first table has a vertical scrollbar:

synced_tables_different_widths.mp4

Maybe this is a correct behavior and not a bug, but if I want to align those columns contents, I have to add additional spaces or do some extra layout calculations to position them correctly.
Ideally, in this particular use case there would be a way to freeze the bottom row, so it wouldn't be necessary to create those synced tables.

Code example in Go language:

columnsNum := 6
columnsSetup := func() {
	ui.TableSetupColumn("First")
	ui.TableSetupColumn("Second")
	ui.TableSetupColumn("Third")
	ui.TableSetupColumn("Fourth")
	ui.TableSetupColumn("Fifth")
	ui.TableSetupColumn("And so on")
}

tableID := "##syncedTable"
tableFlags := ui.TableFlagsSizingStretchSame | ui.TableFlagsScrollY | ui.TableFlagsBorders

if ui.BeginTableV(tableID, columnsNum, tableFlags, ui.Vec2{Y: -30}, 0) {
	columnsSetup()
	ui.TableSetupScrollFreeze(0, 1)

	ui.TableHeadersRow()
	for i := 0; i < 60; i += 1 {
		ui.TableNextRow()
		for j := 1; j <= columnsNum; j += 1 {
			ui.TableNextColumn()
			ui.Text(fmt.Sprintf("%d. %d", j, i))
		}
	}

	ui.EndTable()
}

// sum row
if ui.BeginTableV(tableID, columnsNum, tableFlags, ui.Vec2{}, 0) {
	columnsSetup()

	ui.TableNextRow()
	for j := 1; j <= columnsNum; j += 1 {
		ui.TableNextColumn()
		ui.Text(fmt.Sprintf("%d. %d", j, 252352))
	}

	ui.EndTable()
}
@ocornut ocornut added the bug label Dec 8, 2022
ocornut added a commit that referenced this issue Dec 8, 2022
…ot all) instances have a vertical scrollbar. (#5920)
@ocornut
Copy link
Owner

ocornut commented Dec 8, 2022

Thank you for reporting this issue and the repro.

I have now pushed a fix for this 317b33d
image

I have tried 3 approach:

(1)
My first attempt at fixing this was by synchronizing the value of each window DecoOuterX2 to the max of all, which left a hole on the right.

(2)
Then it seemed simpler instead to synchronize the visibility state of ScrollbarY, meaning other instances would have a full scrollbar, equivalent of using ImGuiWindowFlags_AlwaysVerticalScrollbar.

(3)
The obvious possible improvement would be to keep this region usable in instances not needing the scrolling. I've came up with a really simple way to handle that (that's the current commit) but tbh I'm not exactly sure of all the possible side-effects, as synced instanced are currently not thoroughly tested for.

For now it seems to work and passes our existing test suite.

@ocornut ocornut closed this as completed Dec 8, 2022
ocornut added a commit that referenced this issue Jul 20, 2023
…ar width of scrolling tables. (#5920, #6619)

Avoid width variation when resizing down a table hosting a child window.
+ shallow tweak to GetContentRegionMax().
ocornut added a commit that referenced this issue Jun 3, 2024
…e, previous scrollbar width would be accounted for. (#5920)

Amend 317b33d
@ocornut
Copy link
Owner

ocornut commented Jun 3, 2024

Pushed 68a05e3 which fixes a (rarely manifesting) bug with the implementation of this: when a table stops using _ScrollY flag the last scrollbar width was accounted for. I don't believe it would have affected much real world code.

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