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

Using TableSetupScrollFreeze causes MultiSelect to skip items when scrolling upwards in a Table #7821

Closed
bratpilz opened this issue Jul 26, 2024 · 4 comments

Comments

@bratpilz
Copy link

Version/Branch of Dear ImGui:

Version 1.91.0 WIP (19099), Branch: docking

Back-ends:

imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp

Compiler, OS:

Linux + GCC

Full config/build information:

Dear ImGui 1.91.0 WIP (19099)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=201103
define: __linux__
define: __GNUC__=12
define: IMGUI_HAS_VIEWPORT
define: IMGUI_HAS_DOCK
--------------------------------
io.BackendPlatformName: imgui_impl_glfw
io.BackendRendererName: imgui_impl_opengl3
io.ConfigFlags: 0x00000483
 NavEnableKeyboard
 NavEnableGamepad
 DockingEnable
 ViewportsEnable
io.ConfigViewportsNoDecoration
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x00001C0E
 HasMouseCursors
 HasSetMousePos
 PlatformHasViewports
 HasMouseHoveredViewport
 RendererHasVtxOffset
 RendererHasViewports
--------------------------------
io.Fonts: 1 fonts, Flags: 0x00000000, TexSize: 512,64
io.DisplaySize: 1280.00,720.00
io.DisplayFramebufferScale: 1.00,1.00
--------------------------------
style.WindowPadding: 8.00,8.00
style.WindowBorderSize: 1.00
style.FramePadding: 4.00,3.00
style.FrameRounding: 0.00
style.FrameBorderSize: 0.00
style.ItemSpacing: 8.00,4.00
style.ItemInnerSpacing: 4.00,4.00

Details:

My Issue/Question:

Hello! While trying out the new MultiSelect functionality, I noticed that it doesn't play nice with TableSetupScrollFreeze as of now, and the box selection skips items when scrolling upwards. You can see what I mean in the attached example video and code.
Can you see an easy way to make this work? Thanks in advance!

Screenshots/Video:

freeze-multi-select-issue.mp4

Minimal, Complete and Verifiable Example code:

// Here's some code anyone can copy and paste to reproduce your issue
	{
	  using namespace ImGui;
	  SetNextWindowSize (ImVec2 (400.0f, 300.0f), ImGuiCond_Appearing);
	  Begin ("Test");
	  static bool freeze_header = true;
	  Checkbox ("Freeze header", &freeze_header);
	  static ImGuiSelectionBasicStorage selection;
	  if (BeginTable ("Table", 1, ImGuiTableFlags_ScrollY, GetContentRegionAvail()))
	    {
	      TableSetupColumn ("Column");
	      if (freeze_header)
		TableSetupScrollFreeze (0, 1);
	      TableHeadersRow();

	      static unsigned const N = 100;
	      auto ms = BeginMultiSelect (ImGuiMultiSelectFlags_BoxSelect1d, selection.Size, N);
	      selection.ApplyRequests (ms);

	      for (unsigned i = 0; i < N; ++i)
		{
		  TableNextColumn();
		  SetNextItemSelectionUserData (i);
		  char label[32];
		  snprintf (label, sizeof label, "Row %d", i);
		  Selectable (label, selection.Contains (i));
		}

	      ms = EndMultiSelect();
	      selection.ApplyRequests (ms);

	      EndTable();
	    }
	  End();
	}
@ocornut
Copy link
Owner

ocornut commented Jul 26, 2024

It seems like the edge of the box-select rectangle should be corrected to exclude the frozen rows and be limited to the scrollable region.

It's important that this rectangle is limited to the correct area as box-select does a selection/unselect when an item cross the boundaries between old and new rectangles, and an item exactly under the frozen row will be clipped.

@ocornut ocornut added the bug label Jul 26, 2024
@ocornut
Copy link
Owner

ocornut commented Jul 26, 2024

This is analogous to the fix we did for #5143 and namely 0b4a1a4, for some reason adding + ImVec2(window->DecoInnerSizeX1, window->DecoInnerSizeY1) to scope_rect in EndMultiSelect() doesn't seem to be enough, I'll try to look at this on Monday when I have more time.

ocornut added a commit that referenced this issue Jul 29, 2024
…actual freezing due to zero scrolling. (#7821, #5143)

Amend 0b4a1a4
(ignore whitespace to view this patch easily)
ocornut added a commit that referenced this issue Jul 29, 2024
@ocornut
Copy link
Owner

ocornut commented Jul 29, 2024

Should be fixed by 249d5ca and b847c41. Thanks for reporting!

@ocornut ocornut closed this as completed Jul 29, 2024
@bratpilz
Copy link
Author

Thank you!

ocornut added a commit that referenced this issue Sep 12, 2024
…while drag-scrolling in a table with outer borders. (#7970, #7821).

See "widgets_multiselect_boxselect_2" test.
ocornut added a commit to ocornut/imgui_test_engine that referenced this issue Sep 12, 2024
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