MCPcopy Create free account
hub / github.com/KebsCS/KBotExt / TabBarScrollToTab

Method TabBarScrollToTab

KBotExt/imgui/imgui_widgets.cpp:7999–8030  ·  view source on GitHub ↗

Note: we may scroll to tab that are not selected! e.g. using keyboard arrow keys

Source from the content-addressed store, hash-verified

7997
7998// Note: we may scroll to tab that are not selected! e.g. using keyboard arrow keys
7999static 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
8032void ImGui::TabBarQueueFocus(ImGuiTabBar* tab_bar, ImGuiTabItem* tab)
8033{

Callers

nothing calls this directly

Calls 3

TabBarGetTabOrderFunction · 0.85
ImMaxFunction · 0.85

Tested by

no test coverage detected