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

Function ComboAutoSelectComplex

KBotExt/Misc.h:487–752  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

485 };
486
487 inline bool ComboAutoSelectComplex(const char* label, char* input, const int inputlen, int* current_item,
488 std::vector<std::string> data, const int items_count, const ImGuiComboFlags flags)
489 {
490 // Always consume the SetNextWindowSizeConstraint() call in our early return paths
491 const ImGuiContext& g = *GImGui;
492
493 ImGuiWindow* window = GetCurrentWindow();
494 if (window->SkipItems)
495 return false;
496
497 // Call the getter to obtain the preview string which is a parameter to BeginCombo()
498
499 const ImGuiID popupId = window->GetID(label);
500 bool popupIsAlreadyOpened = IsPopupOpen(popupId, 0); //ImGuiPopupFlags_AnyPopupLevel);
501 const char* sActiveidxValue1 = nullptr;
502 itemsGetter(&data, *current_item, &sActiveidxValue1);
503 const bool popupNeedsToBeOpened = (input[0] != 0) && (sActiveidxValue1 && strcmp(input, sActiveidxValue1));
504 bool popupJustOpened = false;
505
506 IM_ASSERT(
507 (flags & (ImGuiComboFlags_NoArrowButton | ImGuiComboFlags_NoPreview)) != (ImGuiComboFlags_NoArrowButton | ImGuiComboFlags_NoPreview));
508 // Can't use both flags together
509
510 const ImGuiStyle& style = g.Style;
511
512 const float arrow_size = flags & ImGuiComboFlags_NoArrowButton ? 0.0f : GetFrameHeight();
513 const ImVec2 label_size = CalcTextSize(label, nullptr, true);
514 const float expected_w = CalcItemWidth();
515 const float w = flags & ImGuiComboFlags_NoPreview ? arrow_size : expected_w;
516 const ImRect frame_bb(window->DC.CursorPos,
517 ImVec2(window->DC.CursorPos.x + w, window->DC.CursorPos.y + label_size.y + style.FramePadding.y * 2.0f));
518 const ImRect total_bb(frame_bb.Min, ImVec2((label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f) + frame_bb.Max.x,
519 frame_bb.Max.y));
520 const float value_x2 = ImMax(frame_bb.Min.x, frame_bb.Max.x - arrow_size);
521 ItemSize(total_bb, style.FramePadding.y);
522 if (!ItemAdd(total_bb, popupId, &frame_bb))
523 return false;
524
525 bool hovered, held;
526 const bool pressed = ButtonBehavior(frame_bb, popupId, &hovered, &held);
527
528 if (!popupIsAlreadyOpened)
529 {
530 const ImU32 frame_col = GetColorU32(hovered ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg);
531 RenderNavHighlight(frame_bb, popupId);
532 if (!(flags & ImGuiComboFlags_NoPreview))
533 window->DrawList->AddRectFilled(frame_bb.Min, ImVec2(value_x2, frame_bb.Max.y), frame_col, style.FrameRounding,
534 (flags & ImGuiComboFlags_NoArrowButton) ? ImDrawFlags_RoundCornersAll : ImDrawFlags_RoundCornersLeft);
535 }
536 if (!(flags & ImGuiComboFlags_NoArrowButton))
537 {
538 const ImU32 bg_col = GetColorU32((popupIsAlreadyOpened || hovered) ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
539 const ImU32 text_col = GetColorU32(ImGuiCol_Text);
540 window->DrawList->AddRectFilled(ImVec2(value_x2, frame_bb.Min.y), frame_bb.Max, bg_col, style.FrameRounding,
541 (w <= arrow_size) ? ImDrawFlags_RoundCornersAll : ImDrawFlags_RoundCornersRight);
542 if (value_x2 + arrow_size - style.FramePadding.x <= frame_bb.Max.x)
543 RenderArrow(window->DrawList, ImVec2(value_x2 + style.FramePadding.y, frame_bb.Min.y + style.FramePadding.y), text_col, ImGuiDir_Down,
544 1.0f);

Callers 1

ComboAutoSelectFunction · 0.85

Calls 12

GetCurrentWindowFunction · 0.85
itemsGetterFunction · 0.85
ImVec2Function · 0.85
ImMaxFunction · 0.85
ItemSizeFunction · 0.85
ImFormatStringFunction · 0.85
FuzzySearchFunction · 0.85
GetKeyIndexFunction · 0.85
GetInputTextStateFunction · 0.85
ImTextStrFromUtf8Function · 0.85
GetIDMethod · 0.80
AddRectFilledMethod · 0.80

Tested by

no test coverage detected