Note: we may scroll to tab that are not selected! e.g. using keyboard arrow keys
| 7997 | |
| 7998 | // Note: we may scroll to tab that are not selected! e.g. using keyboard arrow keys |
| 7999 | static void ImGui::TabBarScrollToTab(ImGuiTabBar* tab_bar, ImGuiID tab_id, ImGuiTabBarSection* sections) |
| 8000 | { |
| 8001 | ImGuiTabItem* tab = TabBarFindTabByID(tab_bar, tab_id); |
| 8002 | if (tab == NULL) |
| 8003 | return; |
| 8004 | if (tab->Flags & ImGuiTabItemFlags_SectionMask_) |
| 8005 | return; |
| 8006 | |
| 8007 | ImGuiContext& g = *GImGui; |
| 8008 | float margin = g.FontSize * 1.0f; // When to scroll to make Tab N+1 visible always make a bit of N visible to suggest more scrolling area (since we don't have a scrollbar) |
| 8009 | int order = TabBarGetTabOrder(tab_bar, tab); |
| 8010 | |
| 8011 | // Scrolling happens only in the central section (leading/trailing sections are not scrolling) |
| 8012 | float scrollable_width = TabBarCalcScrollableWidth(tab_bar, sections); |
| 8013 | |
| 8014 | // We make all tabs positions all relative Sections[0].Width to make code simpler |
| 8015 | float tab_x1 = tab->Offset - sections[0].Width + (order > sections[0].TabCount - 1 ? -margin : 0.0f); |
| 8016 | float tab_x2 = tab->Offset - sections[0].Width + tab->Width + (order + 1 < tab_bar->Tabs.Size - sections[2].TabCount ? margin : 1.0f); |
| 8017 | tab_bar->ScrollingTargetDistToVisibility = 0.0f; |
| 8018 | if (tab_bar->ScrollingTarget > tab_x1 || (tab_x2 - tab_x1 >= scrollable_width)) |
| 8019 | { |
| 8020 | // Scroll to the left |
| 8021 | tab_bar->ScrollingTargetDistToVisibility = ImMax(tab_bar->ScrollingAnim - tab_x2, 0.0f); |
| 8022 | tab_bar->ScrollingTarget = tab_x1; |
| 8023 | } |
| 8024 | else if (tab_bar->ScrollingTarget < tab_x2 - scrollable_width) |
| 8025 | { |
| 8026 | // Scroll to the right |
| 8027 | tab_bar->ScrollingTargetDistToVisibility = ImMax((tab_x1 - scrollable_width) - tab_bar->ScrollingAnim, 0.0f); |
| 8028 | tab_bar->ScrollingTarget = tab_x2 - scrollable_width; |
| 8029 | } |
| 8030 | } |
| 8031 | |
| 8032 | void ImGui::TabBarQueueFocus(ImGuiTabBar* tab_bar, ImGuiTabItem* tab) |
| 8033 | { |
nothing calls this directly
no test coverage detected