Skip to content

Commit

Permalink
Wip / borderless resizable
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed Jan 1, 2024
1 parent 440ae7e commit 5bb0421
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/hello_imgui/internal/backend_impls/abstract_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "hello_imgui/internal/clock_seconds.h"
#include "hello_imgui/internal/platform/ini_folder_locations.h"
#include "imgui.h"
#include "hello_imgui/internal/borderless_resizable.h"

#include "hello_imgui/internal/imgui_global_context.h" // must be included before imgui_internal.h
#include "imgui_internal.h"
Expand Down Expand Up @@ -504,6 +505,9 @@ void AbstractRunner::RenderGui()
if (params.imGuiWindowParams.showMenuBar)
Menu_StatusBar::ShowMenu(params);

if (params.appWindowParams.borderless) // Need to add params.appWindowParams.borderlessResizable
HandleBorderlessResizable(mWindow, mBackendWindowHelper.get());

if (params.callbacks.ShowGui)
{
bool wantAutoSize = WantAutoSize();
Expand Down
88 changes: 88 additions & 0 deletions src/hello_imgui/internal/borderless_resizable.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#define IMGUI_DEFINE_MATH_OPERATORS
#include "hello_imgui/internal/borderless_resizable.h"
#include "hello_imgui/hello_imgui.h"
#include "imgui_internal.h"


namespace HelloImGui
{
void HandleBorderlessResizable(
BackendApi::WindowPointer window,
BackendApi::IBackendWindowHelper * backendWindowHelper)
{
ImVec2 winSize = ImGui::GetWindowSize();
auto highlightColor = ImGui::GetColorU32(ImGuiCol_FrameBgHovered, 0.8f);

// Drag zone at the top of the window
{
ImVec2 topLeftCorner = ImGui::GetMainViewport()->Pos;
ImVec2 bottomRightCorner = topLeftCorner + ImVec2(winSize.x, HelloImGui::EmSize(1.5f));
ImRect dragRect = ImRect(topLeftCorner, bottomRightCorner);

ImVec2 mousePos = ImGui::GetIO().MousePos;
bool isMouseInDragZone = dragRect.Contains(mousePos);

// highlight drag zone if hovering
if (isMouseInDragZone)
{
ImGui::GetForegroundDrawList()->AddRectFilled(
dragRect.Min,
dragRect.Max,
highlightColor
);
}

static bool isDragging = false;
if (ImGui::IsMouseDragging(0) && isMouseInDragZone)
isDragging = true;
if (ImGui::IsMouseReleased(0))
isDragging = false;

if (isDragging)
{
ImVec2 dragDelta = ImGui::GetMouseDragDelta(0);
ImGui::ResetMouseDragDelta(0);

// move window
{
auto windowBounds = backendWindowHelper->GetWindowBounds(window);
windowBounds.position[0] += (int)dragDelta.x;
windowBounds.position[1] += (int)dragDelta.y;
backendWindowHelper->SetWindowBounds(window, windowBounds);
}
}
}

// Drag zone at the bottom-right of the window
// This is still a draft, which needs to be completed
// and probably refactored: there is too much repetition between the two blocks of code
{
ImVec2 bottomRightCorner = ImGui::GetMainViewport()->Pos + ImGui::GetMainViewport()->Size;
ImVec2 topLeftCorner = bottomRightCorner - HelloImGui::EmToVec2(1.5f, 1.5f);

// Small triangle in the bottom-right corner
ImVec2 t1 = bottomRightCorner;
ImVec2 t2 = bottomRightCorner - HelloImGui::EmToVec2(1.5f, 0.f);
ImVec2 t3 = bottomRightCorner - HelloImGui::EmToVec2(0.f, 1.5f);

ImRect dragRect = ImRect(topLeftCorner, bottomRightCorner);

ImVec2 mousePos = ImGui::GetIO().MousePos;
bool isMouseInDragZone = dragRect.Contains(mousePos);

// highlight drag zone if hovering
if (isMouseInDragZone)
{
ImGui::GetForegroundDrawList()->AddTriangleFilled(
t1, t2, t3,
highlightColor
);
}

// To be completed...

}
}
}


10 changes: 10 additions & 0 deletions src/hello_imgui/internal/borderless_resizable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once
#include "hello_imgui/runner_params.h"
#include "hello_imgui/internal/backend_impls/backend_window_helper/backend_window_helper.h"

namespace HelloImGui
{
void HandleBorderlessResizable(
BackendApi::WindowPointer window,
BackendApi::IBackendWindowHelper * backendWindowHelper);
}
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ int main(int, char**)
runnerParams.imGuiWindowParams.menuAppTitle = "Docking Demo";
runnerParams.appWindowParams.windowGeometry.size = {1000, 900};
runnerParams.appWindowParams.restorePreviousGeometry = true;
runnerParams.appWindowParams.borderless = true;

// Load additional font
runnerParams.callbacks.LoadAdditionalFonts = LoadFonts;
Expand Down

0 comments on commit 5bb0421

Please sign in to comment.