Skip to content

Commit

Permalink
WidgetWithResizeHandle needs and id
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed May 11, 2024
1 parent 75bef57 commit d55c6cc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/hello_imgui/hello_imgui_widgets.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ namespace HelloImGui
// ImPlot::EndPlot();
// }
// };
// widget_size = widget_with_resize_handle(myWidgetFunction);
// widget_size = widget_with_resize_handle("plot", myWidgetFunction);
// }
ImVec2 WidgetWithResizeHandle(
const char* id,
VoidFunction widgetGuiFunction,
float handleSizeEm = 1.0f,
std::optional<VoidFunction> onItemResized = std::nullopt,
Expand Down
11 changes: 7 additions & 4 deletions src/hello_imgui/impl/hello_imgui_widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace HelloImGui


ImVec2 WidgetWithResizeHandle(
const char* id,
VoidFunction widgetGuiFunction,
float handleSizeEm,
std::optional<VoidFunction> onItemResized,
Expand All @@ -47,14 +48,15 @@ namespace HelloImGui
{
widgetGuiFunction();

ImGuiID widget_id = ImGui::GetID(id);
ImVec2 widget_size = ImGui::GetItemRectSize();

if (ImGui::IsMouseHoveringRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax()))
{
if (onItemHovered.has_value() && onItemHovered)
onItemHovered.value()();
}

ImVec2 widget_size = ImGui::GetItemRectSize();
ImGuiID widget_id = ImGui::GetItemID();

float em = ImGui::GetFontSize(), size = em * handleSizeEm;
ImVec2 widget_bottom_right = ImGui::GetItemRectMax();
Expand All @@ -72,6 +74,9 @@ namespace HelloImGui
resizingState->MouseInResizingZone = ImGui::IsMouseHoveringRect(zone.Min, zone.Max);
resizingState->MouseDown = ImGui::IsMouseDown(0);

bool wasMouseJustClicked = !previousResizingState.MouseDown && resizingState->MouseDown;
bool mouseInZoneBeforeAfter = previousResizingState.MouseInResizingZone && resizingState->MouseInResizingZone;

ImVec2 mouseDelta = resizingState->MousePosition - previousResizingState.MousePosition;

// Color
Expand All @@ -85,8 +90,6 @@ namespace HelloImGui

if (!resizingState->Resizing)
{
bool wasMouseJustClicked = !previousResizingState.MouseDown && resizingState->MouseDown;
bool mouseInZoneBeforeAfter = previousResizingState.MouseInResizingZone && resizingState->MouseInResizingZone;
if (wasMouseJustClicked && mouseInZoneBeforeAfter)
{
if (onItemResized.has_value() && onItemResized)
Expand Down

0 comments on commit d55c6cc

Please sign in to comment.