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

Method TabBarScrollingButtons

KBotExt/imgui/imgui_widgets.cpp:8112–8171  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8110}
8111
8112static ImGuiTabItem* ImGui::TabBarScrollingButtons(ImGuiTabBar* tab_bar)
8113{
8114 ImGuiContext& g = *GImGui;
8115 ImGuiWindow* window = g.CurrentWindow;
8116
8117 const ImVec2 arrow_button_size(g.FontSize - 2.0f, g.FontSize + g.Style.FramePadding.y * 2.0f);
8118 const float scrolling_buttons_width = arrow_button_size.x * 2.0f;
8119
8120 const ImVec2 backup_cursor_pos = window->DC.CursorPos;
8121 //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));
8122
8123 int select_dir = 0;
8124 ImVec4 arrow_col = g.Style.Colors[ImGuiCol_Text];
8125 arrow_col.w *= 0.5f;
8126
8127 PushStyleColor(ImGuiCol_Text, arrow_col);
8128 PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0));
8129 const float backup_repeat_delay = g.IO.KeyRepeatDelay;
8130 const float backup_repeat_rate = g.IO.KeyRepeatRate;
8131 g.IO.KeyRepeatDelay = 0.250f;
8132 g.IO.KeyRepeatRate = 0.200f;
8133 float x = ImMax(tab_bar->BarRect.Min.x, tab_bar->BarRect.Max.x - scrolling_buttons_width);
8134 window->DC.CursorPos = ImVec2(x, tab_bar->BarRect.Min.y);
8135 if (ArrowButtonEx("##<", ImGuiDir_Left, arrow_button_size, ImGuiButtonFlags_PressedOnClick | ImGuiButtonFlags_Repeat))
8136 select_dir = -1;
8137 window->DC.CursorPos = ImVec2(x + arrow_button_size.x, tab_bar->BarRect.Min.y);
8138 if (ArrowButtonEx("##>", ImGuiDir_Right, arrow_button_size, ImGuiButtonFlags_PressedOnClick | ImGuiButtonFlags_Repeat))
8139 select_dir = +1;
8140 PopStyleColor(2);
8141 g.IO.KeyRepeatRate = backup_repeat_rate;
8142 g.IO.KeyRepeatDelay = backup_repeat_delay;
8143
8144 ImGuiTabItem* tab_to_scroll_to = NULL;
8145 if (select_dir != 0)
8146 if (ImGuiTabItem* tab_item = TabBarFindTabByID(tab_bar, tab_bar->SelectedTabId))
8147 {
8148 int selected_order = TabBarGetTabOrder(tab_bar, tab_item);
8149 int target_order = selected_order + select_dir;
8150
8151 // Skip tab item buttons until another tab item is found or end is reached
8152 while (tab_to_scroll_to == NULL)
8153 {
8154 // If we are at the end of the list, still scroll to make our tab visible
8155 tab_to_scroll_to = &tab_bar->Tabs[(target_order >= 0 && target_order < tab_bar->Tabs.Size) ? target_order : selected_order];
8156
8157 // Cross through buttons
8158 // (even if first/last item is a button, return it so we can update the scroll)
8159 if (tab_to_scroll_to->Flags & ImGuiTabItemFlags_Button)
8160 {
8161 target_order += select_dir;
8162 selected_order += select_dir;
8163 tab_to_scroll_to = (target_order < 0 || target_order >= tab_bar->Tabs.Size) ? tab_to_scroll_to : NULL;
8164 }
8165 }
8166 }
8167 window->DC.CursorPos = backup_cursor_pos;
8168 tab_bar->BarRect.Max.x -= scrolling_buttons_width + 1.0f;
8169

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