MCPcopy Create free account
hub / github.com/Wemino/MarkerPatch / TabBarScrollingButtons

Method TabBarScrollingButtons

include/imgui/imgui_widgets.cpp:10411–10472  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10409}
10410
10411static ImGuiTabItem* ImGui::TabBarScrollingButtons(ImGuiTabBar* tab_bar)
10412{
10413 ImGuiContext& g = *GImGui;
10414 ImGuiWindow* window = g.CurrentWindow;
10415
10416 const ImVec2 arrow_button_size(g.FontSize - 2.0f, g.FontSize + g.Style.FramePadding.y * 2.0f);
10417 const float scrolling_buttons_width = arrow_button_size.x * 2.0f;
10418
10419 const ImVec2 backup_cursor_pos = window->DC.CursorPos;
10420 //window->DrawList->AddRect(ImVec2(tab_bar->BarRect.Max.x - scrolling_buttons_width, tab_bar->BarRect.Min.y), ImVec2(tab_bar->BarRect.Max.x, tab_bar->BarRect.Max.y), IM_COL32(255,0,0,255));
10421
10422 int select_dir = 0;
10423 ImVec4 arrow_col = g.Style.Colors[ImGuiCol_Text];
10424 arrow_col.w *= 0.5f;
10425
10426 PushStyleColor(ImGuiCol_Text, arrow_col);
10427 PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0));
10428 PushItemFlag(ImGuiItemFlags_ButtonRepeat | ImGuiItemFlags_NoNav, true);
10429 const float backup_repeat_delay = g.IO.KeyRepeatDelay;
10430 const float backup_repeat_rate = g.IO.KeyRepeatRate;
10431 g.IO.KeyRepeatDelay = 0.250f;
10432 g.IO.KeyRepeatRate = 0.200f;
10433 float x = ImMax(tab_bar->BarRect.Min.x, tab_bar->BarRect.Max.x - scrolling_buttons_width);
10434 window->DC.CursorPos = ImVec2(x, tab_bar->BarRect.Min.y);
10435 if (ArrowButtonEx("##<", ImGuiDir_Left, arrow_button_size, ImGuiButtonFlags_PressedOnClick))
10436 select_dir = -1;
10437 window->DC.CursorPos = ImVec2(x + arrow_button_size.x, tab_bar->BarRect.Min.y);
10438 if (ArrowButtonEx("##>", ImGuiDir_Right, arrow_button_size, ImGuiButtonFlags_PressedOnClick))
10439 select_dir = +1;
10440 PopItemFlag();
10441 PopStyleColor(2);
10442 g.IO.KeyRepeatRate = backup_repeat_rate;
10443 g.IO.KeyRepeatDelay = backup_repeat_delay;
10444
10445 ImGuiTabItem* tab_to_scroll_to = NULL;
10446 if (select_dir != 0)
10447 if (ImGuiTabItem* tab_item = TabBarFindTabByID(tab_bar, tab_bar->SelectedTabId))
10448 {
10449 int selected_order = TabBarGetTabOrder(tab_bar, tab_item);
10450 int target_order = selected_order + select_dir;
10451
10452 // Skip tab item buttons until another tab item is found or end is reached
10453 while (tab_to_scroll_to == NULL)
10454 {
10455 // If we are at the end of the list, still scroll to make our tab visible
10456 tab_to_scroll_to = &tab_bar->Tabs[(target_order >= 0 && target_order < tab_bar->Tabs.Size) ? target_order : selected_order];
10457
10458 // Cross through buttons
10459 // (even if first/last item is a button, return it so we can update the scroll)
10460 if (tab_to_scroll_to->Flags & ImGuiTabItemFlags_Button)
10461 {
10462 target_order += select_dir;
10463 selected_order += select_dir;
10464 tab_to_scroll_to = (target_order < 0 || target_order >= tab_bar->Tabs.Size) ? tab_to_scroll_to : NULL;
10465 }
10466 }
10467 }
10468 window->DC.CursorPos = backup_cursor_pos;

Callers

nothing calls this directly

Calls 4

ImVec4Class · 0.85
ImMaxFunction · 0.85
ImVec2Function · 0.85
TabBarGetTabOrderFunction · 0.85

Tested by

no test coverage detected