mirror of
https://github.com/ocornut/imgui.git
synced 2025-10-17 23:41:45 +00:00
Merge branch 'master' into docking
# Conflicts: # backends/imgui_impl_metal.mm # backends/imgui_impl_opengl3.cpp # imgui.cpp
This commit is contained in:
171
imgui.cpp
171
imgui.cpp
@@ -11,7 +11,7 @@
|
||||
// - FAQ http://dearimgui.org/faq
|
||||
// - Homepage & latest https://github.com/ocornut/imgui
|
||||
// - Releases & changelog https://github.com/ocornut/imgui/releases
|
||||
// - Gallery https://github.com/ocornut/imgui/issues/4451 (please post your screenshots/video there!)
|
||||
// - Gallery https://github.com/ocornut/imgui/issues/5243 (please post your screenshots/video there!)
|
||||
// - Wiki https://github.com/ocornut/imgui/wiki (lots of good stuff there)
|
||||
// - Glossary https://github.com/ocornut/imgui/wiki/Glossary
|
||||
// - Issues & support https://github.com/ocornut/imgui/issues
|
||||
@@ -4227,7 +4227,9 @@ void ImGui::UpdateMouseWheel()
|
||||
}
|
||||
}
|
||||
|
||||
if (g.IO.MouseWheel == 0.0f && g.IO.MouseWheelH == 0.0f)
|
||||
float wheel_x = g.IO.MouseWheelH;
|
||||
float wheel_y = g.IO.MouseWheel;
|
||||
if (wheel_x == 0.0f && wheel_y == 0.0f)
|
||||
return;
|
||||
|
||||
if ((g.ActiveId != 0 && g.ActiveIdUsingMouseWheel) || (g.HoveredIdPreviousFrame != 0 && g.HoveredIdPreviousFrameUsingMouseWheel))
|
||||
@@ -4239,7 +4241,7 @@ void ImGui::UpdateMouseWheel()
|
||||
|
||||
// Zoom / Scale window
|
||||
// FIXME-OBSOLETE: This is an old feature, it still works but pretty much nobody is using it and may be best redesigned.
|
||||
if (g.IO.MouseWheel != 0.0f && g.IO.KeyCtrl && g.IO.FontAllowUserScaling)
|
||||
if (wheel_y != 0.0f && g.IO.KeyCtrl && g.IO.FontAllowUserScaling)
|
||||
{
|
||||
StartLockWheelingWindow(window);
|
||||
const float new_font_scale = ImClamp(window->FontWindowScale + g.IO.MouseWheel * 0.10f, 0.50f, 2.50f);
|
||||
@@ -4263,8 +4265,11 @@ void ImGui::UpdateMouseWheel()
|
||||
// As a standard behavior holding SHIFT while using Vertical Mouse Wheel triggers Horizontal scroll instead
|
||||
// (we avoid doing it on OSX as it the OS input layer handles this already)
|
||||
const bool swap_axis = g.IO.KeyShift && !g.IO.ConfigMacOSXBehaviors;
|
||||
const float wheel_y = swap_axis ? 0.0f : g.IO.MouseWheel;
|
||||
const float wheel_x = swap_axis ? g.IO.MouseWheel : g.IO.MouseWheelH;
|
||||
if (swap_axis)
|
||||
{
|
||||
wheel_x = wheel_y;
|
||||
wheel_y = 0.0f;
|
||||
}
|
||||
|
||||
// Vertical Mouse Wheel scrolling
|
||||
if (wheel_y != 0.0f)
|
||||
@@ -8170,14 +8175,6 @@ const char* ImGui::GetKeyName(ImGuiKey key)
|
||||
return GKeyNames[key - ImGuiKey_NamedKey_BEGIN];
|
||||
}
|
||||
|
||||
// Note that Dear ImGui doesn't know the meaning/semantic of ImGuiKey from 0..511: they are legacy native keycodes.
|
||||
// Consider transitioning from 'IsKeyDown(MY_ENGINE_KEY_A)' (<1.87) to IsKeyDown(ImGuiKey_A) (>= 1.87)
|
||||
bool ImGui::IsKeyDown(ImGuiKey key)
|
||||
{
|
||||
const ImGuiKeyData* key_data = GetKeyData(key);
|
||||
return key_data->Down;
|
||||
}
|
||||
|
||||
// t0 = previous time (e.g.: g.Time - g.IO.DeltaTime)
|
||||
// t1 = current time (e.g.: g.Time)
|
||||
// An event is triggered at:
|
||||
@@ -8204,22 +8201,35 @@ int ImGui::GetKeyPressedAmount(ImGuiKey key, float repeat_delay, float repeat_ra
|
||||
return CalcTypematicRepeatAmount(t - g.IO.DeltaTime, t, repeat_delay, repeat_rate);
|
||||
}
|
||||
|
||||
// Note that Dear ImGui doesn't know the meaning/semantic of ImGuiKey from 0..511: they are legacy native keycodes.
|
||||
// Consider transitioning from 'IsKeyDown(MY_ENGINE_KEY_A)' (<1.87) to IsKeyDown(ImGuiKey_A) (>= 1.87)
|
||||
bool ImGui::IsKeyDown(ImGuiKey key)
|
||||
{
|
||||
const ImGuiKeyData* key_data = GetKeyData(key);
|
||||
if (!key_data->Down)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ImGui::IsKeyPressed(ImGuiKey key, bool repeat)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
const ImGuiKeyData* key_data = GetKeyData(key);
|
||||
const float t = key_data->DownDuration;
|
||||
if (t == 0.0f)
|
||||
return true;
|
||||
if (repeat && t > g.IO.KeyRepeatDelay)
|
||||
return GetKeyPressedAmount(key, g.IO.KeyRepeatDelay, g.IO.KeyRepeatRate) > 0;
|
||||
return false;
|
||||
if (t < 0.0f)
|
||||
return false;
|
||||
const bool pressed = (t == 0.0f) || (repeat && t > g.IO.KeyRepeatDelay && GetKeyPressedAmount(key, g.IO.KeyRepeatDelay, g.IO.KeyRepeatRate) > 0);
|
||||
if (!pressed)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ImGui::IsKeyReleased(ImGuiKey key)
|
||||
{
|
||||
const ImGuiKeyData* key_data = GetKeyData(key);
|
||||
return key_data->DownDurationPrev >= 0.0f && !key_data->Down;
|
||||
if (key_data->DownDurationPrev < 0.0f || key_data->Down)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ImGui::IsMouseDown(ImGuiMouseButton button)
|
||||
@@ -17501,12 +17511,16 @@ static void SetPlatformImeDataFn_DefaultImpl(ImGuiViewport*, ImGuiPlatformImeDat
|
||||
//-----------------------------------------------------------------------------
|
||||
// - RenderViewportThumbnail() [Internal]
|
||||
// - RenderViewportsThumbnails() [Internal]
|
||||
// - DebugTextEncoding()
|
||||
// - MetricsHelpMarker() [Internal]
|
||||
// - ShowFontAtlas() [Internal]
|
||||
// - ShowMetricsWindow()
|
||||
// - DebugNodeColumns() [Internal]
|
||||
// - DebugNodeDockNode() [Internal]
|
||||
// - DebugNodeDrawList() [Internal]
|
||||
// - DebugNodeDrawCmdShowMeshAndBoundingBox() [Internal]
|
||||
// - DebugNodeFont() [Internal]
|
||||
// - DebugNodeFontGlyph() [Internal]
|
||||
// - DebugNodeStorage() [Internal]
|
||||
// - DebugNodeTabBar() [Internal]
|
||||
// - DebugNodeViewport() [Internal]
|
||||
@@ -17573,11 +17587,47 @@ static void RenderViewportsThumbnails()
|
||||
|
||||
static int IMGUI_CDECL ViewportComparerByFrontMostStampCount(const void* lhs, const void* rhs)
|
||||
{
|
||||
const ImGuiViewportP* a = *(const ImGuiViewportP* const *)lhs;
|
||||
const ImGuiViewportP* b = *(const ImGuiViewportP* const *)rhs;
|
||||
const ImGuiViewportP* a = *(const ImGuiViewportP* const*)lhs;
|
||||
const ImGuiViewportP* b = *(const ImGuiViewportP* const*)rhs;
|
||||
return b->LastFrontMostStampCount - a->LastFrontMostStampCount;
|
||||
}
|
||||
|
||||
// Helper tool to diagnose between text encoding issues and font loading issues. Pass your UTF-8 string and verify that there are correct.
|
||||
void ImGui::DebugTextEncoding(const char* str)
|
||||
{
|
||||
Text("Text: \"%s\"", str);
|
||||
if (!BeginTable("list", 4, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit))
|
||||
return;
|
||||
TableSetupColumn("Offset");
|
||||
TableSetupColumn("UTF-8");
|
||||
TableSetupColumn("Glyph");
|
||||
TableSetupColumn("Codepoint");
|
||||
TableHeadersRow();
|
||||
for (const char* p = str; *p != 0; )
|
||||
{
|
||||
unsigned int c;
|
||||
const int c_utf8_len = ImTextCharFromUtf8(&c, p, NULL);
|
||||
TableNextColumn();
|
||||
Text("%d", (int)(p - str));
|
||||
TableNextColumn();
|
||||
for (int byte_index = 0; byte_index < c_utf8_len; byte_index++)
|
||||
{
|
||||
if (byte_index > 0)
|
||||
SameLine();
|
||||
Text("0x%02X", (int)(unsigned char)p[byte_index]);
|
||||
}
|
||||
TableNextColumn();
|
||||
if (GetFont()->FindGlyphNoFallback((ImWchar)c))
|
||||
TextUnformatted(p, p + c_utf8_len);
|
||||
else
|
||||
TextUnformatted((c == IM_UNICODE_CODEPOINT_INVALID) ? "[invalid]" : "[missing]");
|
||||
TableNextColumn();
|
||||
Text("U+%04X", (int)c);
|
||||
p += c_utf8_len;
|
||||
}
|
||||
EndTable();
|
||||
}
|
||||
|
||||
// Avoid naming collision with imgui_demo.cpp's HelpMarker() for unity builds.
|
||||
static void MetricsHelpMarker(const char* desc)
|
||||
{
|
||||
@@ -17592,9 +17642,24 @@ static void MetricsHelpMarker(const char* desc)
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef IMGUI_DISABLE_DEMO_WINDOWS
|
||||
namespace ImGui { void ShowFontAtlas(ImFontAtlas* atlas); }
|
||||
#endif
|
||||
// [DEBUG] List fonts in a font atlas and display its texture
|
||||
void ImGui::ShowFontAtlas(ImFontAtlas* atlas)
|
||||
{
|
||||
for (int i = 0; i < atlas->Fonts.Size; i++)
|
||||
{
|
||||
ImFont* font = atlas->Fonts[i];
|
||||
PushID(font);
|
||||
DebugNodeFont(font);
|
||||
PopID();
|
||||
}
|
||||
if (TreeNode("Atlas texture", "Atlas texture (%dx%d pixels)", atlas->TexWidth, atlas->TexHeight))
|
||||
{
|
||||
ImVec4 tint_col = ImVec4(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
ImVec4 border_col = ImVec4(1.0f, 1.0f, 1.0f, 0.5f);
|
||||
Image(atlas->TexID, ImVec2((float)atlas->TexWidth, (float)atlas->TexHeight), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f), tint_col, border_col);
|
||||
TreePop();
|
||||
}
|
||||
}
|
||||
|
||||
void ImGui::ShowMetricsWindow(bool* p_open)
|
||||
{
|
||||
@@ -17669,6 +17734,19 @@ void ImGui::ShowMetricsWindow(bool* p_open)
|
||||
// Tools
|
||||
if (TreeNode("Tools"))
|
||||
{
|
||||
bool show_encoding_viewer = TreeNode("UTF-8 Encoding viewer");
|
||||
SameLine();
|
||||
MetricsHelpMarker("You can also call ImGui::DebugTextEncoding() from your code with a given string to test that your UTF-8 encoding settings are correct.");
|
||||
if (show_encoding_viewer)
|
||||
{
|
||||
static char buf[100] = "";
|
||||
SetNextItemWidth(-FLT_MIN);
|
||||
InputText("##Text", buf, IM_ARRAYSIZE(buf));
|
||||
if (buf[0] != 0)
|
||||
DebugTextEncoding(buf);
|
||||
TreePop();
|
||||
}
|
||||
|
||||
// Stack Tool is your best friend!
|
||||
Checkbox("Show stack tool", &cfg->ShowStackTool);
|
||||
SameLine();
|
||||
@@ -17867,14 +17945,12 @@ void ImGui::ShowMetricsWindow(bool* p_open)
|
||||
}
|
||||
|
||||
// Details for Fonts
|
||||
#ifndef IMGUI_DISABLE_DEMO_WINDOWS
|
||||
ImFontAtlas* atlas = g.IO.Fonts;
|
||||
if (TreeNode("Fonts", "Fonts (%d)", atlas->Fonts.Size))
|
||||
{
|
||||
ShowFontAtlas(atlas);
|
||||
TreePop();
|
||||
}
|
||||
#endif
|
||||
|
||||
// Details for Docking
|
||||
#ifdef IMGUI_HAS_DOCK
|
||||
@@ -18083,25 +18159,6 @@ void ImGui::ShowMetricsWindow(bool* p_open)
|
||||
End();
|
||||
}
|
||||
|
||||
// [DEBUG] List fonts in a font atlas and display its texture
|
||||
void ImGui::ShowFontAtlas(ImFontAtlas* atlas)
|
||||
{
|
||||
for (int i = 0; i < atlas->Fonts.Size; i++)
|
||||
{
|
||||
ImFont* font = atlas->Fonts[i];
|
||||
PushID(font);
|
||||
DebugNodeFont(font);
|
||||
PopID();
|
||||
}
|
||||
if (TreeNode("Atlas texture", "Atlas texture (%dx%d pixels)", atlas->TexWidth, atlas->TexHeight))
|
||||
{
|
||||
ImVec4 tint_col = ImVec4(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
ImVec4 border_col = ImVec4(1.0f, 1.0f, 1.0f, 0.5f);
|
||||
Image(atlas->TexID, ImVec2((float)atlas->TexWidth, (float)atlas->TexHeight), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f), tint_col, border_col);
|
||||
TreePop();
|
||||
}
|
||||
}
|
||||
|
||||
// [DEBUG] Display contents of Columns
|
||||
void ImGui::DebugNodeColumns(ImGuiOldColumns* columns)
|
||||
{
|
||||
@@ -18395,17 +18452,13 @@ void ImGui::DebugNodeFont(ImFont* font)
|
||||
ImVec2 cell_p2(cell_p1.x + cell_size, cell_p1.y + cell_size);
|
||||
const ImFontGlyph* glyph = font->FindGlyphNoFallback((ImWchar)(base + n));
|
||||
draw_list->AddRect(cell_p1, cell_p2, glyph ? IM_COL32(255, 255, 255, 100) : IM_COL32(255, 255, 255, 50));
|
||||
if (glyph)
|
||||
font->RenderChar(draw_list, cell_size, cell_p1, glyph_col, (ImWchar)(base + n));
|
||||
if (glyph && IsMouseHoveringRect(cell_p1, cell_p2))
|
||||
if (!glyph)
|
||||
continue;
|
||||
font->RenderChar(draw_list, cell_size, cell_p1, glyph_col, (ImWchar)(base + n));
|
||||
if (IsMouseHoveringRect(cell_p1, cell_p2))
|
||||
{
|
||||
BeginTooltip();
|
||||
Text("Codepoint: U+%04X", base + n);
|
||||
Separator();
|
||||
Text("Visible: %d", glyph->Visible);
|
||||
Text("AdvanceX: %.1f", glyph->AdvanceX);
|
||||
Text("Pos: (%.2f,%.2f)->(%.2f,%.2f)", glyph->X0, glyph->Y0, glyph->X1, glyph->Y1);
|
||||
Text("UV: (%.3f,%.3f)->(%.3f,%.3f)", glyph->U0, glyph->V0, glyph->U1, glyph->V1);
|
||||
DebugNodeFontGlyph(font, glyph);
|
||||
EndTooltip();
|
||||
}
|
||||
}
|
||||
@@ -18417,6 +18470,16 @@ void ImGui::DebugNodeFont(ImFont* font)
|
||||
TreePop();
|
||||
}
|
||||
|
||||
void ImGui::DebugNodeFontGlyph(ImFont*, const ImFontGlyph* glyph)
|
||||
{
|
||||
Text("Codepoint: U+%04X", glyph->Codepoint);
|
||||
Separator();
|
||||
Text("Visible: %d", glyph->Visible);
|
||||
Text("AdvanceX: %.1f", glyph->AdvanceX);
|
||||
Text("Pos: (%.2f,%.2f)->(%.2f,%.2f)", glyph->X0, glyph->Y0, glyph->X1, glyph->Y1);
|
||||
Text("UV: (%.3f,%.3f)->(%.3f,%.3f)", glyph->U0, glyph->V0, glyph->U1, glyph->V1);
|
||||
}
|
||||
|
||||
// [DEBUG] Display contents of ImGuiStorage
|
||||
void ImGui::DebugNodeStorage(ImGuiStorage* storage, const char* label)
|
||||
{
|
||||
|
Reference in New Issue
Block a user