Merge branch 'master' into navigation

This commit is contained in:
omar 2017-09-27 17:25:50 +02:00
commit cc26db8ec7
13 changed files with 60 additions and 67 deletions

View File

@ -37,7 +37,7 @@ int main(int, char**)
bool show_test_window = true;
bool show_another_window = false;
ImVec4 clear_color = ImColor(114, 144, 154);
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
// Main loop
bool running = true;

View File

@ -137,7 +137,7 @@ int main(int, char**)
bool show_test_window = true;
bool show_another_window = false;
ImVec4 clear_col = ImColor(114, 144, 154);
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
// Main loop
MSG msg;
@ -158,7 +158,7 @@ int main(int, char**)
static float f = 0.0f;
ImGui::Text("Hello, world!");
ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
ImGui::ColorEdit3("clear color", (float*)&clear_col);
ImGui::ColorEdit3("clear color", (float*)&clear_color);
if (ImGui::Button("Test Window")) show_test_window ^= 1;
if (ImGui::Button("Another Window")) show_another_window ^= 1;
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
@ -180,7 +180,7 @@ int main(int, char**)
}
// Rendering
g_pd3dDevice->ClearRenderTargetView(g_mainRenderTargetView, (float*)&clear_col);
g_pd3dDevice->ClearRenderTargetView(g_mainRenderTargetView, (float*)&clear_color);
ImGui::Render();
g_pSwapChain->Present(1, 0); // Present with vsync

View File

@ -140,7 +140,7 @@ int main(int, char**)
bool show_test_window = true;
bool show_another_window = false;
ImVec4 clear_col = ImColor(114, 144, 154);
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
// Main loop
MSG msg;
@ -161,7 +161,7 @@ int main(int, char**)
static float f = 0.0f;
ImGui::Text("Hello, world!");
ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
ImGui::ColorEdit3("clear color", (float*)&clear_col);
ImGui::ColorEdit3("clear color", (float*)&clear_color);
if (ImGui::Button("Test Window")) show_test_window ^= 1;
if (ImGui::Button("Another Window")) show_another_window ^= 1;
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
@ -183,7 +183,7 @@ int main(int, char**)
}
// Rendering
g_pd3dDeviceContext->ClearRenderTargetView(g_mainRenderTargetView, (float*)&clear_col);
g_pd3dDeviceContext->ClearRenderTargetView(g_mainRenderTargetView, (float*)&clear_color);
ImGui::Render();
g_pSwapChain->Present(1, 0); // Present with vsync

View File

@ -89,7 +89,7 @@ int main(int, char**)
bool show_test_window = true;
bool show_another_window = false;
ImVec4 clear_col = ImColor(114, 144, 154);
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
// Main loop
MSG msg;
@ -112,7 +112,7 @@ int main(int, char**)
static float f = 0.0f;
ImGui::Text("Hello, world!");
ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
ImGui::ColorEdit3("clear color", (float*)&clear_col);
ImGui::ColorEdit3("clear color", (float*)&clear_color);
if (ImGui::Button("Test Window")) show_test_window ^= 1;
if (ImGui::Button("Another Window")) show_another_window ^= 1;
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
@ -137,7 +137,7 @@ int main(int, char**)
g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, false);
g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, false);
g_pd3dDevice->SetRenderState(D3DRS_SCISSORTESTENABLE, false);
D3DCOLOR clear_col_dx = D3DCOLOR_RGBA((int)(clear_col.x*255.0f), (int)(clear_col.y*255.0f), (int)(clear_col.z*255.0f), (int)(clear_col.w*255.0f));
D3DCOLOR clear_col_dx = D3DCOLOR_RGBA((int)(clear_color.x*255.0f), (int)(clear_color.y*255.0f), (int)(clear_color.z*255.0f), (int)(clear_color.w*255.0f));
g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, clear_col_dx, 1.0f, 0);
if (g_pd3dDevice->BeginScene() >= 0)
{

View File

@ -29,7 +29,7 @@ int main(int, char**)
bool show_test_window = true;
bool show_another_window = false;
ImVec4 clear_color = ImColor(114, 144, 154);
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
// Main loop
while (true)

View File

@ -36,7 +36,7 @@ int main(int, char**)
bool show_test_window = true;
bool show_another_window = false;
ImVec4 clear_color = ImColor(114, 144, 154);
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
// Main loop
while (!glfwWindowShouldClose(window))

View File

@ -44,7 +44,7 @@ int main(int, char**)
bool show_test_window = true;
bool show_another_window = false;
ImVec4 clear_color = ImColor(114, 144, 154);
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
// Main loop
while (!glfwWindowShouldClose(window))

View File

@ -42,7 +42,7 @@ int main(int, char**)
bool show_test_window = true;
bool show_another_window = false;
ImVec4 clear_color = ImColor(114, 144, 154);
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
// Main loop
bool done = false;

View File

@ -45,7 +45,7 @@ int main(int, char**)
bool show_test_window = true;
bool show_another_window = false;
ImVec4 clear_color = ImColor(114, 144, 154);
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
// Main loop
bool done = false;

View File

@ -664,7 +664,7 @@ int main(int, char**)
bool show_test_window = true;
bool show_another_window = false;
ImVec4 clear_color = ImColor(114, 144, 154);
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
// When IMGUI_UNLIMITED_FRAME_RATE is defined we render into latest image acquired from the swapchain but we display the image which was rendered before.
// Hence we must render once and increase the g_FrameIndex without presenting, which we do before entering the render loop.

View File

@ -2160,7 +2160,6 @@ bool ImGui::ItemAdd(const ImRect& bb, const ImGuiID* id, const ImRect* nav_bb_ar
ImGuiWindow* window = g.CurrentWindow;
window->DC.LastItemId = id ? *id : 0;
window->DC.LastItemRect = bb;
window->DC.LastItemHoveredAndUsable = window->DC.LastItemHoveredRect = false;
const bool is_clipped = IsClippedEx(bb, id, false);
if (id != NULL)
window->DC.NavLayerActiveFlagsNext |= (1 << window->DC.NavLayerCurrent);
@ -2212,21 +2211,49 @@ bool ImGui::ItemAdd(const ImRect& bb, const ImGuiID* id, const ImRect* nav_bb_ar
return false;
//if (g.IO.KeyAlt) window->DrawList->AddRect(bb.Min, bb.Max, IM_COL32(255,255,0,120)); // [DEBUG]
// Setting LastItemHoveredAndUsable for IsItemHovered(). This is a sensible default, but widgets are free to override it.
if (IsMouseHoveringRect(bb.Min, bb.Max))
{
// Matching the behavior of IsHovered() but allow if ActiveId==window->MoveID (we clicked on the window background)
// So that clicking on items with no active id such as Text() still returns true with IsItemHovered()
window->DC.LastItemHoveredRect = true;
if (g.HoveredRootWindow == window->RootWindow)
if (g.ActiveId == 0 || (id && g.ActiveId == *id) || g.ActiveIdAllowOverlap || (g.ActiveId == window->MoveId))
if (!g.NavDisableMouseHover && IsWindowContentHoverable(window))
window->DC.LastItemHoveredAndUsable = true;
}
return true;
}
// This is roughly matching the behavior of internal-facing IsHovered()
// - we allow hovering to be true when ActiveId==window->MoveID, so that clicking on non-interactive items such as a Text() item still returns true with IsItemHovered())
// - we don't expose the flatten_child feature that IsHovered() has, which is only used by the window resizing widget (may rework this)
bool ImGui::IsItemHovered()
{
ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow;
if (g.NavDisableMouseHover)
return IsItemFocused();
if (g.HoveredWindow == window)
if (g.ActiveId == 0 || g.ActiveId == window->DC.LastItemId || g.ActiveIdAllowOverlap || g.ActiveId == window->MoveId)
if (IsMouseHoveringRect(window->DC.LastItemRect.Min, window->DC.LastItemRect.Max))
if (IsWindowContentHoverable(window))
return true;
return false;
}
bool ImGui::IsItemRectHovered()
{
ImGuiWindow* window = GetCurrentWindowRead();
return IsMouseHoveringRect(window->DC.LastItemRect.Min, window->DC.LastItemRect.Max);
}
// Internal facing IsHovered() differs slightly from IsItemHovered().
bool ImGui::IsHovered(const ImRect& bb, ImGuiID id, bool flatten_childs)
{
ImGuiContext& g = *GImGui;
if (g.HoveredId == 0 || g.HoveredId == id || g.HoveredIdAllowOverlap)
{
ImGuiWindow* window = g.CurrentWindow;
if (g.HoveredWindow == window || (flatten_childs && g.HoveredRootWindow == window->RootWindow))
if (g.ActiveId == 0 || g.ActiveId == id || g.ActiveIdAllowOverlap)
if (IsMouseHoveringRect(bb.Min, bb.Max))
if (!g.NavDisableMouseHover && IsWindowContentHoverable(g.HoveredRootWindow))
return true;
}
return false;
}
bool ImGui::IsClippedEx(const ImRect& bb, const ImGuiID* id, bool clip_even_when_logged)
{
ImGuiContext& g = *GImGui;
@ -2238,21 +2265,6 @@ bool ImGui::IsClippedEx(const ImRect& bb, const ImGuiID* id, bool clip_even_when
return false;
}
// NB: This is an internal helper. The user-facing IsItemHovered() is using data emitted from ItemAdd(), with a slightly different logic.
bool ImGui::IsHovered(const ImRect& bb, ImGuiID id, bool flatten_childs)
{
ImGuiContext& g = *GImGui;
if (g.HoveredId == 0 || g.HoveredId == id || g.HoveredIdAllowOverlap)
{
ImGuiWindow* window = GetCurrentWindowRead();
if (g.HoveredWindow == window || (flatten_childs && g.HoveredRootWindow == window->RootWindow))
if ((g.ActiveId == 0 || g.ActiveId == id || g.ActiveIdAllowOverlap) && IsMouseHoveringRect(bb.Min, bb.Max))
if (!g.NavDisableMouseHover && IsWindowContentHoverable(g.HoveredRootWindow))
return true;
}
return false;
}
bool ImGui::FocusableItemRegister(ImGuiWindow* window, ImGuiID id, bool tab_stop)
{
ImGuiContext& g = *GImGui;
@ -4020,21 +4032,6 @@ void ImGui::CaptureMouseFromApp(bool capture)
GImGui->WantCaptureMouseNextFrame = capture ? 1 : 0;
}
bool ImGui::IsItemHovered()
{
ImGuiWindow* window = GetCurrentWindowRead();
ImGuiContext& g = *GImGui;
if (g.NavDisableMouseHover)
return IsItemFocused();
return window->DC.LastItemHoveredAndUsable;
}
bool ImGui::IsItemRectHovered()
{
ImGuiWindow* window = GetCurrentWindowRead();
return window->DC.LastItemHoveredRect;
}
bool ImGui::IsItemActive()
{
ImGuiContext& g = *GImGui;
@ -10959,13 +10956,12 @@ void ImGui::EndGroup()
ItemAdd(group_bb, NULL);
}
// If the current ActiveId was declared within the boundary of our group, we copy it to LastItemId so IsItemActive() will function on the entire group.
// If the current ActiveId was declared within the boundary of our group, we copy it to LastItemId so IsItemActive() will be functional on the entire group.
// It would be be neater if we replaced window.DC.LastItemId by e.g. 'bool LastItemIsActive', but if you search for LastItemId you'll notice it is only used in that context.
const bool active_id_within_group = (!group_data.BackupActiveIdIsAlive && g.ActiveIdIsAlive && g.ActiveId && g.ActiveIdWindow->RootWindow == window->RootWindow);
if (active_id_within_group)
window->DC.LastItemId = g.ActiveId;
if (active_id_within_group && g.HoveredId == g.ActiveId)
window->DC.LastItemHoveredAndUsable = window->DC.LastItemHoveredRect = true;
window->DC.LastItemRect = group_bb;
window->DC.GroupStack.pop_back();

View File

@ -1129,11 +1129,11 @@ void ImGui::ShowTestWindow(bool* p_open)
ImGui::Button("CCC");
ImGui::Button("DDD");
ImGui::EndGroup();
if (ImGui::IsItemHovered())
ImGui::SetTooltip("Group hovered");
ImGui::SameLine();
ImGui::Button("EEE");
ImGui::EndGroup();
if (ImGui::IsItemHovered())
ImGui::SetTooltip("First group hovered");
}
// Capture the group size and create widgets using the same size
ImVec2 size = ImGui::GetItemRectSize();

View File

@ -658,8 +658,6 @@ struct IMGUI_API ImGuiDrawContext
int TreeDepth;
ImGuiID LastItemId;
ImRect LastItemRect;
bool LastItemHoveredAndUsable; // Item rectangle is hovered, and its window is currently interactable with (not blocked by a popup preventing access to the window)
bool LastItemHoveredRect; // Item rectangle is hovered, but its window may or not be currently interactable with (might be blocked by a popup preventing access to the window)
bool NavHasScroll; // Set when scrolling can be used (ScrollMax > 0.0f)
int NavLayerCurrent; // Current layer, 0..31 (we currently only use 0..1)
int NavLayerActiveFlags, NavLayerActiveFlagsNext; // Which layer have been written to.
@ -703,7 +701,6 @@ struct IMGUI_API ImGuiDrawContext
TreeDepth = 0;
LastItemId = 0;
LastItemRect = ImRect(0.0f,0.0f,0.0f,0.0f);
LastItemHoveredAndUsable = LastItemHoveredRect = false;
NavHasScroll = false;
NavLayerActiveFlags = NavLayerActiveFlagsNext = 0x00;
NavLayerCurrent = 0;