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

Improving nested scrolling regions behavior #830

Closed
ggtucker opened this issue Sep 14, 2016 · 7 comments
Closed

Improving nested scrolling regions behavior #830

ggtucker opened this issue Sep 14, 2016 · 7 comments

Comments

@ggtucker
Copy link
Contributor

When a scrolling region is nested within another, it would be nice if the following behavior existed:

  • When the inner scroll region's scrollbar is at the top, and attempting to scroll up while hovering the inner region, the outer scroll region should take focus and scroll up.
  • When the inner scroll region's scrollbar is at the bottom, and attempting to scroll down while hovering the inner region, the outer scroll region should take focus and scroll down.

Here's an example for quickly fiddling around with this yourself:

Example Image

ImGui::Begin("WindowName");
ImGui::BeginChild("OuterRegion", ImVec2(0, -ImGui::GetItemsLineHeightWithSpacing()), false);
ImGui::Columns(2);
for (int i = 0; i < 40; ++i) {
    ImGui::Text("Entry %i", i);
    ImGui::NextColumn();
    ImGui::Text("Value %i", i);
    ImGui::NextColumn();
}
ImGui::Columns();
ImGui::BeginChild("InnerRegion", ImVec2(0, 300), false);
ImGui::Columns(2);
for (int i = 0; i < 40; ++i) {
    ImGui::Text("InnerEntry %i", i);
    ImGui::NextColumn();
    ImGui::Text("InnerValue %i", i);
    ImGui::NextColumn();
}
ImGui::Columns();
ImGui::EndChild();
ImGui::Columns(2);
for (int i = 40; i < 80; ++i) {
    ImGui::Text("Entry %i", i);
    ImGui::NextColumn();
    ImGui::Text("Value %i", i);
    ImGui::NextColumn();
}
ImGui::Columns();
ImGui::EndChild();
ImGui::End();
@ggtucker
Copy link
Contributor Author

Tangentially related, it would be nice if, when using columns in a fixed-height child region, the dividers extended to the bottom of the region (in the case that there are not enough rows to fill the region).

See below for an example:

Example Image

ImGui::Begin("WindowName");
ImGui::BeginChild("OuterRegion", ImVec2(0, -ImGui::GetItemsLineHeightWithSpacing()), false);
ImGui::Columns(2);
for (int i = 0; i < 40; ++i) {
    ImGui::Text("Entry %i", i);
    ImGui::NextColumn();
    ImGui::Text("Value %i", i);
    ImGui::NextColumn();
}
ImGui::Columns();
ImGui::Separator();
ImGui::BeginChild("InnerRegion", ImVec2(0, 150), false);
ImGui::Columns(2);
ImGui::Text("EntryHeader");
ImGui::NextColumn();
ImGui::Text("ValueHeader");
ImGui::NextColumn();
ImGui::Separator();
for (int i = 0; i < 3; ++i) {
    ImGui::Text("InnerEntry %i", i);
    ImGui::NextColumn();
    ImGui::Text("InnerValue %i", i);
    ImGui::NextColumn();
}
ImGui::Columns();
ImGui::EndChild();
ImGui::Columns(2);
ImGui::Separator();
for (int i = 40; i < 80; ++i) {
    ImGui::Text("Entry %i", i);
    ImGui::NextColumn();
    ImGui::Text("Value %i", i);
    ImGui::NextColumn();
}
ImGui::Columns();
ImGui::EndChild();
ImGui::End();

@ocornut
Copy link
Owner

ocornut commented Sep 15, 2016

Hi Geoffrey,

For the first request. I understand it in this context but I'm having a hard time figuring out it is desirable or would make sense in the general context. I think it might be but it'd be cautious. Moreover, different behavior might be desirable with mouse-wheel based scroll vs programmatic vs gamepad navigation scroll.

(Those changes are already a quite trickier than they sounds because there are a few subtle dependencies within the frame. Mouse-wheel are processed in NewFrame() and calling SetWindowScrollY() which sets ScrollY immediately - it is a rather unusual path but works since we're not in Begin/End. It may make more sense to store and defer the desirable relative scroll amount and process in Begin() once we have a contents size for the current frame, or move it all in Begin().)

Columns are a total mess at the moment, they barely changed since 1.0 and accumulating a pile of todos. What I would do right now is just to move your cursor to the bottom of the child window before closing the columns. I'm accumulating notes locally and in #513 #125 and that's one thing that will be automatically handled. Along with making it more natural and easy to line up stuff.

TL;DR; both doable, not high priority since I'm rather busy right now but I may have a look in particular at (1) since it seems less involved. Columns may need to wait for big update.

@ocornut
Copy link
Owner

ocornut commented Sep 15, 2016

For your second question, I tested this:
ImGui::SetCursorPosY(ImGui::GetWindowContentRegionMax().y);
Before the closing call to Columns() within InnerRegion and it does what you wanted.

col

The center column is still not horizontally aligned making everything looks a bit horrible but that's another problem.

@ocornut
Copy link
Owner

ocornut commented Sep 15, 2016

  1. re-
    If you want the columns set width to match between parents and child and can't wait for hypothetical refactor of Columns system, you can possibly use this silly workaround (not particularly recommended, but throwing it out there):
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(8,0));
ImGui::SetCursorPosX(0.0f);
ImGui::BeginChild("InnerRegion", ImVec2(ImGui::GetWindowWidth(), 150), false, ImGuiWindowFlags_AlwaysUseWindowPadding);
ImGui::EndChild();
ImGui::PopStyleVar();

Basically enforcing child pos and size to match.

col

@ggtucker
Copy link
Contributor Author

ggtucker commented Sep 15, 2016

Hi Omar!

Thanks for taking the time to answer my questions and looking into a solution for (1) despite your busy schedule. From an API perspective, would it make sense to pass a flag when creating the child region that determines whether or not it should pass scrolling focus to the parent? When configured, I imagine this behavior would only be associated with mouse-wheel (although maybe gamepad too?). I'm not sure it would make sense from a programmatic perspective.

As for (2), the workaround you mentioned works great for me.

Cheers,
Geoff

@ocornut
Copy link
Owner

ocornut commented Sep 23, 2016

Geoff,
Yes, a flag may be appropriate there. Would start by implementing the feature before figuring out if it needs a flag or if it can be the default. I agree that it probably doesn't make sense from the programmatic API either.

@ocornut
Copy link
Owner

ocornut commented Jan 4, 2022

Closing this old issue as it is handled by Tables and Columns are essentially legacy API at this point.

@ocornut ocornut closed this as completed Jan 4, 2022
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