@@ -7618,6 +7618,12 @@ void ImGui::EndTabBar()
7618
7618
g.CurrentTabBar = g.CurrentTabBarStack .empty () ? NULL : GetTabBarFromTabBarRef (g.CurrentTabBarStack .back ());
7619
7619
}
7620
7620
7621
+ // Scrolling happens only in the central section (leading/trailing sections are not scrolling)
7622
+ static float TabBarCalcScrollableWidth (ImGuiTabBar* tab_bar, ImGuiTabBarSection* sections)
7623
+ {
7624
+ return tab_bar->BarRect .GetWidth () - sections[0 ].Width - sections[2 ].Width - sections[1 ].Spacing ;
7625
+ }
7626
+
7621
7627
// This is called only once a frame before by the first call to ItemTab()
7622
7628
// The reason we're not calling it in BeginTabBar() is to leave a chance to the user to call the SetTabItemClosed() functions.
7623
7629
static void ImGui::TabBarLayout (ImGuiTabBar* tab_bar)
@@ -7820,9 +7826,23 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar)
7820
7826
tab_bar->VisibleTabId = tab_bar->SelectedTabId ;
7821
7827
tab_bar->VisibleTabWasSubmitted = false ;
7822
7828
7823
- // Update scrolling
7829
+ // Apply request requests
7824
7830
if (scroll_to_tab_id != 0 )
7825
7831
TabBarScrollToTab (tab_bar, scroll_to_tab_id, sections);
7832
+ else if ((tab_bar->Flags & ImGuiTabBarFlags_FittingPolicyScroll) && IsMouseHoveringRect (tab_bar->BarRect .Min , tab_bar->BarRect .Max , true ) && IsWindowContentHoverable (g.CurrentWindow ))
7833
+ {
7834
+ const float wheel = g.IO .MouseWheelRequestAxisSwap ? g.IO .MouseWheel : g.IO .MouseWheelH ;
7835
+ const ImGuiKey wheel_key = g.IO .MouseWheelRequestAxisSwap ? ImGuiKey_MouseWheelY : ImGuiKey_MouseWheelX;
7836
+ if (TestKeyOwner (wheel_key, tab_bar->ID ) && wheel != 0 .0f )
7837
+ {
7838
+ const float scroll_step = wheel * TabBarCalcScrollableWidth (tab_bar, sections) / 3 .0f ;
7839
+ tab_bar->ScrollingTargetDistToVisibility = 0 .0f ;
7840
+ tab_bar->ScrollingTarget = TabBarScrollClamp (tab_bar, tab_bar->ScrollingTarget - scroll_step);
7841
+ }
7842
+ SetKeyOwner (wheel_key, tab_bar->ID );
7843
+ }
7844
+
7845
+ // Update scrolling
7826
7846
tab_bar->ScrollingAnim = TabBarScrollClamp (tab_bar, tab_bar->ScrollingAnim );
7827
7847
tab_bar->ScrollingTarget = TabBarScrollClamp (tab_bar, tab_bar->ScrollingTarget );
7828
7848
if (tab_bar->ScrollingAnim != tab_bar->ScrollingTarget )
@@ -7959,8 +7979,7 @@ static void ImGui::TabBarScrollToTab(ImGuiTabBar* tab_bar, ImGuiID tab_id, ImGui
7959
7979
int order = TabBarGetTabOrder (tab_bar, tab);
7960
7980
7961
7981
// Scrolling happens only in the central section (leading/trailing sections are not scrolling)
7962
- // FIXME: This is all confusing.
7963
- float scrollable_width = tab_bar->BarRect .GetWidth () - sections[0 ].Width - sections[2 ].Width - sections[1 ].Spacing ;
7982
+ float scrollable_width = TabBarCalcScrollableWidth (tab_bar, sections);
7964
7983
7965
7984
// We make all tabs positions all relative Sections[0].Width to make code simpler
7966
7985
float tab_x1 = tab->Offset - sections[0 ].Width + (order > sections[0 ].TabCount - 1 ? -margin : 0 .0f );
0 commit comments