MCPcopy Create free account
hub / github.com/clementgallet/libTAS / TabBarScrollToTab

Method TabBarScrollToTab

src/external/imgui/imgui_widgets.cpp:8281–8312  ·  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

8279
8280// Note: we may scroll to tab that are not selected! e.g. using keyboard arrow keys
8281static void ImGui::TabBarScrollToTab(ImGuiTabBar* tab_bar, ImGuiID tab_id, ImGuiTabBarSection* sections)
8282{
8283 ImGuiTabItem* tab = TabBarFindTabByID(tab_bar, tab_id);
8284 if (tab == NULL)
8285 return;
8286 if (tab->Flags & ImGuiTabItemFlags_SectionMask_)
8287 return;
8288
8289 ImGuiContext& g = *GImGui;
8290 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)
8291 int order = TabBarGetTabOrder(tab_bar, tab);
8292
8293 // Scrolling happens only in the central section (leading/trailing sections are not scrolling)
8294 float scrollable_width = TabBarCalcScrollableWidth(tab_bar, sections);
8295
8296 // We make all tabs positions all relative Sections[0].Width to make code simpler
8297 float tab_x1 = tab->Offset - sections[0].Width + (order > sections[0].TabCount - 1 ? -margin : 0.0f);
8298 float tab_x2 = tab->Offset - sections[0].Width + tab->Width + (order + 1 < tab_bar->Tabs.Size - sections[2].TabCount ? margin : 1.0f);
8299 tab_bar->ScrollingTargetDistToVisibility = 0.0f;
8300 if (tab_bar->ScrollingTarget > tab_x1 || (tab_x2 - tab_x1 >= scrollable_width))
8301 {
8302 // Scroll to the left
8303 tab_bar->ScrollingTargetDistToVisibility = ImMax(tab_bar->ScrollingAnim - tab_x2, 0.0f);
8304 tab_bar->ScrollingTarget = tab_x1;
8305 }
8306 else if (tab_bar->ScrollingTarget < tab_x2 - scrollable_width)
8307 {
8308 // Scroll to the right
8309 tab_bar->ScrollingTargetDistToVisibility = ImMax((tab_x1 - scrollable_width) - tab_bar->ScrollingAnim, 0.0f);
8310 tab_bar->ScrollingTarget = tab_x2 - scrollable_width;
8311 }
8312}
8313
8314void ImGui::TabBarQueueFocus(ImGuiTabBar* tab_bar, ImGuiTabItem* tab)
8315{

Callers

nothing calls this directly

Calls 3

TabBarGetTabOrderFunction · 0.85
ImMaxFunction · 0.85

Tested by

no test coverage detected