MCPcopy Create free account
hub / github.com/Raais/ImStudio / ButtonBehavior

Method ButtonBehavior

src/third-party/imgui/imgui_widgets.cpp:491–668  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

489//-------------------------------------------------------------------------------------------------------------------------------------------------
490
491bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool* out_held, ImGuiButtonFlags flags)
492{
493 ImGuiContext& g = *GImGui;
494 ImGuiWindow* window = GetCurrentWindow();
495
496 // Default only reacts to left mouse button
497 if ((flags & ImGuiButtonFlags_MouseButtonMask_) == 0)
498 flags |= ImGuiButtonFlags_MouseButtonDefault_;
499
500 // Default behavior requires click + release inside bounding box
501 if ((flags & ImGuiButtonFlags_PressedOnMask_) == 0)
502 flags |= ImGuiButtonFlags_PressedOnDefault_;
503
504 ImGuiWindow* backup_hovered_window = g.HoveredWindow;
505 const bool flatten_hovered_children = (flags & ImGuiButtonFlags_FlattenChildren) && g.HoveredWindow && g.HoveredWindow->RootWindow == window;
506 if (flatten_hovered_children)
507 g.HoveredWindow = window;
508
509#ifdef IMGUI_ENABLE_TEST_ENGINE
510 if (id != 0 && g.LastItemData.ID != id)
511 IMGUI_TEST_ENGINE_ITEM_ADD(bb, id);
512#endif
513
514 bool pressed = false;
515 bool hovered = ItemHoverable(bb, id);
516
517 // Drag source doesn't report as hovered
518 if (hovered && g.DragDropActive && g.DragDropPayload.SourceId == id && !(g.DragDropSourceFlags & ImGuiDragDropFlags_SourceNoDisableHover))
519 hovered = false;
520
521 // Special mode for Drag and Drop where holding button pressed for a long time while dragging another item triggers the button
522 if (g.DragDropActive && (flags & ImGuiButtonFlags_PressedOnDragDropHold) && !(g.DragDropSourceFlags & ImGuiDragDropFlags_SourceNoHoldToOpenOthers))
523 if (IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem))
524 {
525 hovered = true;
526 SetHoveredID(id);
527 if (g.HoveredIdTimer - g.IO.DeltaTime <= DRAGDROP_HOLD_TO_OPEN_TIMER && g.HoveredIdTimer >= DRAGDROP_HOLD_TO_OPEN_TIMER)
528 {
529 pressed = true;
530 g.DragDropHoldJustPressedId = id;
531 FocusWindow(window);
532 }
533 }
534
535 if (flatten_hovered_children)
536 g.HoveredWindow = backup_hovered_window;
537
538 // AllowOverlap mode (rarely used) requires previous frame HoveredId to be null or to match. This allows using patterns where a later submitted widget overlaps a previous one.
539 if (hovered && (flags & ImGuiButtonFlags_AllowItemOverlap) && (g.HoveredIdPreviousFrame != id && g.HoveredIdPreviousFrame != 0))
540 hovered = false;
541
542 // Mouse handling
543 if (hovered)
544 {
545 if (!(flags & ImGuiButtonFlags_NoKeyModifiers) || (!g.IO.KeyCtrl && !g.IO.KeyShift && !g.IO.KeyAlt))
546 {
547 // Poll buttons
548 int mouse_button_clicked = -1;

Callers

nothing calls this directly

Calls 2

GetCurrentWindowFunction · 0.85
IsNavInputTestFunction · 0.85

Tested by

no test coverage detected