Using 'hover_visibility_delay' allows us to hide the highlight and mouse cursor for a short time, which can be convenient to reduce visual noise.
| 1723 | |
| 1724 | // Using 'hover_visibility_delay' allows us to hide the highlight and mouse cursor for a short time, which can be convenient to reduce visual noise. |
| 1725 | bool ImGui::SplitterBehavior(const ImRect& bb, ImGuiID id, ImGuiAxis axis, float* size1, float* size2, float min_size1, float min_size2, float hover_extend, float hover_visibility_delay, ImU32 bg_col) |
| 1726 | { |
| 1727 | ImGuiContext& g = *GImGui; |
| 1728 | ImGuiWindow* window = g.CurrentWindow; |
| 1729 | |
| 1730 | if (!ItemAdd(bb, id, NULL, ImGuiItemFlags_NoNav)) |
| 1731 | return false; |
| 1732 | |
| 1733 | // FIXME: AFAIK the only leftover reason for passing ImGuiButtonFlags_AllowOverlap here is |
| 1734 | // to allow caller of SplitterBehavior() to call SetItemAllowOverlap() after the item. |
| 1735 | // Nowadays we would instead want to use SetNextItemAllowOverlap() before the item. |
| 1736 | ImGuiButtonFlags button_flags = ImGuiButtonFlags_FlattenChildren; |
| 1737 | #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS |
| 1738 | button_flags |= ImGuiButtonFlags_AllowOverlap; |
| 1739 | #endif |
| 1740 | |
| 1741 | bool hovered, held; |
| 1742 | ImRect bb_interact = bb; |
| 1743 | bb_interact.Expand(axis == ImGuiAxis_Y ? ImVec2(0.0f, hover_extend) : ImVec2(hover_extend, 0.0f)); |
| 1744 | ButtonBehavior(bb_interact, id, &hovered, &held, button_flags); |
| 1745 | if (hovered) |
| 1746 | g.LastItemData.StatusFlags |= ImGuiItemStatusFlags_HoveredRect; // for IsItemHovered(), because bb_interact is larger than bb |
| 1747 | |
| 1748 | if (held || (hovered && g.HoveredIdPreviousFrame == id && g.HoveredIdTimer >= hover_visibility_delay)) |
| 1749 | SetMouseCursor(axis == ImGuiAxis_Y ? ImGuiMouseCursor_ResizeNS : ImGuiMouseCursor_ResizeEW); |
| 1750 | |
| 1751 | ImRect bb_render = bb; |
| 1752 | if (held) |
| 1753 | { |
| 1754 | float mouse_delta = (g.IO.MousePos - g.ActiveIdClickOffset - bb_interact.Min)[axis]; |
| 1755 | |
| 1756 | // Minimum pane size |
| 1757 | float size_1_maximum_delta = ImMax(0.0f, *size1 - min_size1); |
| 1758 | float size_2_maximum_delta = ImMax(0.0f, *size2 - min_size2); |
| 1759 | if (mouse_delta < -size_1_maximum_delta) |
| 1760 | mouse_delta = -size_1_maximum_delta; |
| 1761 | if (mouse_delta > size_2_maximum_delta) |
| 1762 | mouse_delta = size_2_maximum_delta; |
| 1763 | |
| 1764 | // Apply resize |
| 1765 | if (mouse_delta != 0.0f) |
| 1766 | { |
| 1767 | *size1 = ImMax(*size1 + mouse_delta, min_size1); |
| 1768 | *size2 = ImMax(*size2 - mouse_delta, min_size2); |
| 1769 | bb_render.Translate((axis == ImGuiAxis_X) ? ImVec2(mouse_delta, 0.0f) : ImVec2(0.0f, mouse_delta)); |
| 1770 | MarkItemEdited(id); |
| 1771 | } |
| 1772 | } |
| 1773 | |
| 1774 | // Render at new position |
| 1775 | if (bg_col & IM_COL32_A_MASK) |
| 1776 | window->DrawList->AddRectFilled(bb_render.Min, bb_render.Max, bg_col, 0.0f); |
| 1777 | const ImU32 col = GetColorU32(held ? ImGuiCol_SeparatorActive : (hovered && g.HoveredIdTimer >= hover_visibility_delay) ? ImGuiCol_SeparatorHovered : ImGuiCol_Separator); |
| 1778 | window->DrawList->AddRectFilled(bb_render.Min, bb_render.Max, col, 0.0f); |
| 1779 | |
| 1780 | return held; |
| 1781 | } |
| 1782 |
nothing calls this directly
no test coverage detected