Added ImGuiWindowFlags_NoScrollWithMouse flag.

ButtonBehaviour test hovering of CurrentRootWindow (vs CurrentWindow, different for child-windows). This is intentionally meant to fix grabbing the lower-right resize grip when lower-right corner has a child-window, but may be the overall right-er test. Testing out.
docking
omar 10 years ago
parent e0dc8ac910
commit 860cf578f5

@ -1,4 +1,4 @@
// ImGui library v1.17 wip // ImGui library v1.18 wip
// See ImGui::ShowTestWindow() for sample code. // See ImGui::ShowTestWindow() for sample code.
// Read 'Programmer guide' below for notes on how to setup ImGui in your codebase. // Read 'Programmer guide' below for notes on how to setup ImGui in your codebase.
// Get latest version at https://github.com/ocornut/imgui // Get latest version at https://github.com/ocornut/imgui
@ -757,7 +757,7 @@ struct ImGuiState
ImVector<ImGuiWindow*> CurrentWindowStack; ImVector<ImGuiWindow*> CurrentWindowStack;
ImGuiWindow* FocusedWindow; // Will catch keyboard inputs ImGuiWindow* FocusedWindow; // Will catch keyboard inputs
ImGuiWindow* HoveredWindow; // Will catch mouse inputs ImGuiWindow* HoveredWindow; // Will catch mouse inputs
ImGuiWindow* HoveredWindowExcludingChilds; // Will catch mouse inputs (for focus/move only) ImGuiWindow* HoveredRootWindow; // Will catch mouse inputs (for focus/move only)
ImGuiID HoveredId; ImGuiID HoveredId;
ImGuiID ActiveId; ImGuiID ActiveId;
ImGuiID ActiveIdPreviousFrame; ImGuiID ActiveIdPreviousFrame;
@ -794,7 +794,7 @@ struct ImGuiState
CurrentWindow = NULL; CurrentWindow = NULL;
FocusedWindow = NULL; FocusedWindow = NULL;
HoveredWindow = NULL; HoveredWindow = NULL;
HoveredWindowExcludingChilds = NULL; HoveredRootWindow = NULL;
ActiveIdIsAlive = false; ActiveIdIsAlive = false;
SettingsDirtyTimer = 0.0f; SettingsDirtyTimer = 0.0f;
NewWindowDefaultPos = ImVec2(60, 60); NewWindowDefaultPos = ImVec2(60, 60);
@ -837,8 +837,9 @@ struct ImGuiWindow
int LastFrameDrawn; int LastFrameDrawn;
float ItemWidthDefault; float ItemWidthDefault;
ImGuiStorage StateStorage; ImGuiStorage StateStorage;
float FontWindowScale; // Scale multipler per-window float FontWindowScale; // Scale multiplier per-window
ImDrawList* DrawList; ImDrawList* DrawList;
ImGuiWindow* RootWindow;
// Focus // Focus
int FocusIdxAllCounter; // Start at -1 and increase as assigned via FocusItemRegister() int FocusIdxAllCounter; // Start at -1 and increase as assigned via FocusItemRegister()
@ -1445,7 +1446,7 @@ void ImGui::NewFrame()
} }
g.HoveredWindow = FindHoveredWindow(g.IO.MousePos, false); g.HoveredWindow = FindHoveredWindow(g.IO.MousePos, false);
g.HoveredWindowExcludingChilds = FindHoveredWindow(g.IO.MousePos, true); g.HoveredRootWindow = FindHoveredWindow(g.IO.MousePos, true);
// Are we using inputs? Tell user so they can capture/discard them. // Are we using inputs? Tell user so they can capture/discard them.
g.IO.WantCaptureMouse = (g.HoveredWindow != NULL) || (g.ActiveId != 0); g.IO.WantCaptureMouse = (g.HoveredWindow != NULL) || (g.ActiveId != 0);
@ -1474,8 +1475,11 @@ void ImGui::NewFrame()
else else
{ {
// Scroll // Scroll
const int scroll_lines = (window->Flags & ImGuiWindowFlags_ComboBox) ? 3 : 5; if (!(window->Flags & ImGuiWindowFlags_NoScrollWithMouse))
window->NextScrollY -= g.IO.MouseWheel * window->FontSize() * scroll_lines; {
const int scroll_lines = (window->Flags & ImGuiWindowFlags_ComboBox) ? 3 : 5;
window->NextScrollY -= g.IO.MouseWheel * window->FontSize() * scroll_lines;
}
} }
} }
@ -1521,7 +1525,7 @@ void ImGui::Shutdown()
g.RenderDrawLists.clear(); g.RenderDrawLists.clear();
g.FocusedWindow = NULL; g.FocusedWindow = NULL;
g.HoveredWindow = NULL; g.HoveredWindow = NULL;
g.HoveredWindowExcludingChilds = NULL; g.HoveredRootWindow = NULL;
for (size_t i = 0; i < g.Settings.size(); i++) for (size_t i = 0; i < g.Settings.size(); i++)
{ {
g.Settings[i]->~ImGuiIniData(); g.Settings[i]->~ImGuiIniData();
@ -2128,6 +2132,16 @@ bool ImGui::Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, I
g.CurrentWindowStack.push_back(window); g.CurrentWindowStack.push_back(window);
g.CurrentWindow = window; g.CurrentWindow = window;
// Find root
size_t root_idx = g.CurrentWindowStack.size() - 1;
while (root_idx > 0)
{
if ((g.CurrentWindowStack[root_idx]->Flags & ImGuiWindowFlags_ChildWindow) == 0)
break;
root_idx--;
}
window->RootWindow = g.CurrentWindowStack[root_idx];
// Default alpha // Default alpha
if (fill_alpha < 0.0f) if (fill_alpha < 0.0f)
fill_alpha = style.WindowFillAlphaDefault; fill_alpha = style.WindowFillAlphaDefault;
@ -2282,7 +2296,7 @@ bool ImGui::Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, I
const ImVec2 size_auto_fit = ImClamp(window->SizeContentsFit + style.AutoFitPadding, style.WindowMinSize, g.IO.DisplaySize - style.AutoFitPadding); const ImVec2 size_auto_fit = ImClamp(window->SizeContentsFit + style.AutoFitPadding, style.WindowMinSize, g.IO.DisplaySize - style.AutoFitPadding);
if ((window->Flags & ImGuiWindowFlags_AlwaysAutoResize) != 0) if ((window->Flags & ImGuiWindowFlags_AlwaysAutoResize) != 0)
{ {
// Don't continously mark settings as dirty, the size of the window doesn't need to be stored. // Don't continuously mark settings as dirty, the size of the window doesn't need to be stored.
window->SizeFull = size_auto_fit; window->SizeFull = size_auto_fit;
} }
else if (window->AutoFitFrames > 0) else if (window->AutoFitFrames > 0)
@ -2298,7 +2312,7 @@ bool ImGui::Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, I
{ {
// Resize grip // Resize grip
const ImGuiAabb resize_aabb(window->Aabb().GetBR()-ImVec2(18,18), window->Aabb().GetBR()); const ImGuiAabb resize_aabb(window->Aabb().GetBR()-ImVec2(18,18), window->Aabb().GetBR());
const ImGuiID resize_id = window->GetID("#RESIZE"); const ImGuiID resize_id = window->GetID("##RESIZE");
bool hovered, held; bool hovered, held;
ButtonBehaviour(resize_aabb, resize_id, &hovered, &held, true); ButtonBehaviour(resize_aabb, resize_id, &hovered, &held, true);
resize_col = window->Color(held ? ImGuiCol_ResizeGripActive : hovered ? ImGuiCol_ResizeGripHovered : ImGuiCol_ResizeGrip); resize_col = window->Color(held ? ImGuiCol_ResizeGripActive : hovered ? ImGuiCol_ResizeGripHovered : ImGuiCol_ResizeGrip);
@ -2506,7 +2520,7 @@ void ImGui::End()
// Select window for move/focus when we're done with all our widgets (we only consider non-childs windows here) // Select window for move/focus when we're done with all our widgets (we only consider non-childs windows here)
const ImGuiAabb bb(window->Pos, window->Pos+window->Size); const ImGuiAabb bb(window->Pos, window->Pos+window->Size);
if (g.ActiveId == 0 && g.HoveredId == 0 && g.HoveredWindowExcludingChilds == window && IsMouseHoveringBox(bb) && g.IO.MouseClicked[0]) if (g.ActiveId == 0 && g.HoveredId == 0 && g.HoveredRootWindow == window && IsMouseHoveringBox(bb) && g.IO.MouseClicked[0])
g.ActiveId = window->GetID("#MOVE"); g.ActiveId = window->GetID("#MOVE");
// Stop logging // Stop logging
@ -2532,6 +2546,7 @@ void ImGui::End()
} }
// Pop // Pop
window->RootWindow = NULL;
g.CurrentWindowStack.pop_back(); g.CurrentWindowStack.pop_back();
g.CurrentWindow = g.CurrentWindowStack.empty() ? NULL : g.CurrentWindowStack.back(); g.CurrentWindow = g.CurrentWindowStack.empty() ? NULL : g.CurrentWindowStack.back();
} }
@ -3113,7 +3128,7 @@ static bool ButtonBehaviour(const ImGuiAabb& bb, const ImGuiID& id, bool* out_ho
ImGuiState& g = GImGui; ImGuiState& g = GImGui;
ImGuiWindow* window = GetCurrentWindow(); ImGuiWindow* window = GetCurrentWindow();
const bool hovered = (g.HoveredWindow == window) && (g.HoveredId == 0) && IsMouseHoveringBox(bb); const bool hovered = (g.HoveredRootWindow == window->RootWindow) && (g.HoveredId == 0) && IsMouseHoveringBox(bb);
bool pressed = false; bool pressed = false;
if (hovered) if (hovered)
{ {

@ -1,4 +1,4 @@
// ImGui library v1.17 wip // ImGui library v1.18 wip
// See .cpp file for commentary. // See .cpp file for commentary.
// See ImGui::ShowTestWindow() for sample code. // See ImGui::ShowTestWindow() for sample code.
// Read 'Programmer guide' in .cpp for notes on how to setup ImGui in your codebase. // Read 'Programmer guide' in .cpp for notes on how to setup ImGui in your codebase.
@ -308,12 +308,13 @@ enum ImGuiWindowFlags_
ImGuiWindowFlags_NoResize = 1 << 2, ImGuiWindowFlags_NoResize = 1 << 2,
ImGuiWindowFlags_NoMove = 1 << 3, ImGuiWindowFlags_NoMove = 1 << 3,
ImGuiWindowFlags_NoScrollbar = 1 << 4, ImGuiWindowFlags_NoScrollbar = 1 << 4,
ImGuiWindowFlags_AlwaysAutoResize = 1 << 5, ImGuiWindowFlags_NoScrollWithMouse = 1 << 5,
ImGuiWindowFlags_ChildWindow = 1 << 6, // For internal use by BeginChild() ImGuiWindowFlags_AlwaysAutoResize = 1 << 6,
ImGuiWindowFlags_ChildWindowAutoFitX = 1 << 7, // For internal use by BeginChild() ImGuiWindowFlags_ChildWindow = 1 << 7, // For internal use by BeginChild()
ImGuiWindowFlags_ChildWindowAutoFitY = 1 << 8, // For internal use by BeginChild() ImGuiWindowFlags_ChildWindowAutoFitX = 1 << 8, // For internal use by BeginChild()
ImGuiWindowFlags_ComboBox = 1 << 9, // For internal use by ComboBox() ImGuiWindowFlags_ChildWindowAutoFitY = 1 << 9, // For internal use by BeginChild()
ImGuiWindowFlags_Tooltip = 1 << 10 // For internal use by Render() when using Tooltip ImGuiWindowFlags_ComboBox = 1 << 10, // For internal use by ComboBox()
ImGuiWindowFlags_Tooltip = 1 << 11 // For internal use by Render() when using Tooltip
}; };
// Flags for ImGui::InputText() // Flags for ImGui::InputText()

Loading…
Cancel
Save