1
0
mirror of https://github.com/ocornut/imgui.git synced 2024-09-24 03:28:33 +02:00

Comments in demo and opengl code + Internals: Added HoveredIdNotActiveTimer tracking hovering time unless the item is active, which is a commonly useful pattern.

This commit is contained in:
omar 2018-10-25 17:31:16 +02:00
parent e610afeea3
commit ac9aaf4b6e
4 changed files with 26 additions and 18 deletions

View File

@ -306,7 +306,7 @@ void ImGui_ImplOpenGL3_DestroyFontsTexture()
} }
} }
// If you get an error please report on github. You may try different GL context version or GLSL version. // If you get an error please report on github. You may try different GL context version or GLSL version. See GL<>GLSL version table at the top of this file.
static bool CheckShader(GLuint handle, const char* desc) static bool CheckShader(GLuint handle, const char* desc)
{ {
GLint status = 0, log_length = 0; GLint status = 0, log_length = 0;
@ -324,14 +324,14 @@ static bool CheckShader(GLuint handle, const char* desc)
return (GLboolean)status == GL_TRUE; return (GLboolean)status == GL_TRUE;
} }
// If you get an error please report on github. You may try different GL context version or GLSL version. // If you get an error please report on GitHub. You may try different GL context version or GLSL version.
static bool CheckProgram(GLuint handle, const char* desc) static bool CheckProgram(GLuint handle, const char* desc)
{ {
GLint status = 0, log_length = 0; GLint status = 0, log_length = 0;
glGetProgramiv(handle, GL_LINK_STATUS, &status); glGetProgramiv(handle, GL_LINK_STATUS, &status);
glGetProgramiv(handle, GL_INFO_LOG_LENGTH, &log_length); glGetProgramiv(handle, GL_INFO_LOG_LENGTH, &log_length);
if ((GLboolean)status == GL_FALSE) if ((GLboolean)status == GL_FALSE)
fprintf(stderr, "ERROR: ImGui_ImplOpenGL3_CreateDeviceObjects: failed to link %s!\n", desc); fprintf(stderr, "ERROR: ImGui_ImplOpenGL3_CreateDeviceObjects: failed to link %s! (with GLSL '%s')\n", desc, g_GlslVersionString);
if (log_length > 0) if (log_length > 0)
{ {
ImVector<char> buf; ImVector<char> buf;

View File

@ -2511,7 +2511,7 @@ void ImGui::SetHoveredID(ImGuiID id)
g.HoveredId = id; g.HoveredId = id;
g.HoveredIdAllowOverlap = false; g.HoveredIdAllowOverlap = false;
if (id != 0 && g.HoveredIdPreviousFrame != id) if (id != 0 && g.HoveredIdPreviousFrame != id)
g.HoveredIdTimer = 0.0f; g.HoveredIdTimer = g.HoveredIdNotActiveTimer = 0.0f;
} }
ImGuiID ImGui::GetHoveredID() ImGuiID ImGui::GetHoveredID()
@ -3191,8 +3191,12 @@ void ImGui::NewFrame()
// Clear reference to active widget if the widget isn't alive anymore // Clear reference to active widget if the widget isn't alive anymore
if (!g.HoveredIdPreviousFrame) if (!g.HoveredIdPreviousFrame)
g.HoveredIdTimer = 0.0f; g.HoveredIdTimer = 0.0f;
if (!g.HoveredIdPreviousFrame || (g.HoveredId && g.ActiveId == g.HoveredId))
g.HoveredIdNotActiveTimer = 0.0f;
if (g.HoveredId) if (g.HoveredId)
g.HoveredIdTimer += g.IO.DeltaTime; g.HoveredIdTimer += g.IO.DeltaTime;
if (g.HoveredId && g.ActiveId != g.HoveredId)
g.HoveredIdNotActiveTimer += g.IO.DeltaTime;
g.HoveredIdPreviousFrame = g.HoveredId; g.HoveredIdPreviousFrame = g.HoveredId;
g.HoveredId = 0; g.HoveredId = 0;
g.HoveredIdAllowOverlap = false; g.HoveredIdAllowOverlap = false;

View File

@ -1,22 +1,25 @@
// dear imgui, v1.66 WIP // dear imgui, v1.66 WIP
// (demo code) // (demo code)
// Message to the person tempted to delete this file when integrating ImGui into their code base: // Message to the person tempted to delete this file when integrating Dear ImGui into their code base:
// Don't do it! Do NOT remove this file from your project! It is useful reference code that you and other users will want to refer to. // Do NOT remove this file from your project! Think again! It is the most useful reference code that you and other coders
// will want to refer to and call. Have the ImGui::ShowDemoWindow() function wired in an always-available debug menu of
// your game/app! Removing this file from your project is hindering access to documentation for everyone in your team,
// likely leading you to poorer usage of the library.
// Everything in this file will be stripped out by the linker if you don't call ImGui::ShowDemoWindow(). // Everything in this file will be stripped out by the linker if you don't call ImGui::ShowDemoWindow().
// During development, you can call ImGui::ShowDemoWindow() in your code to learn about various features of ImGui. Have it wired in a debug menu! // If you want to link core Dear ImGui in your shipped builds but want an easy guarantee that the demo will not be linked,
// Removing this file from your project is hindering access to documentation for everyone in your team, likely leading you to poorer usage of the library. // you can setup your imconfig.h with #define IMGUI_DISABLE_DEMO_WINDOWS and those functions will be empty.
// Note that you can #define IMGUI_DISABLE_DEMO_WINDOWS in imconfig.h for the same effect. // In other situation, whenever you have Dear ImGui available you probably want this to be available for reference.
// If you want to link core ImGui in your final builds but not those demo windows, #define IMGUI_DISABLE_DEMO_WINDOWS in imconfig.h and those functions will be empty.
// In other situation, when you have ImGui available you probably want this to be available for reference and execution.
// Thank you, // Thank you,
// -Your beloved friend, imgui_demo.cpp (that you won't delete) // -Your beloved friend, imgui_demo.cpp (that you won't delete)
// Message to beginner C/C++ programmers about the meaning of the 'static' keyword: in this demo code, we frequently we use 'static' variables inside functions. // Message to beginner C/C++ programmers about the meaning of the 'static' keyword:
// A static variable persist across calls, so it is essentially like a global variable but declared inside the scope of the function. // In this demo code, we frequently we use 'static' variables inside functions. A static variable persist across calls, so it is
// We do this as a way to gather code and data in the same place, just to make the demo code faster to read, faster to write, and use less code. // essentially like a global variable but declared inside the scope of the function. We do this as a way to gather code and data
// It also happens to be a convenient way of storing simple UI related information as long as your function doesn't need to be reentrant or used in threads. // in the same place, to make the demo source code faster to read, faster to write, and smaller in size.
// This might be a pattern you occasionally want to use in your code, but most of the real data you would be editing is likely to be stored outside your functions. // It also happens to be a convenient way of storing simple UI related information as long as your function doesn't need to be reentrant
// or used in threads. This might be a pattern you will want to use in your code, but most of the real data you would be editing is
// likely going to be stored outside your functions.
/* /*

View File

@ -662,7 +662,8 @@ struct ImGuiContext
ImGuiID HoveredId; // Hovered widget ImGuiID HoveredId; // Hovered widget
bool HoveredIdAllowOverlap; bool HoveredIdAllowOverlap;
ImGuiID HoveredIdPreviousFrame; ImGuiID HoveredIdPreviousFrame;
float HoveredIdTimer; float HoveredIdTimer; // Measure contiguous hovering time
float HoveredIdNotActiveTimer; // Measure contiguous hovering time where the item has not been active
ImGuiID ActiveId; // Active widget ImGuiID ActiveId; // Active widget
ImGuiID ActiveIdPreviousFrame; ImGuiID ActiveIdPreviousFrame;
ImGuiID ActiveIdIsAlive; // Active widget has been seen this frame (we can't use a bool as the ActiveId may change within the frame) ImGuiID ActiveIdIsAlive; // Active widget has been seen this frame (we can't use a bool as the ActiveId may change within the frame)
@ -809,7 +810,7 @@ struct ImGuiContext
HoveredId = 0; HoveredId = 0;
HoveredIdAllowOverlap = false; HoveredIdAllowOverlap = false;
HoveredIdPreviousFrame = 0; HoveredIdPreviousFrame = 0;
HoveredIdTimer = 0.0f; HoveredIdTimer = HoveredIdNotActiveTimer = 0.0f;
ActiveId = 0; ActiveId = 0;
ActiveIdPreviousFrame = 0; ActiveIdPreviousFrame = 0;
ActiveIdIsAlive = 0; ActiveIdIsAlive = 0;