@@ -710,6 +710,13 @@ bool ImGui::CollapseButton(ImGuiID id, const ImVec2& pos)
710
710
return pressed;
711
711
}
712
712
713
+ ImGuiID ImGui::GetScrollbarID (ImGuiLayoutType direction)
714
+ {
715
+ ImGuiContext& g = *GImGui;
716
+ ImGuiWindow* window = g.CurrentWindow ;
717
+ return window->GetID ((direction == ImGuiLayoutType_Horizontal) ? " #SCROLLX" : " #SCROLLY" );
718
+ }
719
+
713
720
// Vertical/Horizontal scrollbar
714
721
// The entire piece of code below is rather confusing because:
715
722
// - We handle absolute seeking (when first clicking outside the grab) and relative manipulation (afterward or when clicking inside the grab)
@@ -722,8 +729,8 @@ void ImGui::Scrollbar(ImGuiLayoutType direction)
722
729
723
730
const bool horizontal = (direction == ImGuiLayoutType_Horizontal);
724
731
const ImGuiStyle& style = g.Style ;
725
- const ImGuiID id = window-> GetID (horizontal ? " #SCROLLX " : " #SCROLLY " );
726
-
732
+ const ImGuiID id = GetScrollbarID (direction );
733
+
727
734
// Render background
728
735
bool other_scrollbar = (horizontal ? window->ScrollbarY : window->ScrollbarX );
729
736
float other_scrollbar_size_w = other_scrollbar ? style.ScrollbarSize : 0 .0f ;
@@ -734,9 +741,21 @@ void ImGui::Scrollbar(ImGuiLayoutType direction)
734
741
: ImRect (window_rect.Max .x - style.ScrollbarSize , window->Pos .y + border_size, window_rect.Max .x - border_size, window_rect.Max .y - other_scrollbar_size_w - border_size);
735
742
if (!horizontal)
736
743
bb.Min .y += window->TitleBarHeight () + ((window->Flags & ImGuiWindowFlags_MenuBar) ? window->MenuBarHeight () : 0 .0f );
737
- if (bb.GetWidth () <= 0 .0f || bb.GetHeight () <= 0 .0f )
744
+
745
+ const float bb_height = bb.GetHeight ();
746
+ if (bb.GetWidth () <= 0 .0f || bb_height <= 0 .0f )
738
747
return ;
739
748
749
+ // When we are too small, start hiding and disabling the grab (this reduce visual noise on very small window and facilitate using the resize grab)
750
+ float alpha = 1 .0f ;
751
+ if ((direction == ImGuiLayoutType_Vertical) && bb_height < g.FontSize + g.Style .FramePadding .y * 2 .0f )
752
+ {
753
+ alpha = ImSaturate ((bb_height - g.FontSize ) / (g.Style .FramePadding .y * 2 .0f ));
754
+ if (alpha <= 0 .0f )
755
+ return ;
756
+ }
757
+ const bool allow_interaction = (alpha >= 1 .0f );
758
+
740
759
int window_rounding_corners;
741
760
if (horizontal)
742
761
window_rounding_corners = ImDrawCornerFlags_BotLeft | (other_scrollbar ? 0 : ImDrawCornerFlags_BotRight);
@@ -767,7 +786,7 @@ void ImGui::Scrollbar(ImGuiLayoutType direction)
767
786
float scroll_max = ImMax (1 .0f , win_size_contents_v - win_size_avail_v);
768
787
float scroll_ratio = ImSaturate (scroll_v / scroll_max);
769
788
float grab_v_norm = scroll_ratio * (scrollbar_size_v - grab_h_pixels) / scrollbar_size_v;
770
- if (held && grab_h_norm < 1 .0f )
789
+ if (held && allow_interaction && grab_h_norm < 1 .0f )
771
790
{
772
791
float scrollbar_pos_v = horizontal ? bb.Min .x : bb.Min .y ;
773
792
float mouse_pos_v = horizontal ? g.IO .MousePos .x : g.IO .MousePos .y ;
@@ -810,8 +829,8 @@ void ImGui::Scrollbar(ImGuiLayoutType direction)
810
829
*click_delta_to_grab_center_v = clicked_v_norm - grab_v_norm - grab_h_norm*0 .5f ;
811
830
}
812
831
813
- // Render
814
- const ImU32 grab_col = GetColorU32 (held ? ImGuiCol_ScrollbarGrabActive : hovered ? ImGuiCol_ScrollbarGrabHovered : ImGuiCol_ScrollbarGrab);
832
+ // Render grab
833
+ const ImU32 grab_col = GetColorU32 (held ? ImGuiCol_ScrollbarGrabActive : hovered ? ImGuiCol_ScrollbarGrabHovered : ImGuiCol_ScrollbarGrab, alpha );
815
834
ImRect grab_rect;
816
835
if (horizontal)
817
836
grab_rect = ImRect (ImLerp (bb.Min .x , bb.Max .x , grab_v_norm), bb.Min .y , ImMin (ImLerp (bb.Min .x , bb.Max .x , grab_v_norm) + grab_h_pixels, window_rect.Max .x ), bb.Max .y );
0 commit comments