Skip to content

Commit

Permalink
fnShowResizeWidget: add invisible button (to disable window drag in t…
Browse files Browse the repository at this point in the history
…his zone)
  • Loading branch information
pthom committed May 12, 2024
1 parent 7d14a6d commit d65c463
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
14 changes: 12 additions & 2 deletions src/immvision/internal/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,11 +497,21 @@ namespace ImmVision
ImVec2 tl(br.x - size, br.y - size);

ImRect zone(tl, br);
ImGui::GetWindowDrawList()->AddTriangleFilled(br, bl, tr, ImGui::GetColorU32(ImGuiCol_ButtonHovered));

{
auto cursorPos = ImGui::GetCursorPos();
ImGui::SetCursorPos(tl);
ImGui::InvisibleButton("##resize", zone.GetSize());
ImGui::SetCursorPos(cursorPos);
}

bool isMouseHoveringWidget = ImGui::IsMouseHoveringRect(zone.Min, zone.Max);
ImU32 color = isMouseHoveringWidget ? ImGui::GetColorU32(ImGuiCol_ButtonHovered) : ImGui::GetColorU32(ImGuiCol_Button);
ImGui::GetWindowDrawList()->AddTriangleFilled(br, bl, tr, color);

if (!cacheParams.IsResizing)
{
if (ImGui::IsMouseHoveringRect(zone.Min, zone.Max) && ImGui::IsMouseDown(0))
if (isMouseHoveringWidget && ImGui::IsMouseDown(0))
{
ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeNWSE);
cacheParams.IsResizing = true;
Expand Down
14 changes: 12 additions & 2 deletions src_all_in_one/immvision/immvision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9955,11 +9955,21 @@ namespace ImmVision
ImVec2 tl(br.x - size, br.y - size);

ImRect zone(tl, br);
ImGui::GetWindowDrawList()->AddTriangleFilled(br, bl, tr, ImGui::GetColorU32(ImGuiCol_ButtonHovered));

{
auto cursorPos = ImGui::GetCursorPos();
ImGui::SetCursorPos(tl);
ImGui::InvisibleButton("##resize", zone.GetSize());
ImGui::SetCursorPos(cursorPos);
}

bool isMouseHoveringWidget = ImGui::IsMouseHoveringRect(zone.Min, zone.Max);
ImU32 color = isMouseHoveringWidget ? ImGui::GetColorU32(ImGuiCol_ButtonHovered) : ImGui::GetColorU32(ImGuiCol_Button);
ImGui::GetWindowDrawList()->AddTriangleFilled(br, bl, tr, color);

if (!cacheParams.IsResizing)
{
if (ImGui::IsMouseHoveringRect(zone.Min, zone.Max) && ImGui::IsMouseDown(0))
if (isMouseHoveringWidget && ImGui::IsMouseDown(0))
{
ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeNWSE);
cacheParams.IsResizing = true;
Expand Down

0 comments on commit d65c463

Please sign in to comment.