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

Method ButtonBehavior

KBotExt/imgui/imgui_widgets.cpp:478–678  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

476//-------------------------------------------------------------------------------------------------------------------------------------------------
477
478bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool* out_held, ImGuiButtonFlags flags)
479{
480 ImGuiContext& g = *GImGui;
481 ImGuiWindow* window = GetCurrentWindow();
482
483 // Default only reacts to left mouse button
484 if ((flags & ImGuiButtonFlags_MouseButtonMask_) == 0)
485 flags |= ImGuiButtonFlags_MouseButtonDefault_;
486
487 // Default behavior requires click + release inside bounding box
488 if ((flags & ImGuiButtonFlags_PressedOnMask_) == 0)
489 flags |= ImGuiButtonFlags_PressedOnDefault_;
490
491 // Default behavior inherited from item flags
492 // Note that _both_ ButtonFlags and ItemFlags are valid sources, so copy one into the item_flags and only check that.
493 ImGuiItemFlags item_flags = (g.LastItemData.ID == id ? g.LastItemData.InFlags : g.CurrentItemFlags);
494 if (flags & ImGuiButtonFlags_AllowOverlap)
495 item_flags |= ImGuiItemFlags_AllowOverlap;
496 if (flags & ImGuiButtonFlags_Repeat)
497 item_flags |= ImGuiItemFlags_ButtonRepeat;
498
499 ImGuiWindow* backup_hovered_window = g.HoveredWindow;
500 const bool flatten_hovered_children = (flags & ImGuiButtonFlags_FlattenChildren) && g.HoveredWindow && g.HoveredWindow->RootWindow == window;
501 if (flatten_hovered_children)
502 g.HoveredWindow = window;
503
504#ifdef IMGUI_ENABLE_TEST_ENGINE
505 // Alternate registration spot, for when caller didn't use ItemAdd()
506 if (id != 0 && g.LastItemData.ID != id)
507 IMGUI_TEST_ENGINE_ITEM_ADD(id, bb, NULL);
508#endif
509
510 bool pressed = false;
511 bool hovered = ItemHoverable(bb, id, item_flags);
512
513 // Special mode for Drag and Drop where holding button pressed for a long time while dragging another item triggers the button
514 if (g.DragDropActive && (flags & ImGuiButtonFlags_PressedOnDragDropHold) && !(g.DragDropSourceFlags & ImGuiDragDropFlags_SourceNoHoldToOpenOthers))
515 if (IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem))
516 {
517 hovered = true;
518 SetHoveredID(id);
519 if (g.HoveredIdTimer - g.IO.DeltaTime <= DRAGDROP_HOLD_TO_OPEN_TIMER && g.HoveredIdTimer >= DRAGDROP_HOLD_TO_OPEN_TIMER)
520 {
521 pressed = true;
522 g.DragDropHoldJustPressedId = id;
523 FocusWindow(window);
524 }
525 }
526
527 if (flatten_hovered_children)
528 g.HoveredWindow = backup_hovered_window;
529
530 // Mouse handling
531 const ImGuiID test_owner_id = (flags & ImGuiButtonFlags_NoTestKeyOwner) ? ImGuiKeyOwner_Any : id;
532 if (hovered)
533 {
534 // Poll mouse buttons
535 // - 'mouse_button_clicked' is generally carried into ActiveIdMouseButton when setting ActiveId.

Callers

nothing calls this directly

Calls 4

GetCurrentWindowFunction · 0.85
MouseButtonToKeyFunction · 0.85
GetKeyDataFunction · 0.85
ImMaxFunction · 0.85

Tested by

no test coverage detected