Imgui: Checking to see if the scrollbar was clicked

Created on 15 Jun 2017  路  4Comments  路  Source: ocornut/imgui

I don't know if this is actually missing or it's just not obvious to me.
Is there any way to check if the window scrollbar has been clicked / is being held down?

scrolling

Most helpful comment

@DaulPavid FYI there's a function ImGuiID GetScrollbarID(ImGuiWindow* window, ImGuiAxis axis) in imgui_internal.h, so you can replace the code above with:

ImGuiWindow* window = ImGui::GetCurrentWindow();
ImGuiID active_id = ImGui::GetActiveID();
bool any_scrollbar_active = active_id && (active_id == ImGui::GetScrollbarID(window, ImGuiAxis_X) || active_id == ImGui::GetScrollbarID(window, ImGuiAxis_Y)

Unlike the solution above this is not likely to ever break with future updates.

All 4 comments

The undocumented way right now would be to do GImGui->ActiveId == GImGui->CurrentWindow->GetID("#SCROLLX"); however that may break with future update.

It would be more interesting to understand why would you like to do that / what you are trying to achieve, and from there we can devise a solution.

I have both the X and Y scroll enabled on a window, and I also scroll vertically if the mouse is dragging up or down within the window. I'd like to disable vertical scrolling if the user is holding down and dragging on the bottom horizontal scrollbar because I otherwise might induce vertically scrolling while dragging the horizontal scroll bar. If needed, I'll post a visual to illustrate what I mean.

Presumably if you are capturing drags over the window, you have a widget e.g. InvisibleButton() in there covering the window so that it doesn't move? Then you can perform your own scrolling when that widget is active? I'm not sure how is your setup.

@DaulPavid FYI there's a function ImGuiID GetScrollbarID(ImGuiWindow* window, ImGuiAxis axis) in imgui_internal.h, so you can replace the code above with:

ImGuiWindow* window = ImGui::GetCurrentWindow();
ImGuiID active_id = ImGui::GetActiveID();
bool any_scrollbar_active = active_id && (active_id == ImGui::GetScrollbarID(window, ImGuiAxis_X) || active_id == ImGui::GetScrollbarID(window, ImGuiAxis_Y)

Unlike the solution above this is not likely to ever break with future updates.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mnemode2 picture mnemode2  路  3Comments

GrammarLord picture GrammarLord  路  3Comments

bizehao picture bizehao  路  3Comments

ILoveImgui picture ILoveImgui  路  3Comments

inflex picture inflex  路  3Comments