Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/wolfpld/tracy.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBartosz Taudul <wolf@nereid.pl>2022-04-27 01:49:37 +0300
committerBartosz Taudul <wolf@nereid.pl>2022-04-27 01:49:37 +0300
commit0d547bf4db36c0e83ac8d36376d5b0edff60bf7d (patch)
tree8ca12de050e9229ea49bb85177c9e06412601b1a /imgui/imgui.cpp
parentbc36f5ff27d1bd226cf94612325949218562ea93 (diff)
Update ImGui to 1.87 + docking.
Diffstat (limited to 'imgui/imgui.cpp')
-rw-r--r--imgui/imgui.cpp1472
1 files changed, 1002 insertions, 470 deletions
diff --git a/imgui/imgui.cpp b/imgui/imgui.cpp
index 579d8356..b5fa1bf2 100644
--- a/imgui/imgui.cpp
+++ b/imgui/imgui.cpp
@@ -1,4 +1,4 @@
-// dear imgui, v1.86
+// dear imgui, v1.87
// (main code and documentation)
// Help:
@@ -70,6 +70,7 @@ CODE
// [SECTION] STYLING
// [SECTION] RENDER HELPERS
// [SECTION] MAIN CODE (most of the code! lots of stuff, needs tidying up!)
+// [SECTION] INPUTS
// [SECTION] ERROR CHECKING
// [SECTION] LAYOUT
// [SECTION] SCROLLING
@@ -128,7 +129,6 @@ CODE
- CTRL+X,CTRL+C,CTRL+V to use OS clipboard/
- CTRL+Z,CTRL+Y to undo/redo.
- ESCAPE to revert text to its original value.
- - You can apply arithmetic operators +,*,/ on numerical values. Use +- to subtract (because - would set a negative value!)
- Controls are automatically adjusted for OSX to match standard OSX text editing operations.
- General Keyboard controls: enable with ImGuiConfigFlags_NavEnableKeyboard.
- General Gamepad controls: enable with ImGuiConfigFlags_NavEnableGamepad. See suggested mappings in imgui.h ImGuiNavInput_ + download PNG/PSD at http://dearimgui.org/controls_sheets
@@ -255,9 +255,9 @@ CODE
io.DeltaTime = 1.0f/60.0f; // set the time elapsed since the previous frame (in seconds)
io.DisplaySize.x = 1920.0f; // set the current display width
io.DisplaySize.y = 1280.0f; // set the current display height here
- io.MousePos = my_mouse_pos; // set the mouse position
- io.MouseDown[0] = my_mouse_buttons[0]; // set the mouse button states
- io.MouseDown[1] = my_mouse_buttons[1];
+ io.AddMousePosEvent(mouse_x, mouse_y); // update mouse position
+ io.AddMouseButtonEvent(0, mouse_b[0]); // update mouse button states
+ io.AddMouseButtonEvent(1, mouse_b[1]); // update mouse button states
// Call NewFrame(), after this point you can use ImGui::* functions anytime
// (So you want to try calling NewFrame() as early as you can in your main loop to be able to use Dear ImGui everywhere)
@@ -295,6 +295,7 @@ CODE
// TODO: Setup viewport covering draw_data->DisplayPos to draw_data->DisplayPos + draw_data->DisplaySize
// TODO: Setup orthographic projection matrix cover draw_data->DisplayPos to draw_data->DisplayPos + draw_data->DisplaySize
// TODO: Setup shader: vertex { float2 pos, float2 uv, u32 color }, fragment shader sample color from 1 texture, multiply by vertex color.
+ ImVec2 clip_off = draw_data->DisplayPos;
for (int n = 0; n < draw_data->CmdListsCount; n++)
{
const ImDrawList* cmd_list = draw_data->CmdLists[n];
@@ -309,9 +310,11 @@ CODE
}
else
{
- // The texture for the draw call is specified by pcmd->GetTexID().
- // The vast majority of draw calls will use the Dear ImGui texture atlas, which value you have set yourself during initialization.
- MyEngineBindTexture((MyTexture*)pcmd->GetTexID());
+ // Project scissor/clipping rectangles into framebuffer space
+ ImVec2 clip_min(pcmd->ClipRect.x - clip_off.x, pcmd->ClipRect.y - clip_off.y);
+ ImVec2 clip_max(pcmd->ClipRect.z - clip_off.x, pcmd->ClipRect.w - clip_off.y);
+ if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y)
+ continue;
// We are using scissoring to clip some objects. All low-level graphics API should support it.
// - If your engine doesn't support scissoring yet, you may ignore this at first. You will get some small glitches
@@ -322,14 +325,16 @@ CODE
// - In the interest of supporting multi-viewport applications (see 'docking' branch on github),
// always subtract draw_data->DisplayPos from clipping bounds to convert them to your viewport space.
// - Note that pcmd->ClipRect contains Min+Max bounds. Some graphics API may use Min+Max, other may use Min+Size (size being Max-Min)
- ImVec2 pos = draw_data->DisplayPos;
- MyEngineScissor((int)(pcmd->ClipRect.x - pos.x), (int)(pcmd->ClipRect.y - pos.y), (int)(pcmd->ClipRect.z - pos.x), (int)(pcmd->ClipRect.w - pos.y));
+ MyEngineSetScissor(clip_min.x, clip_min.y, clip_max.x, clip_max.y);
+
+ // The texture for the draw call is specified by pcmd->GetTexID().
+ // The vast majority of draw calls will use the Dear ImGui texture atlas, which value you have set yourself during initialization.
+ MyEngineBindTexture((MyTexture*)pcmd->GetTexID());
// Render 'pcmd->ElemCount/3' indexed triangles.
// By default the indices ImDrawIdx are 16-bit, you can change them to 32-bit in imconfig.h if your engine doesn't support 16-bit indices.
- MyEngineDrawIndexedTriangles(pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer, vtx_buffer);
+ MyEngineDrawIndexedTriangles(pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer + pcmd->IdxOffset, vtx_buffer, pcmd->VtxOffset);
}
- idx_buffer += pcmd->ElemCount;
}
}
}
@@ -342,27 +347,26 @@ CODE
- You can ask questions and report issues at https://github.com/ocornut/imgui/issues/787
- The initial focus was to support game controllers, but keyboard is becoming increasingly and decently usable.
- Keyboard:
- - Set io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard to enable.
- NewFrame() will automatically fill io.NavInputs[] based on your io.KeysDown[] + io.KeyMap[] arrays.
- - When keyboard navigation is active (io.NavActive + ImGuiConfigFlags_NavEnableKeyboard), the io.WantCaptureKeyboard flag
- will be set. For more advanced uses, you may want to read from:
+ - Application: Set io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard to enable.
+ - Internally: NewFrame() will automatically fill io.NavInputs[] based on backend's io.AddKeyEvent() calls.
+ - When keyboard navigation is active (io.NavActive + ImGuiConfigFlags_NavEnableKeyboard),
+ the io.WantCaptureKeyboard flag will be set. For more advanced uses, you may want to read from:
- io.NavActive: true when a window is focused and it doesn't have the ImGuiWindowFlags_NoNavInputs flag set.
- io.NavVisible: true when the navigation cursor is visible (and usually goes false when mouse is used).
- or query focus information with e.g. IsWindowFocused(ImGuiFocusedFlags_AnyWindow), IsItemFocused() etc. functions.
Please reach out if you think the game vs navigation input sharing could be improved.
- Gamepad:
- - Set io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad to enable.
- - Backend: Set io.BackendFlags |= ImGuiBackendFlags_HasGamepad + fill the io.NavInputs[] fields before calling NewFrame().
- Note that io.NavInputs[] is cleared by EndFrame().
- - See 'enum ImGuiNavInput_' in imgui.h for a description of inputs. For each entry of io.NavInputs[], set the following values:
- 0.0f= not held. 1.0f= fully held. Pass intermediate 0.0f..1.0f values for analog triggers/sticks.
- - We use a simple >0.0f test for activation testing, and won't attempt to test for a dead-zone.
- Your code will probably need to transform your raw inputs (such as e.g. remapping your 0.2..0.9 raw input range to 0.0..1.0 imgui range, etc.).
+ - Application: Set io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad to enable.
+ - Backend: Set io.BackendFlags |= ImGuiBackendFlags_HasGamepad + call io.AddKeyEvent/AddKeyAnalogEvent() with ImGuiKey_Gamepad_XXX keys.
+ For analog values (0.0f to 1.0f), backend is responsible to handling a dead-zone and rescaling inputs accordingly.
+ Backend code will probably need to transform your raw inputs (such as e.g. remapping your 0.2..0.9 raw input range to 0.0..1.0 imgui range, etc.).
+ - Internally: NewFrame() will automatically fill io.NavInputs[] based on backend's io.AddKeyEvent() + io.AddKeyAnalogEvent() calls.
+ - BEFORE 1.87, BACKENDS USED TO WRITE DIRECTLY TO io.NavInputs[]. This is going to be obsoleted in the future. Please call io functions instead!
- You can download PNG/PSD files depicting the gamepad controls for common controllers at: http://dearimgui.org/controls_sheets
- - If you need to share inputs between your game and the imgui parts, the easiest approach is to go all-or-nothing, with a buttons combo
- to toggle the target. Please reach out if you think the game vs navigation input sharing could be improved.
+ - If you need to share inputs between your game and the Dear ImGui interface, the easiest approach is to go all-or-nothing,
+ with a buttons combo to toggle the target. Please reach out if you think the game vs navigation input sharing could be improved.
- Mouse:
- - PS4 users: Consider emulating a mouse cursor with DualShock4 touch pad or a spare analog stick as a mouse-emulation fallback.
+ - PS4/PS5 users: Consider emulating a mouse cursor with DualShock4 touch pad or a spare analog stick as a mouse-emulation fallback.
- Consoles/Tablet/Phone users: Consider using a Synergy 1.x server (on your PC) + uSynergy.c (on your console/tablet/phone app) to share your PC mouse/keyboard.
- On a TV/console system where readability may be lower or mouse inputs may be awkward, you may want to set the ImGuiConfigFlags_NavEnableSetMousePos flag.
Enabling ImGuiConfigFlags_NavEnableSetMousePos + ImGuiBackendFlags_HasSetMousePos instructs dear imgui to move your mouse cursor along with navigation movements.
@@ -387,9 +391,30 @@ CODE
you may use GetMainViewport()->Pos to offset hard-coded positions, e.g. SetNextWindowPos(GetMainViewport()->Pos)
- likewise io.MousePos and GetMousePos() will use OS coordinates.
If you query mouse positions to interact with non-imgui coordinates you will need to offset them, e.g. subtract GetWindowViewport()->Pos.
- - 2021/XX/XX (1.XX) - Moved IME support functions from io.ImeSetInputScreenPosFn, io.ImeWindowHandle to the PlatformIO api.
-
+ - 2022/01/20 (1.87) - inputs: reworded gamepad IO.
+ - Backend writing to io.NavInputs[] -> backend should call io.AddKeyEvent()/io.AddKeyAnalogEvent() with ImGuiKey_GamepadXXX values.
+ - 2022/01/19 (1.87) - sliders, drags: removed support for legacy arithmetic operators (+,+-,*,/) when inputing text. This doesn't break any api/code but a feature that used to be accessible by end-users (which seemingly no one used).
+ - 2022/01/17 (1.87) - inputs: reworked mouse IO.
+ - Backend writing to io.MousePos -> backend should call io.AddMousePosEvent()
+ - Backend writing to io.MouseDown[] -> backend should call io.AddMouseButtonEvent()
+ - Backend writing to io.MouseWheel -> backend should call io.AddMouseWheelEvent()
+ - Backend writing to io.MouseHoveredViewport -> backend should call io.AddMouseViewportEvent() [Docking branch w/ multi-viewports only]
+ - 2022/01/10 (1.87) - inputs: reworked keyboard IO. Removed io.KeyMap[], io.KeysDown[] in favor of calling io.AddKeyEvent(). Removed GetKeyIndex(), now unecessary. All IsKeyXXX() functions now take ImGuiKey values. All features are still functional until IMGUI_DISABLE_OBSOLETE_KEYIO is defined. Read Changelog and Release Notes for details.
+ - IsKeyPressed(MY_NATIVE_KEY_XXX) -> use IsKeyPressed(ImGuiKey_XXX)
+ - IsKeyPressed(GetKeyIndex(ImGuiKey_XXX)) -> use IsKeyPressed(ImGuiKey_XXX)
+ - Backend writing to io.KeyMap[],io.KeysDown[] -> backend should call io.AddKeyEvent()
+ - Backend writing to io.KeyCtrl, io.KeyShift.. -> backend should call io.AddKeyEvent() with ImGuiKey_ModXXX values. *IF YOU PULLED CODE BETWEEN 2021/01/10 and 2021/01/27: We used to have a io.AddKeyModsEvent() function which was now replaced by io.AddKeyEvent() with ImGuiKey_ModXXX values.*
+ - one case won't work with backward compatibility: if your custom backend used ImGuiKey as mock native indices (e.g. "io.KeyMap[ImGuiKey_A] = ImGuiKey_A") because those values are now larger than the legacy KeyDown[] array. Will assert.
+ - inputs: added ImGuiKey_ModCtrl/ImGuiKey_ModShift/ImGuiKey_ModAlt/ImGuiKey_ModSuper values to submit keyboard modifiers using io.AddKeyEvent(), instead of writing directly to io.KeyCtrl, io.KeyShift, io.KeyAlt, io.KeySuper.
+ - 2022/01/05 (1.87) - inputs: renamed ImGuiKey_KeyPadEnter to ImGuiKey_KeypadEnter to align with new symbols. Kept redirection enum.
+ - 2022/01/05 (1.87) - removed io.ImeSetInputScreenPosFn() in favor of more flexible io.SetPlatformImeDataFn(). Removed 'void* io.ImeWindowHandle' in favor of writing to 'void* ImGuiViewport::PlatformHandleRaw'.
+ - 2022/01/01 (1.87) - commented out redirecting functions/enums names that were marked obsolete in 1.69, 1.70, 1.71, 1.72 (March-July 2019)
+ - ImGui::SetNextTreeNodeOpen() -> use ImGui::SetNextItemOpen()
+ - ImGui::GetContentRegionAvailWidth() -> use ImGui::GetContentRegionAvail().x
+ - ImGui::TreeAdvanceToLabelPos() -> use ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetTreeNodeToLabelSpacing());
+ - ImFontAtlas::CustomRect -> use ImFontAtlasCustomRect
+ - ImGuiColorEditFlags_RGB/HSV/HEX -> use ImGuiColorEditFlags_DisplayRGB/HSV/Hex
- 2021/12/20 (1.86) - backends: removed obsolete Marmalade backend (imgui_impl_marmalade.cpp) + example. Find last supported version at https://github.com/ocornut/imgui/wiki/Bindings
- 2021/11/04 (1.86) - removed CalcListClipping() function. Prefer using ImGuiListClipper which can return non-contiguous ranges. Please open an issue if you think you really need this function.
- 2021/08/23 (1.85) - removed GetWindowContentRegionWidth() function. keep inline redirection helper. can use 'GetWindowContentRegionMax().x - GetWindowContentRegionMin().x' instead for generally 'GetContentRegionAvail().x' is more useful.
@@ -921,6 +946,7 @@ static void WindowSettingsHandler_WriteAll(ImGuiContext*, ImGuiSetti
// Platform Dependents default implementation for IO functions
static const char* GetClipboardTextFn_DefaultImpl(void* user_data);
static void SetClipboardTextFn_DefaultImpl(void* user_data, const char* text);
+static void SetPlatformImeDataFn_DefaultImpl(ImGuiViewport* viewport, ImGuiPlatformImeData* data);
namespace ImGui
{
@@ -954,6 +980,7 @@ static void UpdateDebugToolStackQueries();
// Misc
static void UpdateSettings();
+static void UpdateKeyboardInputs();
static void UpdateMouseInputs();
static void UpdateMouseWheel();
static bool UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& size_auto_fit, int* border_held, int resize_grip_count, ImU32 resize_grip_col[4], const ImRect& visibility_rect);
@@ -1107,7 +1134,7 @@ ImGuiIO::ImGuiIO()
{
// Most fields are initialized with zero
memset(this, 0, sizeof(*this));
- IM_ASSERT(IM_ARRAYSIZE(ImGuiIO::MouseDown) == ImGuiMouseButton_COUNT && IM_ARRAYSIZE(ImGuiIO::MouseClicked) == ImGuiMouseButton_COUNT); // Our pre-C++11 IM_STATIC_ASSERT() macros triggers warning on modern compilers so we don't use it here.
+ IM_STATIC_ASSERT(IM_ARRAYSIZE(ImGuiIO::MouseDown) == ImGuiMouseButton_COUNT && IM_ARRAYSIZE(ImGuiIO::MouseClicked) == ImGuiMouseButton_COUNT);
// Settings
ConfigFlags = ImGuiConfigFlags_None;
@@ -1119,8 +1146,10 @@ ImGuiIO::ImGuiIO()
LogFilename = "imgui_log.txt";
MouseDoubleClickTime = 0.30f;
MouseDoubleClickMaxDist = 6.0f;
+#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO
for (int i = 0; i < ImGuiKey_COUNT; i++)
KeyMap[i] = -1;
+#endif
KeyRepeatDelay = 0.275f;
KeyRepeatRate = 0.050f;
UserData = NULL;
@@ -1150,6 +1179,7 @@ ImGuiIO::ImGuiIO()
#else
ConfigMacOSXBehaviors = false;
#endif
+ ConfigInputTrickleEventQueue = true;
ConfigInputTextCursorBlink = true;
ConfigWindowsResizeFromEdges = true;
ConfigWindowsMoveFromTitleBarOnly = false;
@@ -1161,23 +1191,35 @@ ImGuiIO::ImGuiIO()
GetClipboardTextFn = GetClipboardTextFn_DefaultImpl; // Platform dependent default implementations
SetClipboardTextFn = SetClipboardTextFn_DefaultImpl;
ClipboardUserData = NULL;
+ SetPlatformImeDataFn = SetPlatformImeDataFn_DefaultImpl;
// Input (NB: we already have memset zero the entire structure!)
MousePos = ImVec2(-FLT_MAX, -FLT_MAX);
MousePosPrev = ImVec2(-FLT_MAX, -FLT_MAX);
MouseDragThreshold = 6.0f;
for (int i = 0; i < IM_ARRAYSIZE(MouseDownDuration); i++) MouseDownDuration[i] = MouseDownDurationPrev[i] = -1.0f;
- for (int i = 0; i < IM_ARRAYSIZE(KeysDownDuration); i++) KeysDownDuration[i] = KeysDownDurationPrev[i] = -1.0f;
+ for (int i = 0; i < IM_ARRAYSIZE(KeysData); i++) { KeysData[i].DownDuration = KeysData[i].DownDurationPrev = -1.0f; }
for (int i = 0; i < IM_ARRAYSIZE(NavInputsDownDuration); i++) NavInputsDownDuration[i] = -1.0f;
+ BackendUsingLegacyKeyArrays = (ImS8)-1;
+ BackendUsingLegacyNavInputArray = true; // assume using legacy array until proven wrong
}
// Pass in translated ASCII characters for text input.
// - with glfw you can get those from the callback set in glfwSetCharCallback()
// - on Windows you can get those using ToAscii+keyboard state, or via the WM_CHAR message
+// FIXME: Should in theory be called "AddCharacterEvent()" to be consistent with new API
void ImGuiIO::AddInputCharacter(unsigned int c)
{
- if (c != 0)
- InputQueueCharacters.push_back(c <= IM_UNICODE_CODEPOINT_MAX ? (ImWchar)c : IM_UNICODE_CODEPOINT_INVALID);
+ ImGuiContext& g = *GImGui;
+ IM_ASSERT(&g.IO == this && "Can only add events to current context.");
+ if (c == 0)
+ return;
+
+ ImGuiInputEvent e;
+ e.Type = ImGuiInputEventType_Char;
+ e.Source = ImGuiInputSource_Keyboard;
+ e.Text.Char = c;
+ g.InputEventsQueue.push_back(e);
}
// UTF16 strings use surrogate pairs to encode codepoints >= 0x10000, so
@@ -1190,7 +1232,7 @@ void ImGuiIO::AddInputCharacterUTF16(ImWchar16 c)
if ((c & 0xFC00) == 0xD800) // High surrogate, must save
{
if (InputQueueSurrogate != 0)
- InputQueueCharacters.push_back(IM_UNICODE_CODEPOINT_INVALID);
+ AddInputCharacter(IM_UNICODE_CODEPOINT_INVALID);
InputQueueSurrogate = c;
return;
}
@@ -1200,7 +1242,7 @@ void ImGuiIO::AddInputCharacterUTF16(ImWchar16 c)
{
if ((c & 0xFC00) != 0xDC00) // Invalid low surrogate
{
- InputQueueCharacters.push_back(IM_UNICODE_CODEPOINT_INVALID);
+ AddInputCharacter(IM_UNICODE_CODEPOINT_INVALID);
}
else
{
@@ -1213,7 +1255,7 @@ void ImGuiIO::AddInputCharacterUTF16(ImWchar16 c)
InputQueueSurrogate = 0;
}
- InputQueueCharacters.push_back(cp);
+ AddInputCharacter((unsigned)cp);
}
void ImGuiIO::AddInputCharactersUTF8(const char* utf8_chars)
@@ -1223,7 +1265,7 @@ void ImGuiIO::AddInputCharactersUTF8(const char* utf8_chars)
unsigned int c = 0;
utf8_chars += ImTextCharFromUtf8(&c, utf8_chars, NULL);
if (c != 0)
- InputQueueCharacters.push_back((ImWchar)c);
+ AddInputCharacter(c);
}
}
@@ -1234,20 +1276,161 @@ void ImGuiIO::ClearInputCharacters()
void ImGuiIO::ClearInputKeys()
{
+#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO
memset(KeysDown, 0, sizeof(KeysDown));
- for (int n = 0; n < IM_ARRAYSIZE(KeysDownDuration); n++)
- KeysDownDuration[n] = KeysDownDurationPrev[n] = -1.0f;
+#endif
+ for (int n = 0; n < IM_ARRAYSIZE(KeysData); n++)
+ {
+ KeysData[n].Down = false;
+ KeysData[n].DownDuration = -1.0f;
+ KeysData[n].DownDurationPrev = -1.0f;
+ }
KeyCtrl = KeyShift = KeyAlt = KeySuper = false;
KeyMods = KeyModsPrev = ImGuiKeyModFlags_None;
for (int n = 0; n < IM_ARRAYSIZE(NavInputsDownDuration); n++)
NavInputsDownDuration[n] = NavInputsDownDurationPrev[n] = -1.0f;
}
+// Queue a new key down/up event.
+// - ImGuiKey key: Translated key (as in, generally ImGuiKey_A matches the key end-user would use to emit an 'A' character)
+// - bool down: Is the key down? use false to signify a key release.
+// - float analog_value: 0.0f..1.0f
+void ImGuiIO::AddKeyAnalogEvent(ImGuiKey key, bool down, float analog_value)
+{
+ //if (e->Down) { IMGUI_DEBUG_LOG("AddKeyEvent() Key='%s' %d, NativeKeycode = %d, NativeScancode = %d\n", ImGui::GetKeyName(e->Key), e->Down, e->NativeKeycode, e->NativeScancode); }
+ if (key == ImGuiKey_None)
+ return;
+ ImGuiContext& g = *GImGui;
+ IM_ASSERT(&g.IO == this && "Can only add events to current context.");
+ IM_ASSERT(ImGui::IsNamedKey(key)); // Backend needs to pass a valid ImGuiKey_ constant. 0..511 values are legacy native key codes which are not accepted by this API.
+
+ // Verify that backend isn't mixing up using new io.AddKeyEvent() api and old io.KeysDown[] + io.KeyMap[] data.
+#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO
+ IM_ASSERT((BackendUsingLegacyKeyArrays == -1 || BackendUsingLegacyKeyArrays == 0) && "Backend needs to either only use io.AddKeyEvent(), either only fill legacy io.KeysDown[] + io.KeyMap[]. Not both!");
+ if (BackendUsingLegacyKeyArrays == -1)
+ for (int n = ImGuiKey_NamedKey_BEGIN; n < ImGuiKey_NamedKey_END; n++)
+ IM_ASSERT(KeyMap[n] == -1 && "Backend needs to either only use io.AddKeyEvent(), either only fill legacy io.KeysDown[] + io.KeyMap[]. Not both!");
+ BackendUsingLegacyKeyArrays = 0;
+#endif
+ if (ImGui::IsGamepadKey(key))
+ BackendUsingLegacyNavInputArray = false;
+
+ // Partial filter of duplicates (not strictly needed, but makes data neater in particular for key mods and gamepad values which are most commonly spmamed)
+ ImGuiKeyData* key_data = ImGui::GetKeyData(key);
+ if (key_data->Down == down && key_data->AnalogValue == analog_value)
+ {
+ bool found = false;
+ for (int n = g.InputEventsQueue.Size - 1; n >= 0 && !found; n--)
+ if (g.InputEventsQueue[n].Type == ImGuiInputEventType_Key && g.InputEventsQueue[n].Key.Key == key)
+ found = true;
+ if (!found)
+ return;
+ }
+
+ // Add event
+ ImGuiInputEvent e;
+ e.Type = ImGuiInputEventType_Key;
+ e.Source = ImGui::IsGamepadKey(key) ? ImGuiInputSource_Gamepad : ImGuiInputSource_Keyboard;
+ e.Key.Key = key;
+ e.Key.Down = down;
+ e.Key.AnalogValue = analog_value;
+ g.InputEventsQueue.push_back(e);
+}
+
+void ImGuiIO::AddKeyEvent(ImGuiKey key, bool down)
+{
+ AddKeyAnalogEvent(key, down, down ? 1.0f : 0.0f);
+}
+
+// [Optional] Call after AddKeyEvent().
+// Specify native keycode, scancode + Specify index for legacy <1.87 IsKeyXXX() functions with native indices.
+// If you are writing a backend in 2022 or don't use IsKeyXXX() with native values that are not ImGuiKey values, you can avoid calling this.
+void ImGuiIO::SetKeyEventNativeData(ImGuiKey key, int native_keycode, int native_scancode, int native_legacy_index)
+{
+ if (key == ImGuiKey_None)
+ return;
+ IM_ASSERT(ImGui::IsNamedKey(key)); // >= 512
+ IM_ASSERT(native_legacy_index == -1 || ImGui::IsLegacyKey(native_legacy_index)); // >= 0 && <= 511
+ IM_UNUSED(native_keycode); // Yet unused
+ IM_UNUSED(native_scancode); // Yet unused
+
+ // Build native->imgui map so old user code can still call key functions with native 0..511 values.
+#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO
+ const int legacy_key = (native_legacy_index != -1) ? native_legacy_index : native_keycode;
+ if (ImGui::IsLegacyKey(legacy_key))
+ KeyMap[legacy_key] = key;
+#else
+ IM_UNUSED(key);
+ IM_UNUSED(native_legacy_index);
+#endif
+}
+
+// Queue a mouse move event
+void ImGuiIO::AddMousePosEvent(float x, float y)
+{
+ ImGuiContext& g = *GImGui;
+ IM_ASSERT(&g.IO == this && "Can only add events to current context.");
+
+ ImGuiInputEvent e;
+ e.Type = ImGuiInputEventType_MousePos;
+ e.Source = ImGuiInputSource_Mouse;
+ e.MousePos.PosX = x;
+ e.MousePos.PosY = y;
+ g.InputEventsQueue.push_back(e);
+}
+
+void ImGuiIO::AddMouseButtonEvent(int mouse_button, bool down)
+{
+ ImGuiContext& g = *GImGui;
+ IM_ASSERT(&g.IO == this && "Can only add events to current context.");
+ IM_ASSERT(mouse_button >= 0 && mouse_button < ImGuiMouseButton_COUNT);
+
+ ImGuiInputEvent e;
+ e.Type = ImGuiInputEventType_MouseButton;
+ e.Source = ImGuiInputSource_Mouse;
+ e.MouseButton.Button = mouse_button;
+ e.MouseButton.Down = down;
+ g.InputEventsQueue.push_back(e);
+}
+
+// Queue a mouse wheel event (most mouse/API will only have a Y component)
+void ImGuiIO::AddMouseWheelEvent(float wheel_x, float wheel_y)
+{
+ ImGuiContext& g = *GImGui;
+ IM_ASSERT(&g.IO == this && "Can only add events to current context.");
+ if (wheel_x == 0.0f && wheel_y == 0.0f)
+ return;
+
+ ImGuiInputEvent e;
+ e.Type = ImGuiInputEventType_MouseWheel;
+ e.Source = ImGuiInputSource_Mouse;
+ e.MouseWheel.WheelX = wheel_x;
+ e.MouseWheel.WheelY = wheel_y;
+ g.InputEventsQueue.push_back(e);
+}
+
+void ImGuiIO::AddMouseViewportEvent(ImGuiID viewport_id)
+{
+ ImGuiContext& g = *GImGui;
+ IM_ASSERT(&g.IO == this && "Can only add events to current context.");
+ IM_ASSERT(g.IO.BackendFlags & ImGuiBackendFlags_HasMouseHoveredViewport);
+
+ ImGuiInputEvent e;
+ e.Type = ImGuiInputEventType_MouseViewport;
+ e.Source = ImGuiInputSource_Mouse;
+ e.MouseViewport.HoveredViewportID = viewport_id;
+ g.InputEventsQueue.push_back(e);
+}
+
void ImGuiIO::AddFocusEvent(bool focused)
{
- // We intentionally overwrite this and process in NewFrame(), in order to give a chance
- // to multi-viewports backends to queue AddFocusEvent(false),AddFocusEvent(true) in same frame.
- AppFocusLost = !focused;
+ ImGuiContext& g = *GImGui;
+ IM_ASSERT(&g.IO == this && "Can only add events to current context.");
+
+ ImGuiInputEvent e;
+ e.Type = ImGuiInputEventType_Focus;
+ e.AppFocused.Focused = focused;
+ g.InputEventsQueue.push_back(e);
}
//-----------------------------------------------------------------------------
@@ -2860,7 +3043,7 @@ void ImGui::RenderText(ImVec2 pos, const char* text, const char* text_end, bool
if (text != text_display_end)
{
- window->DrawList->AddText(g.Font, g.FontSize, g.FontLineHeight, g.FontBaselineOffset, pos, GetColorU32(ImGuiCol_Text), text, text_display_end);
+ window->DrawList->AddText(g.Font, g.FontSize, pos, GetColorU32(ImGuiCol_Text), text, text_display_end);
if (g.LogEnabled)
LogRenderedText(&pos, text, text_display_end);
}
@@ -2876,7 +3059,7 @@ void ImGui::RenderTextWrapped(ImVec2 pos, const char* text, const char* text_end
if (text != text_end)
{
- window->DrawList->AddText(g.Font, g.FontSize, g.FontLineHeight, g.FontBaselineOffset, pos, GetColorU32(ImGuiCol_Text), text, text_end, wrap_width);
+ window->DrawList->AddText(g.Font, g.FontSize, pos, GetColorU32(ImGuiCol_Text), text, text_end, wrap_width);
if (g.LogEnabled)
LogRenderedText(&pos, text, text_end);
}
@@ -2951,7 +3134,6 @@ void ImGui::RenderTextEllipsis(ImDrawList* draw_list, const ImVec2& pos_min, con
const ImFont* font = draw_list->_Data->Font;
const float font_size = draw_list->_Data->FontSize;
- const float font_line_height = draw_list->_Data->FontLineHeight;
const char* text_end_ellipsis = NULL;
ImWchar ellipsis_char = font->EllipsisChar;
@@ -2976,18 +3158,18 @@ void ImGui::RenderTextEllipsis(ImDrawList* draw_list, const ImVec2& pos_min, con
// We can now claim the space between pos_max.x and ellipsis_max.x
const float text_avail_width = ImMax((ImMax(pos_max.x, ellipsis_max_x) - ellipsis_total_width) - pos_min.x, 1.0f);
- float text_size_clipped_x = font->CalcTextSizeA(font_size, font_line_height, text_avail_width, 0.0f, text, text_end_full, &text_end_ellipsis).x;
+ float text_size_clipped_x = font->CalcTextSizeA(font_size, text_avail_width, 0.0f, text, text_end_full, &text_end_ellipsis).x;
if (text == text_end_ellipsis && text_end_ellipsis < text_end_full)
{
// Always display at least 1 character if there's no room for character + ellipsis
text_end_ellipsis = text + ImTextCountUtf8BytesFromChar(text, text_end_full);
- text_size_clipped_x = font->CalcTextSizeA(font_size, font_line_height, FLT_MAX, 0.0f, text, text_end_ellipsis).x;
+ text_size_clipped_x = font->CalcTextSizeA(font_size, FLT_MAX, 0.0f, text, text_end_ellipsis).x;
}
while (text_end_ellipsis > text && ImCharIsBlankA(text_end_ellipsis[-1]))
{
// Trim trailing space before ellipsis (FIXME: Supporting non-ascii blanks would be nice, for this we need a function to backtrack in UTF-8 text)
text_end_ellipsis--;
- text_size_clipped_x -= font->CalcTextSizeA(font_size, font_line_height, FLT_MAX, 0.0f, text_end_ellipsis, text_end_ellipsis + 1).x; // Ascii blanks are always 1 byte
+ text_size_clipped_x -= font->CalcTextSizeA(font_size, FLT_MAX, 0.0f, text_end_ellipsis, text_end_ellipsis + 1).x; // Ascii blanks are always 1 byte
}
// Render text, render ellipsis
@@ -2996,7 +3178,7 @@ void ImGui::RenderTextEllipsis(ImDrawList* draw_list, const ImVec2& pos_min, con
if (ellipsis_x + ellipsis_total_width <= ellipsis_max_x)
for (int i = 0; i < ellipsis_char_count; i++)
{
- font->RenderChar(draw_list, font_size, font_line_height, ImVec2(ellipsis_x, pos_min.y), GetColorU32(ImGuiCol_Text), ellipsis_char);
+ font->RenderChar(draw_list, font_size, ImVec2(ellipsis_x, pos_min.y), GetColorU32(ImGuiCol_Text), ellipsis_char);
ellipsis_x += ellipsis_glyph_width;
}
}
@@ -3082,6 +3264,7 @@ ImGuiWindow::ImGuiWindow(ImGuiContext* context, const char* name) : DrawListInst
ViewportAllowPlatformMonitorExtend = -1;
ViewportPos = ImVec2(FLT_MAX, FLT_MAX);
MoveId = GetID("#MOVE");
+ TabId = GetID("#TAB");
ScrollTarget = ImVec2(FLT_MAX, FLT_MAX);
ScrollTargetCenterRatio = ImVec2(0.5f, 0.5f);
AutoFitFramesX = AutoFitFramesY = -1;
@@ -3186,7 +3369,7 @@ static void SetCurrentWindow(ImGuiWindow* window)
g.CurrentWindow = window;
g.CurrentTable = window && window->DC.CurrentTableIdx != -1 ? g.Tables.GetByIndex(window->DC.CurrentTableIdx) : NULL;
if (window)
- ImGui::SetCurrentFont(g.Font);
+ g.FontSize = g.DrawListSharedData.FontSize = window->CalcFontSize();
}
void ImGui::GcCompactTransientMiscBuffers()
@@ -3247,7 +3430,7 @@ void ImGui::SetActiveID(ImGuiID id, ImGuiWindow* window)
if (id)
{
g.ActiveIdIsAlive = id;
- g.ActiveIdSource = (g.NavActivateId == id || g.NavActivateInputId == id || g.NavJustMovedToId == id) ? ImGuiInputSource_Nav : ImGuiInputSource_Mouse;
+ g.ActiveIdSource = (g.NavActivateId == id || g.NavActivateInputId == id || g.NavJustMovedToId == id) ? (ImGuiInputSource)ImGuiInputSource_Nav : ImGuiInputSource_Mouse;
}
// Clear declaration of inputs claimed by the widget
@@ -3255,7 +3438,7 @@ void ImGui::SetActiveID(ImGuiID id, ImGuiWindow* window)
g.ActiveIdUsingMouseWheel = false;
g.ActiveIdUsingNavDirMask = 0x00;
g.ActiveIdUsingNavInputMask = 0x00;
- g.ActiveIdUsingKeyInputMask = 0x00;
+ g.ActiveIdUsingKeyInputMask.ClearAllBits();
}
void ImGui::ClearActiveID()
@@ -3359,8 +3542,9 @@ bool ImGui::IsItemHovered(ImGuiHoveredFlags flags)
// Test if another item is active (e.g. being dragged)
if ((flags & ImGuiHoveredFlags_AllowWhenBlockedByActiveItem) == 0)
- if (g.ActiveId != 0 && g.ActiveId != g.LastItemData.ID && !g.ActiveIdAllowOverlap && g.ActiveId != window->MoveId)
- return false;
+ if (g.ActiveId != 0 && g.ActiveId != g.LastItemData.ID && !g.ActiveIdAllowOverlap)
+ if (g.ActiveId != window->MoveId && g.ActiveId != window->TabId)
+ return false;
// Test if interactions on this window are blocked by an active popup or modal.
// The ImGuiHoveredFlags_AllowWhenBlockedByPopup flag will be tested here.
@@ -3372,8 +3556,9 @@ bool ImGui::IsItemHovered(ImGuiHoveredFlags flags)
return false;
// Special handling for calling after Begin() which represent the title bar or tab.
- // When the window is collapsed (SkipItems==true) that last item will never be overwritten so we need to detect the case.
- if ((g.LastItemData.ID == window->ID || g.LastItemData.ID == window->MoveId) && window->WriteAccessed)
+ // When the window is skipped/collapsed (SkipItems==true) that last item (always ->MoveId submitted by Begin)
+ // will never be overwritten so we need to detect the case.
+ if (g.LastItemData.ID == window->MoveId && window->WriteAccessed)
return false;
}
@@ -3871,65 +4056,132 @@ static bool IsWindowActiveAndVisible(ImGuiWindow* window)
return (window->Active) && (!window->Hidden);
}
+static void ImGui::UpdateKeyboardInputs()
+{
+ ImGuiContext& g = *GImGui;
+ ImGuiIO& io = g.IO;
+
+ // Synchronize io.KeyMods with individual modifiers io.KeyXXX bools
+ io.KeyMods = GetMergedKeyModFlags();
+
+ // Import legacy keys or verify they are not used
+#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO
+ if (io.BackendUsingLegacyKeyArrays == 0)
+ {
+ // Backend used new io.AddKeyEvent() API: Good! Verify that old arrays are never written too.
+ for (int n = 0; n < IM_ARRAYSIZE(io.KeysDown); n++)
+ IM_ASSERT(io.KeysDown[n] == false && "Backend needs to either only use io.AddKeyEvent(), either only fill legacy io.KeysDown[] + io.KeyMap[]. Not both!");
+ }
+ else
+ {
+ if (g.FrameCount == 0)
+ for (int n = ImGuiKey_LegacyNativeKey_BEGIN; n < ImGuiKey_LegacyNativeKey_END; n++)
+ IM_ASSERT(g.IO.KeyMap[n] == -1 && "Backend is not allowed to write to io.KeyMap[0..511]!");
+
+ // Build reverse KeyMap (Named -> Legacy)
+ for (int n = ImGuiKey_NamedKey_BEGIN; n < ImGuiKey_NamedKey_END; n++)
+ if (io.KeyMap[n] != -1)
+ {
+ IM_ASSERT(IsLegacyKey((ImGuiKey)io.KeyMap[n]));
+ io.KeyMap[io.KeyMap[n]] = n;
+ }
+
+ // Import legacy keys into new ones
+ for (int n = ImGuiKey_LegacyNativeKey_BEGIN; n < ImGuiKey_LegacyNativeKey_END; n++)
+ if (io.KeysDown[n] || io.BackendUsingLegacyKeyArrays == 1)
+ {
+ const ImGuiKey key = (ImGuiKey)(io.KeyMap[n] != -1 ? io.KeyMap[n] : n);
+ IM_ASSERT(io.KeyMap[n] == -1 || IsNamedKey(key));
+ io.KeysData[key].Down = io.KeysDown[n];
+ io.BackendUsingLegacyKeyArrays = 1;
+ }
+ if (io.BackendUsingLegacyKeyArrays == 1)
+ {
+ io.KeysData[ImGuiKey_ModCtrl].Down = io.KeyCtrl;
+ io.KeysData[ImGuiKey_ModShift].Down = io.KeyShift;
+ io.KeysData[ImGuiKey_ModAlt].Down = io.KeyAlt;
+ io.KeysData[ImGuiKey_ModSuper].Down = io.KeySuper;
+ }
+ }
+#endif
+
+ // Clear gamepad data if disabled
+ if ((io.BackendFlags & ImGuiBackendFlags_HasGamepad) == 0)
+ for (int i = ImGuiKey_Gamepad_BEGIN; i < ImGuiKey_Gamepad_END; i++)
+ {
+ io.KeysData[i - ImGuiKey_KeysData_OFFSET].Down = false;
+ io.KeysData[i - ImGuiKey_KeysData_OFFSET].AnalogValue = 0.0f;
+ }
+
+ // Update keys
+ for (int i = 0; i < IM_ARRAYSIZE(io.KeysData); i++)
+ {
+ ImGuiKeyData& key_data = io.KeysData[i];
+ key_data.DownDurationPrev = key_data.DownDuration;
+ key_data.DownDuration = key_data.Down ? (key_data.DownDuration < 0.0f ? 0.0f : key_data.DownDuration + io.DeltaTime) : -1.0f;
+ }
+}
+
static void ImGui::UpdateMouseInputs()
{
ImGuiContext& g = *GImGui;
+ ImGuiIO& io = g.IO;
// Round mouse position to avoid spreading non-rounded position (e.g. UpdateManualResize doesn't support them well)
- if (IsMousePosValid(&g.IO.MousePos))
- g.IO.MousePos = g.MouseLastValidPos = ImFloor(g.IO.MousePos);
+ if (IsMousePosValid(&io.MousePos))
+ io.MousePos = g.MouseLastValidPos = ImFloorSigned(io.MousePos);
// If mouse just appeared or disappeared (usually denoted by -FLT_MAX components) we cancel out movement in MouseDelta
- if (IsMousePosValid(&g.IO.MousePos) && IsMousePosValid(&g.IO.MousePosPrev))
- g.IO.MouseDelta = g.IO.MousePos - g.IO.MousePosPrev;
+ if (IsMousePosValid(&io.MousePos) && IsMousePosValid(&io.MousePosPrev))
+ io.MouseDelta = io.MousePos - io.MousePosPrev;
else
- g.IO.MouseDelta = ImVec2(0.0f, 0.0f);
+ io.MouseDelta = ImVec2(0.0f, 0.0f);
// If mouse moved we re-enable mouse hovering in case it was disabled by gamepad/keyboard. In theory should use a >0.0f threshold but would need to reset in everywhere we set this to true.
- if (g.IO.MouseDelta.x != 0.0f || g.IO.MouseDelta.y != 0.0f)
+ if (io.MouseDelta.x != 0.0f || io.MouseDelta.y != 0.0f)
g.NavDisableMouseHover = false;
- g.IO.MousePosPrev = g.IO.MousePos;
- for (int i = 0; i < IM_ARRAYSIZE(g.IO.MouseDown); i++)
+ io.MousePosPrev = io.MousePos;
+ for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++)
{
- g.IO.MouseClicked[i] = g.IO.MouseDown[i] && g.IO.MouseDownDuration[i] < 0.0f;
- g.IO.MouseClickedCount[i] = 0; // Will be filled below
- g.IO.MouseReleased[i] = !g.IO.MouseDown[i] && g.IO.MouseDownDuration[i] >= 0.0f;
- g.IO.MouseDownDurationPrev[i] = g.IO.MouseDownDuration[i];
- g.IO.MouseDownDuration[i] = g.IO.MouseDown[i] ? (g.IO.MouseDownDuration[i] < 0.0f ? 0.0f : g.IO.MouseDownDuration[i] + g.IO.DeltaTime) : -1.0f;
- if (g.IO.MouseClicked[i])
+ io.MouseClicked[i] = io.MouseDown[i] && io.MouseDownDuration[i] < 0.0f;
+ io.MouseClickedCount[i] = 0; // Will be filled below
+ io.MouseReleased[i] = !io.MouseDown[i] && io.MouseDownDuration[i] >= 0.0f;
+ io.MouseDownDurationPrev[i] = io.MouseDownDuration[i];
+ io.MouseDownDuration[i] = io.MouseDown[i] ? (io.MouseDownDuration[i] < 0.0f ? 0.0f : io.MouseDownDuration[i] + io.DeltaTime) : -1.0f;
+ if (io.MouseClicked[i])
{
bool is_repeated_click = false;
- if ((float)(g.Time - g.IO.MouseClickedTime[i]) < g.IO.MouseDoubleClickTime)
+ if ((float)(g.Time - io.MouseClickedTime[i]) < io.MouseDoubleClickTime)
{
- ImVec2 delta_from_click_pos = IsMousePosValid(&g.IO.MousePos) ? (g.IO.MousePos - g.IO.MouseClickedPos[i]) : ImVec2(0.0f, 0.0f);
- if (ImLengthSqr(delta_from_click_pos) < g.IO.MouseDoubleClickMaxDist * g.IO.MouseDoubleClickMaxDist)
+ ImVec2 delta_from_click_pos = IsMousePosValid(&io.MousePos) ? (io.MousePos - io.MouseClickedPos[i]) : ImVec2(0.0f, 0.0f);
+ if (ImLengthSqr(delta_from_click_pos) < io.MouseDoubleClickMaxDist * io.MouseDoubleClickMaxDist)
is_repeated_click = true;
}
if (is_repeated_click)
- g.IO.MouseClickedLastCount[i]++;
+ io.MouseClickedLastCount[i]++;
else
- g.IO.MouseClickedLastCount[i] = 1;
- g.IO.MouseClickedTime[i] = g.Time;
- g.IO.MouseClickedPos[i] = g.IO.MousePos;
- g.IO.MouseClickedCount[i] = g.IO.MouseClickedLastCount[i];
- g.IO.MouseDragMaxDistanceAbs[i] = ImVec2(0.0f, 0.0f);
- g.IO.MouseDragMaxDistanceSqr[i] = 0.0f;
+ io.MouseClickedLastCount[i] = 1;
+ io.MouseClickedTime[i] = g.Time;
+ io.MouseClickedPos[i] = io.MousePos;
+ io.MouseClickedCount[i] = io.MouseClickedLastCount[i];
+ io.MouseDragMaxDistanceAbs[i] = ImVec2(0.0f, 0.0f);
+ io.MouseDragMaxDistanceSqr[i] = 0.0f;
}
- else if (g.IO.MouseDown[i])
+ else if (io.MouseDown[i])
{
// Maintain the maximum distance we reaching from the initial click position, which is used with dragging threshold
- ImVec2 delta_from_click_pos = IsMousePosValid(&g.IO.MousePos) ? (g.IO.MousePos - g.IO.MouseClickedPos[i]) : ImVec2(0.0f, 0.0f);
- g.IO.MouseDragMaxDistanceSqr[i] = ImMax(g.IO.MouseDragMaxDistanceSqr[i], ImLengthSqr(delta_from_click_pos));
- g.IO.MouseDragMaxDistanceAbs[i].x = ImMax(g.IO.MouseDragMaxDistanceAbs[i].x, delta_from_click_pos.x < 0.0f ? -delta_from_click_pos.x : delta_from_click_pos.x);
- g.IO.MouseDragMaxDistanceAbs[i].y = ImMax(g.IO.MouseDragMaxDistanceAbs[i].y, delta_from_click_pos.y < 0.0f ? -delta_from_click_pos.y : delta_from_click_pos.y);
+ ImVec2 delta_from_click_pos = IsMousePosValid(&io.MousePos) ? (io.MousePos - io.MouseClickedPos[i]) : ImVec2(0.0f, 0.0f);
+ io.MouseDragMaxDistanceSqr[i] = ImMax(io.MouseDragMaxDistanceSqr[i], ImLengthSqr(delta_from_click_pos));
+ io.MouseDragMaxDistanceAbs[i].x = ImMax(io.MouseDragMaxDistanceAbs[i].x, delta_from_click_pos.x < 0.0f ? -delta_from_click_pos.x : delta_from_click_pos.x);
+ io.MouseDragMaxDistanceAbs[i].y = ImMax(io.MouseDragMaxDistanceAbs[i].y, delta_from_click_pos.y < 0.0f ? -delta_from_click_pos.y : delta_from_click_pos.y);
}
// We provide io.MouseDoubleClicked[] as a legacy service
- g.IO.MouseDoubleClicked[i] = (g.IO.MouseClickedCount[i] == 2);
+ io.MouseDoubleClicked[i] = (io.MouseClickedCount[i] == 2);
// Clicking any mouse button reactivate mouse hovering which may have been deactivated by gamepad/keyboard navigation
- if (g.IO.MouseClicked[i])
+ if (io.MouseClicked[i])
g.NavDisableMouseHover = false;
}
}
@@ -4009,7 +4261,7 @@ void ImGui::UpdateMouseWheel()
if (!(window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(window->Flags & ImGuiWindowFlags_NoMouseInputs))
{
float max_step = window->InnerRect.GetHeight() * 0.67f;
- float scroll_step = ImFloor(ImMin(5 * window->CalcFontHeight(), max_step));
+ float scroll_step = ImFloor(ImMin(5 * window->CalcFontSize(), max_step));
SetScrollY(window, window->Scroll.y - wheel_y * scroll_step);
}
}
@@ -4023,7 +4275,7 @@ void ImGui::UpdateMouseWheel()
if (!(window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(window->Flags & ImGuiWindowFlags_NoMouseInputs))
{
float max_step = window->InnerRect.GetWidth() * 0.67f;
- float scroll_step = ImFloor(ImMin(2 * window->CalcFontWidth(), max_step));
+ float scroll_step = ImFloor(ImMin(2 * window->CalcFontSize(), max_step));
SetScrollX(window, window->Scroll.x - wheel_x * scroll_step);
}
}
@@ -4223,7 +4475,7 @@ void ImGui::NewFrame()
{
g.ActiveIdUsingNavDirMask = 0x00;
g.ActiveIdUsingNavInputMask = 0x00;
- g.ActiveIdUsingKeyInputMask = 0x00;
+ g.ActiveIdUsingKeyInputMask.ClearAllBits();
}
// Drag and drop
@@ -4238,20 +4490,17 @@ void ImGui::NewFrame()
//if (g.IO.AppFocusLost)
// ClosePopupsExceptModals();
- // Clear buttons state when focus is lost
- // (this is useful so e.g. releasing Alt after focus loss on Alt-Tab doesn't trigger the Alt menu toggle)
- if (g.IO.AppFocusLost)
- {
- g.IO.ClearInputKeys();
- g.IO.AppFocusLost = false;
- }
+ // Process input queue (trickle as many events as possible)
+ g.InputEventsTrail.resize(0);
+ UpdateInputEvents(g.IO.ConfigInputTrickleEventQueue);
// Update keyboard input state
- // Synchronize io.KeyMods with individual modifiers io.KeyXXX bools
- g.IO.KeyMods = GetMergedKeyModFlags();
- memcpy(g.IO.KeysDownDurationPrev, g.IO.KeysDownDuration, sizeof(g.IO.KeysDownDuration));
- for (int i = 0; i < IM_ARRAYSIZE(g.IO.KeysDown); i++)
- g.IO.KeysDownDuration[i] = g.IO.KeysDown[i] ? (g.IO.KeysDownDuration[i] < 0.0f ? 0.0f : g.IO.KeysDownDuration[i] + g.IO.DeltaTime) : -1.0f;
+ UpdateKeyboardInputs();
+
+ //IM_ASSERT(g.IO.KeyCtrl == IsKeyDown(ImGuiKey_LeftCtrl) || IsKeyDown(ImGuiKey_RightCtrl));
+ //IM_ASSERT(g.IO.KeyShift == IsKeyDown(ImGuiKey_LeftShift) || IsKeyDown(ImGuiKey_RightShift));
+ //IM_ASSERT(g.IO.KeyAlt == IsKeyDown(ImGuiKey_LeftAlt) || IsKeyDown(ImGuiKey_RightAlt));
+ //IM_ASSERT(g.IO.KeySuper == IsKeyDown(ImGuiKey_LeftSuper) || IsKeyDown(ImGuiKey_RightSuper));
// Update gamepad/keyboard navigation
NavUpdate();
@@ -4278,8 +4527,10 @@ void ImGui::NewFrame()
g.MouseCursor = ImGuiMouseCursor_Arrow;
g.WantCaptureMouseNextFrame = g.WantCaptureKeyboardNextFrame = g.WantTextInputNextFrame = -1;
- g.PlatformImePos = ImVec2(1.0f, 1.0f); // OS Input Method Editor showing on top-left of our window by default
- g.PlatformImePosViewport = NULL;
+
+ // Platform IME data: reset for the frame
+ g.PlatformImeDataPrev = g.PlatformImeData;
+ g.PlatformImeData.WantVisible = false;
// Mouse wheel scrolling, scale
UpdateMouseWheel();
@@ -4495,11 +4746,10 @@ static void AddWindowToSortBuffer(ImVector<ImGuiWindow*>* out_sorted_windows, Im
static void AddDrawListToDrawData(ImVector<ImDrawList*>* out_list, ImDrawList* draw_list)
{
- // Remove trailing command if unused.
- // Technically we could return directly instead of popping, but this make things looks neat in Metrics/Debugger window as well.
- draw_list->_PopUnusedDrawCmd();
if (draw_list->CmdBuffer.Size == 0)
return;
+ if (draw_list->CmdBuffer.Size == 1 && draw_list->CmdBuffer[0].ElemCount == 0 && draw_list->CmdBuffer[0].UserCallback == NULL)
+ return;
// Draw list sanity check. Detect mismatch between PrimReserve() calls and incrementing _VtxCurrentIdx, _VtxWritePtr etc.
// May trigger for you if you are using PrimXXX functions incorrectly.
@@ -4596,8 +4846,10 @@ static void SetupViewportDrawData(ImGuiViewportP* viewport, ImVector<ImDrawList*
draw_data->OwnerViewport = viewport;
for (int n = 0; n < draw_lists->Size; n++)
{
- draw_data->TotalVtxCount += draw_lists->Data[n]->VtxBuffer.Size;
- draw_data->TotalIdxCount += draw_lists->Data[n]->IdxBuffer.Size;
+ ImDrawList* draw_list = draw_lists->Data[n];
+ draw_list->_PopUnusedDrawCmd();
+ draw_data->TotalVtxCount += draw_list->VtxBuffer.Size;
+ draw_data->TotalIdxCount += draw_list->IdxBuffer.Size;
}
}
@@ -4641,6 +4893,7 @@ static void ImGui::RenderDimmedBackgroundBehindWindow(ImGuiWindow* window, ImU32
{
// We've already called AddWindowToDrawData() which called DrawList->ChannelsMerge() on DockNodeHost windows,
// and draw list have been trimmed already, hence the explicit recreation of a draw command if missing.
+ // FIXME: This is creating complication, might be simpler if we could inject a drawlist in drawdata at a given position and not attempt to manipulate ImDrawCmd order.
ImDrawList* draw_list = window->RootWindowDockTree->DrawList;
if (draw_list->CmdBuffer.Size == 0)
draw_list->AddDrawCmd();
@@ -4651,12 +4904,15 @@ static void ImGui::RenderDimmedBackgroundBehindWindow(ImGuiWindow* window, ImU32
draw_list->CmdBuffer.pop_back();
draw_list->CmdBuffer.push_front(cmd);
draw_list->PopClipRect();
+ draw_list->AddDrawCmd(); // We need to create a command as CmdBuffer.back().IdxOffset won't be correct if we append to same command.
}
// Draw over sibling docking nodes in a same docking tree
if (window->RootWindow->DockIsActive)
{
ImDrawList* draw_list = FindFrontMostVisibleChildWindow(window->RootWindowDockTree)->DrawList;
+ if (draw_list->CmdBuffer.Size == 0)
+ draw_list->AddDrawCmd();
draw_list->PushClipRect(viewport_rect.Min, viewport_rect.Max, false);
RenderRectFilledWithHole(draw_list, window->RootWindowDockTree->Rect(), window->RootWindow->Rect(), col, 0.0f);// window->RootWindowDockTree->WindowRounding);
draw_list->PopClipRect();
@@ -4684,6 +4940,8 @@ static void ImGui::RenderDimmedBackgrounds()
{
ImGuiContext& g = *GImGui;
ImGuiWindow* modal_window = GetTopMostAndVisiblePopupModal();
+ if (g.DimBgRatio <= 0.0f && g.NavWindowingHighlightAlpha <= 0.0f)
+ return;
const bool dim_bg_for_modal = (modal_window != NULL);
const bool dim_bg_for_window_list = (g.NavWindowingTargetAnim != NULL && g.NavWindowingTargetAnim->Active);
if (!dim_bg_for_modal && !dim_bg_for_window_list)
@@ -4701,7 +4959,7 @@ static void ImGui::RenderDimmedBackgrounds()
{
// Draw dimming behind CTRL+Tab target window and behind CTRL+Tab UI window
RenderDimmedBackgroundBehindWindow(g.NavWindowingTargetAnim, GetColorU32(ImGuiCol_NavWindowingDimBg, g.DimBgRatio));
- if (g.NavWindowingListWindow != NULL && g.NavWindowingListWindow->Viewport != g.NavWindowingTargetAnim->Viewport)
+ if (g.NavWindowingListWindow != NULL && g.NavWindowingListWindow->Viewport && g.NavWindowingListWindow->Viewport != g.NavWindowingTargetAnim->Viewport)
RenderDimmedBackgroundBehindWindow(g.NavWindowingListWindow, GetColorU32(ImGuiCol_NavWindowingDimBg, g.DimBgRatio));
viewports_already_dimmed[0] = g.NavWindowingTargetAnim->Viewport;
viewports_already_dimmed[1] = g.NavWindowingListWindow ? g.NavWindowingListWindow->Viewport : NULL;
@@ -4750,14 +5008,12 @@ void ImGui::EndFrame()
ErrorCheckEndFrameSanityChecks();
- // Notify OS when our Input Method Editor cursor has moved (e.g. CJK inputs using Microsoft IME)
- if (g.PlatformIO.Platform_SetImeInputPos && (g.PlatformImeLastPos.x == FLT_MAX || ImLengthSqr(g.PlatformImePos - g.PlatformImeLastPos) > 0.0001f))
- if (g.PlatformImePosViewport && g.PlatformImePosViewport->PlatformWindowCreated)
- {
- g.PlatformIO.Platform_SetImeInputPos(g.PlatformImePosViewport, g.PlatformImePos);
- g.PlatformImeLastPos = g.PlatformImePos;
- g.PlatformImePosViewport = NULL;
- }
+ // Notify Platform/OS when our Input Method Editor cursor has moved (e.g. CJK inputs using Microsoft IME)
+ if (g.IO.SetPlatformImeDataFn && memcmp(&g.PlatformImeData, &g.PlatformImeDataPrev, sizeof(ImGuiPlatformImeData)) != 0)
+ {
+ ImGuiViewport* viewport = FindViewportByID(g.PlatformImeViewport);
+ g.IO.SetPlatformImeDataFn(viewport ? viewport : GetMainViewport(), &g.PlatformImeData);
+ }
// Hide implicit/fallback "Debug" window if it hasn't been used
g.WithinFrameScopeWithImplicitWindow = false;
@@ -4920,10 +5176,9 @@ ImVec2 ImGui::CalcTextSize(const char* text, const char* text_end, bool hide_tex
ImFont* font = g.Font;
const float font_size = g.FontSize;
- const float font_line_height = g.FontLineHeight;
if (text == text_display_end)
- return ImVec2(0.0f, font_line_height);
- ImVec2 text_size = font->CalcTextSizeA(font_size, font_line_height, FLT_MAX, wrap_width, text, text_display_end, NULL);
+ return ImVec2(0.0f, font_size);
+ ImVec2 text_size = font->CalcTextSizeA(font_size, FLT_MAX, wrap_width, text, text_display_end, NULL);
// Round
// FIXME: This has been here since Dec 2015 (7b0bf230) but down the line we want this out.
@@ -5002,240 +5257,6 @@ static void FindHoveredWindow()
g.MovingWindow->Viewport = moving_window_viewport;
}
-// Test if mouse cursor is hovering given rectangle
-// NB- Rectangle is clipped by our current clip setting
-// NB- Expand the rectangle to be generous on imprecise inputs systems (g.Style.TouchExtraPadding)
-bool ImGui::IsMouseHoveringRect(const ImVec2& r_min, const ImVec2& r_max, bool clip)
-{
- ImGuiContext& g = *GImGui;
-
- // Clip
- ImRect rect_clipped(r_min, r_max);
- if (clip)
- rect_clipped.ClipWith(g.CurrentWindow->ClipRect);
-
- // Expand for touch input
- const ImRect rect_for_touch(rect_clipped.Min - g.Style.TouchExtraPadding, rect_clipped.Max + g.Style.TouchExtraPadding);
- if (!rect_for_touch.Contains(g.IO.MousePos))
- return false;
- if (!g.MouseViewport->GetMainRect().Overlaps(rect_clipped))
- return false;
- return true;
-}
-
-int ImGui::GetKeyIndex(ImGuiKey imgui_key)
-{
- IM_ASSERT(imgui_key >= 0 && imgui_key < ImGuiKey_COUNT);
- ImGuiContext& g = *GImGui;
- return g.IO.KeyMap[imgui_key];
-}
-
-// Note that dear imgui doesn't know the semantic of each entry of io.KeysDown[]!
-// Use your own indices/enums according to how your backend/engine stored them into io.KeysDown[]!
-bool ImGui::IsKeyDown(int user_key_index)
-{
- if (user_key_index < 0)
- return false;
- ImGuiContext& g = *GImGui;
- IM_ASSERT(user_key_index >= 0 && user_key_index < IM_ARRAYSIZE(g.IO.KeysDown));
- return g.IO.KeysDown[user_key_index];
-}
-
-// t0 = previous time (e.g.: g.Time - g.IO.DeltaTime)
-// t1 = current time (e.g.: g.Time)
-// An event is triggered at:
-// t = 0.0f t = repeat_delay, t = repeat_delay + repeat_rate*N
-int ImGui::CalcTypematicRepeatAmount(float t0, float t1, float repeat_delay, float repeat_rate)
-{
- if (t1 == 0.0f)
- return 1;
- if (t0 >= t1)
- return 0;
- if (repeat_rate <= 0.0f)
- return (t0 < repeat_delay) && (t1 >= repeat_delay);
- const int count_t0 = (t0 < repeat_delay) ? -1 : (int)((t0 - repeat_delay) / repeat_rate);
- const int count_t1 = (t1 < repeat_delay) ? -1 : (int)((t1 - repeat_delay) / repeat_rate);
- const int count = count_t1 - count_t0;
- return count;
-}
-
-int ImGui::GetKeyPressedAmount(int key_index, float repeat_delay, float repeat_rate)
-{
- ImGuiContext& g = *GImGui;
- if (key_index < 0)
- return 0;
- IM_ASSERT(key_index >= 0 && key_index < IM_ARRAYSIZE(g.IO.KeysDown));
- const float t = g.IO.KeysDownDuration[key_index];
- return CalcTypematicRepeatAmount(t - g.IO.DeltaTime, t, repeat_delay, repeat_rate);
-}
-
-bool ImGui::IsKeyPressed(int user_key_index, bool repeat)
-{
- ImGuiContext& g = *GImGui;
- if (user_key_index < 0)
- return false;
- IM_ASSERT(user_key_index >= 0 && user_key_index < IM_ARRAYSIZE(g.IO.KeysDown));
- const float t = g.IO.KeysDownDuration[user_key_index];
- if (t == 0.0f)
- return true;
- if (repeat && t > g.IO.KeyRepeatDelay)
- return GetKeyPressedAmount(user_key_index, g.IO.KeyRepeatDelay, g.IO.KeyRepeatRate) > 0;
- return false;
-}
-
-bool ImGui::IsKeyReleased(int user_key_index)
-{
- ImGuiContext& g = *GImGui;
- if (user_key_index < 0) return false;
- IM_ASSERT(user_key_index >= 0 && user_key_index < IM_ARRAYSIZE(g.IO.KeysDown));
- return g.IO.KeysDownDurationPrev[user_key_index] >= 0.0f && !g.IO.KeysDown[user_key_index];
-}
-
-bool ImGui::IsMouseDown(ImGuiMouseButton button)
-{
- ImGuiContext& g = *GImGui;
- IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
- return g.IO.MouseDown[button];
-}
-
-bool ImGui::IsMouseClicked(ImGuiMouseButton button, bool repeat)
-{
- ImGuiContext& g = *GImGui;
- IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
- const float t = g.IO.MouseDownDuration[button];
- if (t == 0.0f)
- return true;
-
- if (repeat && t > g.IO.KeyRepeatDelay)
- {
- // FIXME: 2019/05/03: Our old repeat code was wrong here and led to doubling the repeat rate, which made it an ok rate for repeat on mouse hold.
- int amount = CalcTypematicRepeatAmount(t - g.IO.DeltaTime, t, g.IO.KeyRepeatDelay, g.IO.KeyRepeatRate * 0.50f);
- if (amount > 0)
- return true;
- }
- return false;
-}
-
-bool ImGui::IsMouseReleased(ImGuiMouseButton button)
-{
- ImGuiContext& g = *GImGui;
- IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
- return g.IO.MouseReleased[button];
-}
-
-bool ImGui::IsMouseDoubleClicked(ImGuiMouseButton button)
-{
- ImGuiContext& g = *GImGui;
- IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
- return g.IO.MouseClickedCount[button] == 2;
-}
-
-int ImGui::GetMouseClickedCount(ImGuiMouseButton button)
-{
- ImGuiContext& g = *GImGui;
- IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
- return g.IO.MouseClickedCount[button];
-}
-
-// Return if a mouse click/drag went past the given threshold. Valid to call during the MouseReleased frame.
-// [Internal] This doesn't test if the button is pressed
-bool ImGui::IsMouseDragPastThreshold(ImGuiMouseButton button, float lock_threshold)
-{
- ImGuiContext& g = *GImGui;
- IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
- if (lock_threshold < 0.0f)
- lock_threshold = g.IO.MouseDragThreshold;
- return g.IO.MouseDragMaxDistanceSqr[button] >= lock_threshold * lock_threshold;
-}
-
-bool ImGui::IsMouseDragging(ImGuiMouseButton button, float lock_threshold)
-{
- ImGuiContext& g = *GImGui;
- IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
- if (!g.IO.MouseDown[button])
- return false;
- return IsMouseDragPastThreshold(button, lock_threshold);
-}
-
-ImVec2 ImGui::GetMousePos()
-{
- ImGuiContext& g = *GImGui;
- return g.IO.MousePos;
-}
-
-// NB: prefer to call right after BeginPopup(). At the time Selectable/MenuItem is activated, the popup is already closed!
-ImVec2 ImGui::GetMousePosOnOpeningCurrentPopup()
-{
- ImGuiContext& g = *GImGui;
- if (g.BeginPopupStack.Size > 0)
- return g.OpenPopupStack[g.BeginPopupStack.Size - 1].OpenMousePos;
- return g.IO.MousePos;
-}
-
-// We typically use ImVec2(-FLT_MAX,-FLT_MAX) to denote an invalid mouse position.
-bool ImGui::IsMousePosValid(const ImVec2* mouse_pos)
-{
- // The assert is only to silence a false-positive in XCode Static Analysis.
- // Because GImGui is not dereferenced in every code path, the static analyzer assume that it may be NULL (which it doesn't for other functions).
- IM_ASSERT(GImGui != NULL);
- const float MOUSE_INVALID = -256000.0f;
- ImVec2 p = mouse_pos ? *mouse_pos : GImGui->IO.MousePos;
- return p.x >= MOUSE_INVALID && p.y >= MOUSE_INVALID;
-}
-
-bool ImGui::IsAnyMouseDown()
-{
- ImGuiContext& g = *GImGui;
- for (int n = 0; n < IM_ARRAYSIZE(g.IO.MouseDown); n++)
- if (g.IO.MouseDown[n])
- return true;
- return false;
-}
-
-// Return the delta from the initial clicking position while the mouse button is clicked or was just released.
-// This is locked and return 0.0f until the mouse moves past a distance threshold at least once.
-// NB: This is only valid if IsMousePosValid(). backends in theory should always keep mouse position valid when dragging even outside the client window.
-ImVec2 ImGui::GetMouseDragDelta(ImGuiMouseButton button, float lock_threshold)
-{
- ImGuiContext& g = *GImGui;
- IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
- if (lock_threshold < 0.0f)
- lock_threshold = g.IO.MouseDragThreshold;
- if (g.IO.MouseDown[button] || g.IO.MouseReleased[button])
- if (g.IO.MouseDragMaxDistanceSqr[button] >= lock_threshold * lock_threshold)
- if (IsMousePosValid(&g.IO.MousePos) && IsMousePosValid(&g.IO.MouseClickedPos[button]))
- return g.IO.MousePos - g.IO.MouseClickedPos[button];
- return ImVec2(0.0f, 0.0f);
-}
-
-void ImGui::ResetMouseDragDelta(ImGuiMouseButton button)
-{
- ImGuiContext& g = *GImGui;
- IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
- // NB: We don't need to reset g.IO.MouseDragMaxDistanceSqr
- g.IO.MouseClickedPos[button] = g.IO.MousePos;
-}
-
-ImGuiMouseCursor ImGui::GetMouseCursor()
-{
- return GImGui->MouseCursor;
-}
-
-void ImGui::SetMouseCursor(ImGuiMouseCursor cursor_type)
-{
- GImGui->MouseCursor = cursor_type;
-}
-
-void ImGui::CaptureKeyboardFromApp(bool capture)
-{
- GImGui->WantCaptureKeyboardNextFrame = capture ? 1 : 0;
-}
-
-void ImGui::CaptureMouseFromApp(bool capture)
-{
- GImGui->WantCaptureMouseNextFrame = capture ? 1 : 0;
-}
-
bool ImGui::IsItemActive()
{
ImGuiContext& g = *GImGui;
@@ -5360,7 +5381,7 @@ void ImGui::SetActiveIdUsingNavAndKeys()
IM_ASSERT(g.ActiveId != 0);
g.ActiveIdUsingNavDirMask = ~(ImU32)0;
g.ActiveIdUsingNavInputMask = ~(ImU32)0;
- g.ActiveIdUsingKeyInputMask = ~(ImU64)0;
+ g.ActiveIdUsingKeyInputMask.SetAllBits();
NavMoveRequestCancel();
}
@@ -6161,7 +6182,7 @@ void ImGui::RenderWindowTitleBarContents(ImGuiWindow* window, const ImRect& titl
// FIXME: Would be nice to generalize the subtleties expressed here into reusable code.
float pad_l = style.FramePadding.x;
float pad_r = style.FramePadding.x;
- float button_sz = g.FontLineHeight;
+ float button_sz = g.FontSize;
ImVec2 close_button_pos;
ImVec2 collapse_button_pos;
if (has_close_button)
@@ -6362,10 +6383,10 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
BeginDocked(window, p_open);
flags = window->Flags;
if (window->DockIsActive)
+ {
IM_ASSERT(window->DockNode != NULL);
-
- // Docking currently override constraints
- g.NextWindowData.Flags &= ~ImGuiNextWindowDataFlags_HasSizeConstraint;
+ g.NextWindowData.Flags &= ~ImGuiNextWindowDataFlags_HasSizeConstraint; // Docking currently override constraints
+ }
// Amend the Appearing flag
if (window->DockTabIsVisible && !dock_tab_was_visible && dock_node_was_visible && !window->Appearing && !window_was_appearing)
@@ -6473,6 +6494,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
{
// Initialize
const bool window_is_child_tooltip = (flags & ImGuiWindowFlags_ChildWindow) && (flags & ImGuiWindowFlags_Tooltip); // FIXME-WIP: Undocumented behavior of Child+Tooltip for pinned tooltip (#1345)
+ const bool window_just_appearing_after_hidden_for_resize = (window->HiddenFramesCannotSkipItems > 0);
window->Active = true;
window->HasCloseButton = (p_open != NULL);
window->ClipRect = ImVec4(-FLT_MAX, -FLT_MAX, +FLT_MAX, +FLT_MAX);
@@ -6506,7 +6528,6 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
// UPDATE CONTENTS SIZE, UPDATE HIDDEN STATUS
// Update contents size from last frame for auto-fitting (or use explicit size)
- const bool window_just_appearing_after_hidden_for_resize = (window->HiddenFramesCannotSkipItems > 0);
CalcWindowContentSizes(window, &window->ContentSize, &window->ContentSizeIdeal);
// FIXME: These flags are decremented before they are used. This means that in order to have these fields produce their intended behaviors
@@ -6740,6 +6761,18 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
}
}
+ // [Test Engine] Register whole window in the item system
+#ifdef IMGUI_ENABLE_TEST_ENGINE
+ if (g.TestEngineHookItems)
+ {
+ IM_ASSERT(window->IDStack.Size == 1);
+ window->IDStack.Size = 0;
+ IMGUI_TEST_ENGINE_ITEM_ADD(window->Rect(), window->ID);
+ IMGUI_TEST_ENGINE_ITEM_INFO(window->ID, window->Name, (g.HoveredWindow == window) ? ImGuiItemStatusFlags_HoveredRect : 0);
+ window->IDStack.Size = 1;
+ }
+#endif
+
// Decide if we are going to handle borders and resize grips
const bool handle_borders_and_resize_grips = (window->DockNodeAsHost || !window->DockIsActive);
@@ -6930,7 +6963,6 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
window->DC.NavLayerCurrent = ImGuiNavLayer_Main;
window->DC.NavLayersActiveMask = window->DC.NavLayersActiveMaskNext;
- window->DC.NavLayersActiveMaskNext = 0x00;
window->DC.NavHideHighlightOneFrame = false;
window->DC.NavHasScroll = (window->ScrollMax.y > 0.0f);
@@ -7008,14 +7040,13 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
// We fill last item data based on Title Bar/Tab, in order for IsItemHovered() and IsItemActive() to be usable after Begin().
// This is useful to allow creating context menus on title bar only, etc.
if (window->DockIsActive)
- SetLastItemData(window->ID, g.CurrentItemFlags, window->DockTabItemStatusFlags, window->DockTabItemRect);
+ SetLastItemData(window->MoveId, g.CurrentItemFlags, window->DockTabItemStatusFlags, window->DockTabItemRect);
else
SetLastItemData(window->MoveId, g.CurrentItemFlags, IsMouseHoveringRect(title_bar_rect.Min, title_bar_rect.Max, false) ? ImGuiItemStatusFlags_HoveredRect : 0, title_bar_rect);
-#ifdef IMGUI_ENABLE_TEST_ENGINE
+ // [Test Engine] Register title bar / tab
if (!(window->Flags & ImGuiWindowFlags_NoTitleBar))
IMGUI_TEST_ENGINE_ITEM_ADD(g.LastItemData.Rect, g.LastItemData.ID);
-#endif
}
else
{
@@ -7092,6 +7123,10 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
skip_items = true;
window->SkipItems = skip_items;
+ // Only clear NavLayersActiveMaskNext when marked as visible, so a CTRL+Tab back can use a safe value.
+ if (!window->SkipItems)
+ window->DC.NavLayersActiveMaskNext = 0x00;
+
// Sanity check: there are two spots which can set Appearing = true
// - when 'window_just_activated_by_user' is set -> HiddenFramesCannotSkipItems is set -> SkipItems always false
// - in BeginDocked() path when DockNodeIsVisible == DockTabIsVisible == true -> hidden _should_ be all zero // FIXME: Not formally proven, hence the assert.
@@ -7269,7 +7304,7 @@ void ImGui::FocusWindow(ImGuiWindow* window)
// Select in dock node
if (dock_node && dock_node->TabBar)
- dock_node->TabBar->SelectedTabId = dock_node->TabBar->NextSelectedTabId = window->ID;
+ dock_node->TabBar->SelectedTabId = dock_node->TabBar->NextSelectedTabId = window->TabId;
// Bring to front
BringWindowToFocusFront(focus_front_window);
@@ -7319,19 +7354,14 @@ void ImGui::SetCurrentFont(ImFont* font)
IM_ASSERT(font && font->IsLoaded()); // Font Atlas not created. Did you call io.Fonts->GetTexDataAsRGBA32 / GetTexDataAsAlpha8 ?
IM_ASSERT(font->Scale > 0.0f);
g.Font = font;
- g.FontBaseScale = ImMax(0.01f, g.IO.FontGlobalScale * g.Font->Scale);
- const float font_scale = g.FontBaseScale * (g.CurrentWindow ? g.CurrentWindow->CalcFontScale() : 1.0f);
- g.FontSize = IM_ROUND(g.Font->FontSize * font_scale);
- g.FontLineHeight = IM_ROUND((g.Font->FontSize + g.Font->ExtraLineHeight) * font_scale);
- g.FontBaselineOffset = g.Font->BaselineOffset * font_scale;
+ g.FontBaseSize = ImMax(1.0f, g.IO.FontGlobalScale * g.Font->FontSize * g.Font->Scale);
+ g.FontSize = g.CurrentWindow ? g.CurrentWindow->CalcFontSize() : 0.0f;
ImFontAtlas* atlas = g.Font->ContainerAtlas;
g.DrawListSharedData.TexUvWhitePixel = atlas->TexUvWhitePixel;
g.DrawListSharedData.TexUvLines = atlas->TexUvLines;
g.DrawListSharedData.Font = g.Font;
g.DrawListSharedData.FontSize = g.FontSize;
- g.DrawListSharedData.FontLineHeight = g.FontLineHeight;
- g.DrawListSharedData.FontBaselineOffset = g.FontBaselineOffset;
}
void ImGui::PushFont(ImFont* font)
@@ -7861,16 +7891,6 @@ float ImGui::GetFontSize()
return GImGui->FontSize;
}
-float ImGui::GetFontLineHeight()
-{
- return GImGui->FontLineHeight;
-}
-
-float ImGui::GetFontBaselineOffset()
-{
- return GImGui->FontBaselineOffset;
-}
-
ImVec2 ImGui::GetFontTexUvWhitePixel()
{
return GImGui->DrawListSharedData.TexUvWhitePixel;
@@ -7882,7 +7902,7 @@ void ImGui::SetWindowFontScale(float scale)
ImGuiContext& g = *GImGui;
ImGuiWindow* window = GetCurrentWindow();
window->FontWindowScale = scale;
- SetCurrentFont(g.Font);
+ g.FontSize = g.DrawListSharedData.FontSize = window->CalcFontSize();
}
void ImGui::ActivateItem(ImGuiID id)
@@ -8053,6 +8073,440 @@ bool ImGui::IsRectVisible(const ImVec2& rect_min, const ImVec2& rect_max)
//-----------------------------------------------------------------------------
+// [SECTION] INPUTS
+//-----------------------------------------------------------------------------
+
+// Test if mouse cursor is hovering given rectangle
+// NB- Rectangle is clipped by our current clip setting
+// NB- Expand the rectangle to be generous on imprecise inputs systems (g.Style.TouchExtraPadding)
+bool ImGui::IsMouseHoveringRect(const ImVec2& r_min, const ImVec2& r_max, bool clip)
+{
+ ImGuiContext& g = *GImGui;
+
+ // Clip
+ ImRect rect_clipped(r_min, r_max);
+ if (clip)
+ rect_clipped.ClipWith(g.CurrentWindow->ClipRect);
+
+ // Expand for touch input
+ const ImRect rect_for_touch(rect_clipped.Min - g.Style.TouchExtraPadding, rect_clipped.Max + g.Style.TouchExtraPadding);
+ if (!rect_for_touch.Contains(g.IO.MousePos))
+ return false;
+ if (!g.MouseViewport->GetMainRect().Overlaps(rect_clipped))
+ return false;
+ return true;
+}
+
+ImGuiKeyData* ImGui::GetKeyData(ImGuiKey key)
+{
+ ImGuiContext& g = *GImGui;
+ int index;
+#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO
+ IM_ASSERT(key >= ImGuiKey_LegacyNativeKey_BEGIN && key < ImGuiKey_NamedKey_END);
+ if (IsLegacyKey(key))
+ index = (g.IO.KeyMap[key] != -1) ? g.IO.KeyMap[key] : key; // Remap native->imgui or imgui->native
+ else
+ index = key;
+#else
+ IM_ASSERT(IsNamedKey(key) && "Support for user key indices was dropped in favor of ImGuiKey. Please update backend & user code.");
+ index = key - ImGuiKey_NamedKey_BEGIN;
+#endif
+ return &g.IO.KeysData[index];
+}
+
+#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO
+int ImGui::GetKeyIndex(ImGuiKey key)
+{
+ ImGuiContext& g = *GImGui;
+ IM_ASSERT(IsNamedKey(key));
+ const ImGuiKeyData* key_data = GetKeyData(key);
+ return (int)(key_data - g.IO.KeysData);
+}
+#endif
+
+// Those names a provided for debugging purpose and are not meant to be saved persistently not compared.
+static const char* const GKeyNames[] =
+{
+ "Tab", "LeftArrow", "RightArrow", "UpArrow", "DownArrow", "PageUp", "PageDown",
+ "Home", "End", "Insert", "Delete", "Backspace", "Space", "Enter", "Escape",
+ "LeftCtrl", "LeftShift", "LeftAlt", "LeftSuper", "RightCtrl", "RightShift", "RightAlt", "RightSuper", "Menu",
+ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H",
+ "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
+ "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12",
+ "Apostrophe", "Comma", "Minus", "Period", "Slash", "Semicolon", "Equal", "LeftBracket",
+ "Backslash", "RightBracket", "GraveAccent", "CapsLock", "ScrollLock", "NumLock", "PrintScreen",
+ "Pause", "Keypad0", "Keypad1", "Keypad2", "Keypad3", "Keypad4", "Keypad5", "Keypad6",
+ "Keypad7", "Keypad8", "Keypad9", "KeypadDecimal", "KeypadDivide", "KeypadMultiply",
+ "KeypadSubtract", "KeypadAdd", "KeypadEnter", "KeypadEqual",
+ "GamepadStart", "GamepadBack", "GamepadFaceUp", "GamepadFaceDown", "GamepadFaceLeft", "GamepadFaceRight",
+ "GamepadDpadUp", "GamepadDpadDown", "GamepadDpadLeft", "GamepadDpadRight",
+ "GamepadL1", "GamepadR1", "GamepadL2", "GamepadR2", "GamepadL3", "GamepadR3",
+ "GamepadLStickUp", "GamepadLStickDown", "GamepadLStickLeft", "GamepadLStickRight",
+ "GamepadRStickUp", "GamepadRStickDown", "GamepadRStickLeft", "GamepadRStickRight",
+ "ModCtrl", "ModShift", "ModAlt", "ModSuper"
+};
+IM_STATIC_ASSERT(ImGuiKey_NamedKey_COUNT == IM_ARRAYSIZE(GKeyNames));
+
+const char* ImGui::GetKeyName(ImGuiKey key)
+{
+#ifdef IMGUI_DISABLE_OBSOLETE_KEYIO
+ IM_ASSERT((IsNamedKey(key) || key == ImGuiKey_None) && "Support for user key indices was dropped in favor of ImGuiKey. Please update backend and user code.");
+#else
+ if (IsLegacyKey(key))
+ {
+ ImGuiIO& io = GetIO();
+ if (io.KeyMap[key] == -1)
+ return "N/A";
+ IM_ASSERT(IsNamedKey((ImGuiKey)io.KeyMap[key]));
+ key = (ImGuiKey)io.KeyMap[key];
+ }
+#endif
+ if (key == ImGuiKey_None)
+ return "None";
+ if (!IsNamedKey(key))
+ return "Unknown";
+
+ 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:
+// t = 0.0f t = repeat_delay, t = repeat_delay + repeat_rate*N
+int ImGui::CalcTypematicRepeatAmount(float t0, float t1, float repeat_delay, float repeat_rate)
+{
+ if (t1 == 0.0f)
+ return 1;
+ if (t0 >= t1)
+ return 0;
+ if (repeat_rate <= 0.0f)
+ return (t0 < repeat_delay) && (t1 >= repeat_delay);
+ const int count_t0 = (t0 < repeat_delay) ? -1 : (int)((t0 - repeat_delay) / repeat_rate);
+ const int count_t1 = (t1 < repeat_delay) ? -1 : (int)((t1 - repeat_delay) / repeat_rate);
+ const int count = count_t1 - count_t0;
+ return count;
+}
+
+int ImGui::GetKeyPressedAmount(ImGuiKey key, float repeat_delay, float repeat_rate)
+{
+ ImGuiContext& g = *GImGui;
+ const ImGuiKeyData* key_data = GetKeyData(key);
+ const float t = key_data->DownDuration;
+ return CalcTypematicRepeatAmount(t - g.IO.DeltaTime, t, repeat_delay, repeat_rate);
+}
+
+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;
+}
+
+bool ImGui::IsKeyReleased(ImGuiKey key)
+{
+ const ImGuiKeyData* key_data = GetKeyData(key);
+ return key_data->DownDurationPrev >= 0.0f && !key_data->Down;
+}
+
+bool ImGui::IsMouseDown(ImGuiMouseButton button)
+{
+ ImGuiContext& g = *GImGui;
+ IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
+ return g.IO.MouseDown[button];
+}
+
+bool ImGui::IsMouseClicked(ImGuiMouseButton button, bool repeat)
+{
+ ImGuiContext& g = *GImGui;
+ IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
+ const float t = g.IO.MouseDownDuration[button];
+ if (t == 0.0f)
+ return true;
+
+ if (repeat && t > g.IO.KeyRepeatDelay)
+ {
+ // FIXME: 2019/05/03: Our old repeat code was wrong here and led to doubling the repeat rate, which made it an ok rate for repeat on mouse hold.
+ int amount = CalcTypematicRepeatAmount(t - g.IO.DeltaTime, t, g.IO.KeyRepeatDelay, g.IO.KeyRepeatRate * 0.50f);
+ if (amount > 0)
+ return true;
+ }
+ return false;
+}
+
+bool ImGui::IsMouseReleased(ImGuiMouseButton button)
+{
+ ImGuiContext& g = *GImGui;
+ IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
+ return g.IO.MouseReleased[button];
+}
+
+bool ImGui::IsMouseDoubleClicked(ImGuiMouseButton button)
+{
+ ImGuiContext& g = *GImGui;
+ IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
+ return g.IO.MouseClickedCount[button] == 2;
+}
+
+int ImGui::GetMouseClickedCount(ImGuiMouseButton button)
+{
+ ImGuiContext& g = *GImGui;
+ IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
+ return g.IO.MouseClickedCount[button];
+}
+
+// Return if a mouse click/drag went past the given threshold. Valid to call during the MouseReleased frame.
+// [Internal] This doesn't test if the button is pressed
+bool ImGui::IsMouseDragPastThreshold(ImGuiMouseButton button, float lock_threshold)
+{
+ ImGuiContext& g = *GImGui;
+ IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
+ if (lock_threshold < 0.0f)
+ lock_threshold = g.IO.MouseDragThreshold;
+ return g.IO.MouseDragMaxDistanceSqr[button] >= lock_threshold * lock_threshold;
+}
+
+bool ImGui::IsMouseDragging(ImGuiMouseButton button, float lock_threshold)
+{
+ ImGuiContext& g = *GImGui;
+ IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
+ if (!g.IO.MouseDown[button])
+ return false;
+ return IsMouseDragPastThreshold(button, lock_threshold);
+}
+
+ImVec2 ImGui::GetMousePos()
+{
+ ImGuiContext& g = *GImGui;
+ return g.IO.MousePos;
+}
+
+// NB: prefer to call right after BeginPopup(). At the time Selectable/MenuItem is activated, the popup is already closed!
+ImVec2 ImGui::GetMousePosOnOpeningCurrentPopup()
+{
+ ImGuiContext& g = *GImGui;
+ if (g.BeginPopupStack.Size > 0)
+ return g.OpenPopupStack[g.BeginPopupStack.Size - 1].OpenMousePos;
+ return g.IO.MousePos;
+}
+
+// We typically use ImVec2(-FLT_MAX,-FLT_MAX) to denote an invalid mouse position.
+bool ImGui::IsMousePosValid(const ImVec2* mouse_pos)
+{
+ // The assert is only to silence a false-positive in XCode Static Analysis.
+ // Because GImGui is not dereferenced in every code path, the static analyzer assume that it may be NULL (which it doesn't for other functions).
+ IM_ASSERT(GImGui != NULL);
+ const float MOUSE_INVALID = -256000.0f;
+ ImVec2 p = mouse_pos ? *mouse_pos : GImGui->IO.MousePos;
+ return p.x >= MOUSE_INVALID && p.y >= MOUSE_INVALID;
+}
+
+// [WILL OBSOLETE] This was designed for backends, but prefer having backend maintain a mask of held mouse buttons, because upcoming input queue system will make this invalid.
+bool ImGui::IsAnyMouseDown()
+{
+ ImGuiContext& g = *GImGui;
+ for (int n = 0; n < IM_ARRAYSIZE(g.IO.MouseDown); n++)
+ if (g.IO.MouseDown[n])
+ return true;
+ return false;
+}
+
+// Return the delta from the initial clicking position while the mouse button is clicked or was just released.
+// This is locked and return 0.0f until the mouse moves past a distance threshold at least once.
+// NB: This is only valid if IsMousePosValid(). backends in theory should always keep mouse position valid when dragging even outside the client window.
+ImVec2 ImGui::GetMouseDragDelta(ImGuiMouseButton button, float lock_threshold)
+{
+ ImGuiContext& g = *GImGui;
+ IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
+ if (lock_threshold < 0.0f)
+ lock_threshold = g.IO.MouseDragThreshold;
+ if (g.IO.MouseDown[button] || g.IO.MouseReleased[button])
+ if (g.IO.MouseDragMaxDistanceSqr[button] >= lock_threshold * lock_threshold)
+ if (IsMousePosValid(&g.IO.MousePos) && IsMousePosValid(&g.IO.MouseClickedPos[button]))
+ return g.IO.MousePos - g.IO.MouseClickedPos[button];
+ return ImVec2(0.0f, 0.0f);
+}
+
+void ImGui::ResetMouseDragDelta(ImGuiMouseButton button)
+{
+ ImGuiContext& g = *GImGui;
+ IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
+ // NB: We don't need to reset g.IO.MouseDragMaxDistanceSqr
+ g.IO.MouseClickedPos[button] = g.IO.MousePos;
+}
+
+ImGuiMouseCursor ImGui::GetMouseCursor()
+{
+ ImGuiContext& g = *GImGui;
+ return g.MouseCursor;
+}
+
+void ImGui::SetMouseCursor(ImGuiMouseCursor cursor_type)
+{
+ ImGuiContext& g = *GImGui;
+ g.MouseCursor = cursor_type;
+}
+
+void ImGui::CaptureKeyboardFromApp(bool capture)
+{
+ ImGuiContext& g = *GImGui;
+ g.WantCaptureKeyboardNextFrame = capture ? 1 : 0;
+}
+
+void ImGui::CaptureMouseFromApp(bool capture)
+{
+ ImGuiContext& g = *GImGui;
+ g.WantCaptureMouseNextFrame = capture ? 1 : 0;
+}
+
+static const char* GetInputSourceName(ImGuiInputSource source)
+{
+ const char* input_source_names[] = { "None", "Mouse", "Keyboard", "Gamepad", "Nav", "Clipboard" };
+ IM_ASSERT(IM_ARRAYSIZE(input_source_names) == ImGuiInputSource_COUNT && source >= 0 && source < ImGuiInputSource_COUNT);
+ return input_source_names[source];
+}
+
+
+// Process input queue
+// - trickle_fast_inputs = false : process all events, turn into flattened input state (e.g. successive down/up/down/up will be lost)
+// - trickle_fast_inputs = true : process as many events as possible (successive down/up/down/up will be trickled over several frames so nothing is lost) (new feature in 1.87)
+void ImGui::UpdateInputEvents(bool trickle_fast_inputs)
+{
+ ImGuiContext& g = *GImGui;
+ ImGuiIO& io = g.IO;
+
+ bool mouse_moved = false, mouse_wheeled = false, key_changed = false, text_inputed = false;
+ int mouse_button_changed = 0x00;
+ ImBitArray<ImGuiKey_KeysData_SIZE> key_changed_mask;
+
+ int event_n = 0;
+ for (; event_n < g.InputEventsQueue.Size; event_n++)
+ {
+ const ImGuiInputEvent* e = &g.InputEventsQueue[event_n];
+ if (e->Type == ImGuiInputEventType_MousePos)
+ {
+ ImVec2 event_pos(e->MousePos.PosX, e->MousePos.PosY);
+ if (IsMousePosValid(&event_pos))
+ event_pos = ImVec2(ImFloorSigned(event_pos.x), ImFloorSigned(event_pos.y)); // Apply same flooring as UpdateMouseInputs()
+ if (io.MousePos.x != event_pos.x || io.MousePos.y != event_pos.y)
+ {
+ // Trickling Rule: Stop processing queued events if we already handled a mouse button change
+ if (trickle_fast_inputs && (mouse_button_changed != 0 || mouse_wheeled || key_changed || text_inputed))
+ break;
+ io.MousePos = event_pos;
+ mouse_moved = true;
+ }
+ }
+ else if (e->Type == ImGuiInputEventType_MouseButton)
+ {
+ const ImGuiMouseButton button = e->MouseButton.Button;
+ IM_ASSERT(button >= 0 && button < ImGuiMouseButton_COUNT);
+ if (io.MouseDown[button] != e->MouseButton.Down)
+ {
+ // Trickling Rule: Stop processing queued events if we got multiple action on the same button
+ if (trickle_fast_inputs && ((mouse_button_changed & (1 << button)) || mouse_wheeled))
+ break;
+ io.MouseDown[button] = e->MouseButton.Down;
+ mouse_button_changed |= (1 << button);
+ }
+ }
+ else if (e->Type == ImGuiInputEventType_MouseWheel)
+ {
+ if (e->MouseWheel.WheelX != 0.0f || e->MouseWheel.WheelY != 0.0f)
+ {
+ // Trickling Rule: Stop processing queued events if we got multiple action on the event
+ if (trickle_fast_inputs && (mouse_wheeled || mouse_button_changed != 0))
+ break;
+ io.MouseWheelH += e->MouseWheel.WheelX;
+ io.MouseWheel += e->MouseWheel.WheelY;
+ mouse_wheeled = true;
+ }
+ }
+ else if (e->Type == ImGuiInputEventType_MouseViewport)
+ {
+ io.MouseHoveredViewport = e->MouseViewport.HoveredViewportID;
+ }
+ else if (e->Type == ImGuiInputEventType_Key)
+ {
+ ImGuiKey key = e->Key.Key;
+ IM_ASSERT(key != ImGuiKey_None);
+ const int keydata_index = (key - ImGuiKey_KeysData_OFFSET);
+ ImGuiKeyData* keydata = &io.KeysData[keydata_index];
+ if (keydata->Down != e->Key.Down || keydata->AnalogValue != e->Key.AnalogValue)
+ {
+ // Trickling Rule: Stop processing queued events if we got multiple action on the same button
+ if (trickle_fast_inputs && keydata->Down != e->Key.Down && (key_changed_mask.TestBit(keydata_index) || text_inputed || mouse_button_changed != 0))
+ break;
+ keydata->Down = e->Key.Down;
+ keydata->AnalogValue = e->Key.AnalogValue;
+ key_changed = true;
+ key_changed_mask.SetBit(keydata_index);
+
+ if (key == ImGuiKey_ModCtrl || key == ImGuiKey_ModShift || key == ImGuiKey_ModAlt || key == ImGuiKey_ModSuper)
+ {
+ if (key == ImGuiKey_ModCtrl) { io.KeyCtrl = keydata->Down; }
+ if (key == ImGuiKey_ModShift) { io.KeyShift = keydata->Down; }
+ if (key == ImGuiKey_ModAlt) { io.KeyAlt = keydata->Down; }
+ if (key == ImGuiKey_ModSuper) { io.KeySuper = keydata->Down; }
+ io.KeyMods = GetMergedKeyModFlags();
+ }
+ }
+ }
+ else if (e->Type == ImGuiInputEventType_Char)
+ {
+ // Trickling Rule: Stop processing queued events if keys/mouse have been interacted with
+ if (trickle_fast_inputs && (key_changed || mouse_button_changed != 0 || mouse_moved || mouse_wheeled))
+ break;
+ unsigned int c = e->Text.Char;
+ io.InputQueueCharacters.push_back(c <= IM_UNICODE_CODEPOINT_MAX ? (ImWchar)c : IM_UNICODE_CODEPOINT_INVALID);
+ text_inputed = true;
+ }
+ else if (e->Type == ImGuiInputEventType_Focus)
+ {
+ // We intentionally overwrite this and process lower, in order to give a chance
+ // to multi-viewports backends to queue AddFocusEvent(false) + AddFocusEvent(true) in same frame.
+ io.AppFocusLost = !e->AppFocused.Focused;
+ }
+ else
+ {
+ IM_ASSERT(0 && "Unknown event!");
+ }
+ }
+
+ // Record trail (for domain-specific applications wanting to access a precise trail)
+ //if (event_n != 0) IMGUI_DEBUG_LOG("Processed: %d / Remaining: %d\n", event_n, g.InputEventsQueue.Size - event_n);
+ for (int n = 0; n < event_n; n++)
+ g.InputEventsTrail.push_back(g.InputEventsQueue[n]);
+
+ // Remaining events will be processed on the next frame
+ if (event_n == g.InputEventsQueue.Size)
+ g.InputEventsQueue.resize(0);
+ else
+ g.InputEventsQueue.erase(g.InputEventsQueue.Data, g.InputEventsQueue.Data + event_n);
+
+ // Clear buttons state when focus is lost
+ // (this is useful so e.g. releasing Alt after focus loss on Alt-Tab doesn't trigger the Alt menu toggle)
+ if (g.IO.AppFocusLost)
+ {
+ g.IO.ClearInputKeys();
+ g.IO.AppFocusLost = false;
+ }
+}
+
+
+//-----------------------------------------------------------------------------
// [SECTION] ERROR CHECKING
//-----------------------------------------------------------------------------
@@ -8098,12 +8552,14 @@ static void ImGui::ErrorCheckNewFrameSanityChecks()
IM_ASSERT(g.Style.Alpha >= 0.0f && g.Style.Alpha <= 1.0f && "Invalid style setting!"); // Allows us to avoid a few clamps in color computations
IM_ASSERT(g.Style.WindowMinSize.x >= 1.0f && g.Style.WindowMinSize.y >= 1.0f && "Invalid style setting.");
IM_ASSERT(g.Style.WindowMenuButtonPosition == ImGuiDir_None || g.Style.WindowMenuButtonPosition == ImGuiDir_Left || g.Style.WindowMenuButtonPosition == ImGuiDir_Right);
- for (int n = 0; n < ImGuiKey_COUNT; n++)
- IM_ASSERT(g.IO.KeyMap[n] >= -1 && g.IO.KeyMap[n] < IM_ARRAYSIZE(g.IO.KeysDown) && "io.KeyMap[] contains an out of bound value (need to be 0..512, or -1 for unmapped key)");
+#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO
+ for (int n = ImGuiKey_NamedKey_BEGIN; n < ImGuiKey_COUNT; n++)
+ IM_ASSERT(g.IO.KeyMap[n] >= -1 && g.IO.KeyMap[n] < IM_ARRAYSIZE(g.IO.KeysDown) && "io.KeyMap[] contains an out of bound value (need to be 0..511, or -1 for unmapped key)");
// Check: required key mapping (we intentionally do NOT check all keys to not pressure user into setting up everything, but Space is required and was only added in 1.60 WIP)
- if (g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard)
+ if ((g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) && g.IO.BackendUsingLegacyKeyArrays == 1)
IM_ASSERT(g.IO.KeyMap[ImGuiKey_Space] != -1 && "ImGuiKey_Space is not mapped, required for keyboard navigation.");
+#endif
// Check: the io.ConfigWindowsResizeFromEdges option requires backend to honor mouse cursor changes and set the ImGuiBackendFlags_HasMouseCursors flag accordingly.
if (g.IO.ConfigWindowsResizeFromEdges && !(g.IO.BackendFlags & ImGuiBackendFlags_HasMouseCursors))
@@ -8650,25 +9106,25 @@ ImVec2 ImGui::CalcItemSize(ImVec2 size, float default_w, float default_h)
float ImGui::GetTextLineHeight()
{
ImGuiContext& g = *GImGui;
- return g.FontLineHeight;
+ return g.FontSize;
}
float ImGui::GetTextLineHeightWithSpacing()
{
ImGuiContext& g = *GImGui;
- return g.FontLineHeight + g.Style.ItemSpacing.y;
+ return g.FontSize + g.Style.ItemSpacing.y;
}
float ImGui::GetFrameHeight()
{
ImGuiContext& g = *GImGui;
- return g.FontLineHeight + g.Style.FramePadding.y * 2.0f;
+ return g.FontSize + g.Style.FramePadding.y * 2.0f;
}
float ImGui::GetFrameHeightWithSpacing()
{
ImGuiContext& g = *GImGui;
- return g.FontLineHeight + g.Style.FramePadding.y * 2.0f + g.Style.ItemSpacing.y;
+ return g.FontSize + g.Style.FramePadding.y * 2.0f + g.Style.ItemSpacing.y;
}
// FIXME: All the Contents Region function are messy or misleading. WE WILL AIM TO OBSOLETE ALL OF THEM WITH A NEW "WORK RECT" API. Thanks for your patience!
@@ -9397,7 +9853,8 @@ bool ImGui::BeginPopup(const char* str_id, ImGuiWindowFlags flags)
return false;
}
flags |= ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoSavedSettings;
- return BeginPopupEx(g.CurrentWindow->GetID(str_id), flags);
+ ImGuiID id = g.CurrentWindow->GetID(str_id);
+ return BeginPopupEx(id, flags);
}
// If 'p_open' is specified for a modal popup window, the popup will have a regular close button which will close the popup.
@@ -9476,7 +9933,7 @@ void ImGui::OpenPopupOnItemClick(const char* str_id, ImGuiPopupFlags popup_flags
// - You may want to handle the whole on user side if you have specific needs (e.g. tweaking IsItemHovered() parameters).
// This is essentially the same as:
// id = str_id ? GetID(str_id) : GetItemID();
-// OpenPopupOnItemClick(str_id);
+// OpenPopupOnItemClick(str_id, ImGuiPopupFlags_MouseButtonRight);
// return BeginPopup(id);
// Which is essentially the same as:
// id = str_id ? GetID(str_id) : GetItemID();
@@ -9647,8 +10104,7 @@ ImVec2 ImGui::FindBestWindowPosForPopup(ImGuiWindow* window)
}
if (window->Flags & ImGuiWindowFlags_Popup)
{
- ImRect r_avoid = ImRect(window->Pos.x - 1, window->Pos.y - 1, window->Pos.x + 1, window->Pos.y + 1);
- return FindBestWindowPosForPopupEx(window->Pos, window->Size, &window->AutoPosLastDirection, r_outer, r_avoid, ImGuiPopupPositionPolicy_Default);
+ return FindBestWindowPosForPopupEx(window->Pos, window->Size, &window->AutoPosLastDirection, r_outer, ImRect(window->Pos, window->Pos), ImGuiPopupPositionPolicy_Default); // Ideally we'd disable r_avoid here
}
if (window->Flags & ImGuiWindowFlags_Tooltip)
{
@@ -10161,9 +10617,10 @@ static ImVec2 ImGui::NavCalcPreferredRefPos()
if (g.NavDisableHighlight || !g.NavDisableMouseHover || !window)
{
// Mouse (we need a fallback in case the mouse becomes invalid after being used)
- if (IsMousePosValid(&g.IO.MousePos))
- return g.IO.MousePos;
- return g.MouseLastValidPos;
+ // The +1.0f offset when stored by OpenPopupEx() allows reopening this or another popup (same or another mouse button) while not moving the mouse, it is pretty standard.
+ // In theory we could move that +1.0f offset in OpenPopupEx()
+ ImVec2 p = IsMousePosValid(&g.IO.MousePos) ? g.IO.MousePos : g.MouseLastValidPos;
+ return ImVec2(p.x + 1.0f, p.y);
}
else
{
@@ -10181,6 +10638,18 @@ static ImVec2 ImGui::NavCalcPreferredRefPos()
}
}
+const char* ImGui::GetNavInputName(ImGuiNavInput n)
+{
+ static const char* names[] =
+ {
+ "Activate", "Cancel", "Input", "Menu", "DpadLeft", "DpadRight", "DpadUp", "DpadDown", "LStickLeft", "LStickRight", "LStickUp", "LStickDown",
+ "FocusPrev", "FocusNext", "TweakSlow", "TweakFast", "KeyLeft", "KeyRight", "KeyUp", "KeyDown"
+ };
+ IM_ASSERT(IM_ARRAYSIZE(names) == ImGuiNavInput_COUNT);
+ IM_ASSERT(n >= 0 && n < ImGuiNavInput_COUNT);
+ return names[n];
+}
+
float ImGui::GetNavInputAmount(ImGuiNavInput n, ImGuiInputReadMode mode)
{
ImGuiContext& g = *GImGui;
@@ -10207,7 +10676,7 @@ ImVec2 ImGui::GetNavInputAmount2d(ImGuiNavDirSourceFlags dir_sources, ImGuiInput
{
ImVec2 delta(0.0f, 0.0f);
if (dir_sources & ImGuiNavDirSourceFlags_RawKeyboard)
- delta += ImVec2((float)IsKeyDown(GetKeyIndex(ImGuiKey_RightArrow)) - (float)IsKeyDown(GetKeyIndex(ImGuiKey_LeftArrow)), (float)IsKeyDown(GetKeyIndex(ImGuiKey_DownArrow)) - (float)IsKeyDown(GetKeyIndex(ImGuiKey_UpArrow)));
+ delta += ImVec2((float)IsKeyDown(ImGuiKey_RightArrow) - (float)IsKeyDown(ImGuiKey_LeftArrow), (float)IsKeyDown(ImGuiKey_DownArrow) - (float)IsKeyDown(ImGuiKey_UpArrow));
if (dir_sources & ImGuiNavDirSourceFlags_Keyboard)
delta += ImVec2(GetNavInputAmount(ImGuiNavInput_KeyRight_, mode) - GetNavInputAmount(ImGuiNavInput_KeyLeft_, mode), GetNavInputAmount(ImGuiNavInput_KeyDown_, mode) - GetNavInputAmount(ImGuiNavInput_KeyUp_, mode));
if (dir_sources & ImGuiNavDirSourceFlags_PadDPad)
@@ -10229,21 +10698,38 @@ static void ImGui::NavUpdate()
io.WantSetMousePos = false;
//if (g.NavScoringDebugCount > 0) IMGUI_DEBUG_LOG("NavScoringDebugCount %d for '%s' layer %d (Init:%d, Move:%d)\n", g.NavScoringDebugCount, g.NavWindow ? g.NavWindow->Name : "NULL", g.NavLayer, g.NavInitRequest || g.NavInitResultId != 0, g.NavMoveRequest);
+ // Update Gamepad->Nav inputs mapping
// Set input source as Gamepad when buttons are pressed (as some features differs when used with Gamepad vs Keyboard)
- // (do it before we map Keyboard input!)
- const bool nav_keyboard_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) != 0;
const bool nav_gamepad_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) != 0 && (io.BackendFlags & ImGuiBackendFlags_HasGamepad) != 0;
- if (nav_gamepad_active && g.NavInputSource != ImGuiInputSource_Gamepad)
- {
- if (io.NavInputs[ImGuiNavInput_Activate] > 0.0f || io.NavInputs[ImGuiNavInput_Input] > 0.0f || io.NavInputs[ImGuiNavInput_Cancel] > 0.0f || io.NavInputs[ImGuiNavInput_Menu] > 0.0f
- || io.NavInputs[ImGuiNavInput_DpadLeft] > 0.0f || io.NavInputs[ImGuiNavInput_DpadRight] > 0.0f || io.NavInputs[ImGuiNavInput_DpadUp] > 0.0f || io.NavInputs[ImGuiNavInput_DpadDown] > 0.0f)
- g.NavInputSource = ImGuiInputSource_Gamepad;
+ if (nav_gamepad_active && g.IO.BackendUsingLegacyNavInputArray == false)
+ {
+ for (int n = 0; n < ImGuiNavInput_COUNT; n++)
+ IM_ASSERT(io.NavInputs[n] == 0.0f && "Backend needs to either only use io.AddKeyEvent()/io.AddKeyAnalogEvent(), either only fill legacy io.NavInputs[]. Not both!");
+ #define NAV_MAP_KEY(_KEY, _NAV_INPUT, _ACTIVATE_NAV) do { io.NavInputs[_NAV_INPUT] = io.KeysData[_KEY - ImGuiKey_KeysData_OFFSET].AnalogValue; if (_ACTIVATE_NAV && io.NavInputs[_NAV_INPUT] > 0.0f) { g.NavInputSource = ImGuiInputSource_Gamepad; } } while (0)
+ NAV_MAP_KEY(ImGuiKey_GamepadFaceDown, ImGuiNavInput_Activate, true);
+ NAV_MAP_KEY(ImGuiKey_GamepadFaceRight, ImGuiNavInput_Cancel, true);
+ NAV_MAP_KEY(ImGuiKey_GamepadFaceLeft, ImGuiNavInput_Menu, true);
+ NAV_MAP_KEY(ImGuiKey_GamepadFaceUp, ImGuiNavInput_Input, true);
+ NAV_MAP_KEY(ImGuiKey_GamepadDpadLeft, ImGuiNavInput_DpadLeft, true);
+ NAV_MAP_KEY(ImGuiKey_GamepadDpadRight, ImGuiNavInput_DpadRight, true);
+ NAV_MAP_KEY(ImGuiKey_GamepadDpadUp, ImGuiNavInput_DpadUp, true);
+ NAV_MAP_KEY(ImGuiKey_GamepadDpadDown, ImGuiNavInput_DpadDown, true);
+ NAV_MAP_KEY(ImGuiKey_GamepadL1, ImGuiNavInput_FocusPrev, false);
+ NAV_MAP_KEY(ImGuiKey_GamepadR1, ImGuiNavInput_FocusNext, false);
+ NAV_MAP_KEY(ImGuiKey_GamepadL1, ImGuiNavInput_TweakSlow, false);
+ NAV_MAP_KEY(ImGuiKey_GamepadR1, ImGuiNavInput_TweakFast, false);
+ NAV_MAP_KEY(ImGuiKey_GamepadLStickLeft, ImGuiNavInput_LStickLeft, false);
+ NAV_MAP_KEY(ImGuiKey_GamepadLStickRight, ImGuiNavInput_LStickRight, false);
+ NAV_MAP_KEY(ImGuiKey_GamepadLStickUp, ImGuiNavInput_LStickUp, false);
+ NAV_MAP_KEY(ImGuiKey_GamepadLStickDown, ImGuiNavInput_LStickDown, false);
+ #undef NAV_MAP_KEY
}
// Update Keyboard->Nav inputs mapping
+ const bool nav_keyboard_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) != 0;
if (nav_keyboard_active)
{
- #define NAV_MAP_KEY(_KEY, _NAV_INPUT) do { if (IsKeyDown(io.KeyMap[_KEY])) { io.NavInputs[_NAV_INPUT] = 1.0f; g.NavInputSource = ImGuiInputSource_Keyboard; } } while (0)
+ #define NAV_MAP_KEY(_KEY, _NAV_INPUT) do { if (IsKeyDown(_KEY)) { io.NavInputs[_NAV_INPUT] = 1.0f; g.NavInputSource = ImGuiInputSource_Keyboard; } } while (0)
NAV_MAP_KEY(ImGuiKey_Space, ImGuiNavInput_Activate );
NAV_MAP_KEY(ImGuiKey_Enter, ImGuiNavInput_Input );
NAV_MAP_KEY(ImGuiKey_Escape, ImGuiNavInput_Cancel );
@@ -10352,24 +10838,23 @@ static void ImGui::NavUpdate()
{
// *Fallback* manual-scroll with Nav directional keys when window has no navigable item
ImGuiWindow* window = g.NavWindow;
- const float scroll_speed_x = IM_ROUND(window->CalcFontWidth() * 100 * io.DeltaTime); // We need round the scrolling speed because sub-pixel scroll isn't reliably supported.
- const float scroll_speed_y = IM_ROUND(window->CalcFontHeight() * 100 * io.DeltaTime); // We need round the scrolling speed because sub-pixel scroll isn't reliably supported.
+ const float scroll_speed = IM_ROUND(window->CalcFontSize() * 100 * io.DeltaTime); // We need round the scrolling speed because sub-pixel scroll isn't reliably supported.
const ImGuiDir move_dir = g.NavMoveDir;
if (window->DC.NavLayersActiveMask == 0x00 && window->DC.NavHasScroll && move_dir != ImGuiDir_None)
{
if (move_dir == ImGuiDir_Left || move_dir == ImGuiDir_Right)
- SetScrollX(window, ImFloor(window->Scroll.x + ((move_dir == ImGuiDir_Left) ? -1.0f : +1.0f) * scroll_speed_x));
+ SetScrollX(window, ImFloor(window->Scroll.x + ((move_dir == ImGuiDir_Left) ? -1.0f : +1.0f) * scroll_speed));
if (move_dir == ImGuiDir_Up || move_dir == ImGuiDir_Down)
- SetScrollY(window, ImFloor(window->Scroll.y + ((move_dir == ImGuiDir_Up) ? -1.0f : +1.0f) * scroll_speed_y));
+ SetScrollY(window, ImFloor(window->Scroll.y + ((move_dir == ImGuiDir_Up) ? -1.0f : +1.0f) * scroll_speed));
}
// *Normal* Manual scroll with NavScrollXXX keys
// Next movement request will clamp the NavId reference rectangle to the visible area, so navigation will resume within those bounds.
ImVec2 scroll_dir = GetNavInputAmount2d(ImGuiNavDirSourceFlags_PadLStick, ImGuiInputReadMode_Down, 1.0f / 10.0f, 10.0f);
if (scroll_dir.x != 0.0f && window->ScrollbarX)
- SetScrollX(window, ImFloor(window->Scroll.x + scroll_dir.x * scroll_speed_x));
+ SetScrollX(window, ImFloor(window->Scroll.x + scroll_dir.x * scroll_speed));
if (scroll_dir.y != 0.0f)
- SetScrollY(window, ImFloor(window->Scroll.y + scroll_dir.y * scroll_speed_y));
+ SetScrollY(window, ImFloor(window->Scroll.y + scroll_dir.y * scroll_speed));
}
// Always prioritize mouse highlight if navigation is disabled
@@ -10462,7 +10947,7 @@ void ImGui::NavUpdateCreateMoveRequest()
// [DEBUG] Always send a request
#if IMGUI_DEBUG_NAV_SCORING
- if (io.KeyCtrl && IsKeyPressedMap(ImGuiKey_C))
+ if (io.KeyCtrl && IsKeyPressed(ImGuiKey_C))
g.NavMoveDirForDebug = (ImGuiDir)((g.NavMoveDirForDebug + 1) & 3);
if (io.KeyCtrl && g.NavMoveDir == ImGuiDir_None)
{
@@ -10488,15 +10973,21 @@ void ImGui::NavUpdateCreateMoveRequest()
// When using gamepad, we project the reference nav bounding box into window visible area.
// This is to allow resuming navigation inside the visible area after doing a large amount of scrolling, since with gamepad every movements are relative
// (can't focus a visible object like we can with the mouse).
- if (g.NavMoveSubmitted && g.NavInputSource == ImGuiInputSource_Gamepad && g.NavLayer == ImGuiNavLayer_Main && window != NULL)
+ if (g.NavMoveSubmitted && g.NavInputSource == ImGuiInputSource_Gamepad && g.NavLayer == ImGuiNavLayer_Main && window != NULL)// && (g.NavMoveFlags & ImGuiNavMoveFlags_Forwarded))
{
- ImRect window_rect_rel = WindowRectAbsToRel(window, ImRect(window->InnerRect.Min - ImVec2(1, 1), window->InnerRect.Max + ImVec2(1, 1)));
- if (!window_rect_rel.Contains(window->NavRectRel[g.NavLayer]))
+ bool clamp_x = (g.NavMoveFlags & (ImGuiNavMoveFlags_LoopX | ImGuiNavMoveFlags_WrapX)) == 0;
+ bool clamp_y = (g.NavMoveFlags & (ImGuiNavMoveFlags_LoopY | ImGuiNavMoveFlags_WrapY)) == 0;
+ ImRect inner_rect_rel = WindowRectAbsToRel(window, ImRect(window->InnerRect.Min - ImVec2(1, 1), window->InnerRect.Max + ImVec2(1, 1)));
+ if ((clamp_x || clamp_y) && !inner_rect_rel.Contains(window->NavRectRel[g.NavLayer]))
{
- IMGUI_DEBUG_LOG_NAV("[nav] NavMoveRequest: clamp NavRectRel\n");
- float pad = window->CalcFontWidth() * 0.5f;
- window_rect_rel.Expand(ImVec2(-ImMin(window_rect_rel.GetWidth(), pad), -ImMin(window_rect_rel.GetHeight(), pad))); // Terrible approximation for the intent of starting navigation from first fully visible item
- window->NavRectRel[g.NavLayer].ClipWithFull(window_rect_rel);
+ IMGUI_DEBUG_LOG_NAV("[nav] NavMoveRequest: clamp NavRectRel for gamepad move\n");
+ float pad_x = ImMin(inner_rect_rel.GetWidth(), window->CalcFontSize() * 0.5f);
+ float pad_y = ImMin(inner_rect_rel.GetHeight(), window->CalcFontSize() * 0.5f); // Terrible approximation for the intent of starting navigation from first fully visible item
+ inner_rect_rel.Min.x = clamp_x ? (inner_rect_rel.Min.x + pad_x) : -FLT_MAX;
+ inner_rect_rel.Max.x = clamp_x ? (inner_rect_rel.Max.x - pad_x) : +FLT_MAX;
+ inner_rect_rel.Min.y = clamp_y ? (inner_rect_rel.Min.y + pad_y) : -FLT_MAX;
+ inner_rect_rel.Max.y = clamp_y ? (inner_rect_rel.Max.y - pad_y) : +FLT_MAX;
+ window->NavRectRel[g.NavLayer].ClipWithFull(inner_rect_rel);
g.NavId = g.NavFocusScopeId = 0;
}
}
@@ -10526,7 +11017,7 @@ void ImGui::NavUpdateCreateTabbingRequest()
if (window == NULL || g.NavWindowingTarget != NULL || (window->Flags & ImGuiWindowFlags_NoNavInputs))
return;
- const bool tab_pressed = IsKeyPressedMap(ImGuiKey_Tab, true) && !IsActiveIdUsingKey(ImGuiKey_Tab) && !g.IO.KeyCtrl && !g.IO.KeyAlt;
+ const bool tab_pressed = IsKeyPressed(ImGuiKey_Tab, true) && !IsActiveIdUsingKey(ImGuiKey_Tab) && !g.IO.KeyCtrl && !g.IO.KeyAlt;
if (!tab_pressed)
return;
@@ -10687,16 +11178,14 @@ static void ImGui::NavUpdateCancelRequest()
static float ImGui::NavUpdatePageUpPageDown()
{
ImGuiContext& g = *GImGui;
- ImGuiIO& io = g.IO;
-
ImGuiWindow* window = g.NavWindow;
if ((window->Flags & ImGuiWindowFlags_NoNavInputs) || g.NavWindowingTarget != NULL)
return 0.0f;
- const bool page_up_held = IsKeyDown(io.KeyMap[ImGuiKey_PageUp]) && !IsActiveIdUsingKey(ImGuiKey_PageUp);
- const bool page_down_held = IsKeyDown(io.KeyMap[ImGuiKey_PageDown]) && !IsActiveIdUsingKey(ImGuiKey_PageDown);
- const bool home_pressed = IsKeyPressed(io.KeyMap[ImGuiKey_Home]) && !IsActiveIdUsingKey(ImGuiKey_Home);
- const bool end_pressed = IsKeyPressed(io.KeyMap[ImGuiKey_End]) && !IsActiveIdUsingKey(ImGuiKey_End);
+ const bool page_up_held = IsKeyDown(ImGuiKey_PageUp) && !IsActiveIdUsingKey(ImGuiKey_PageUp);
+ const bool page_down_held = IsKeyDown(ImGuiKey_PageDown) && !IsActiveIdUsingKey(ImGuiKey_PageDown);
+ const bool home_pressed = IsKeyPressed(ImGuiKey_Home) && !IsActiveIdUsingKey(ImGuiKey_Home);
+ const bool end_pressed = IsKeyPressed(ImGuiKey_End) && !IsActiveIdUsingKey(ImGuiKey_End);
if (page_up_held == page_down_held && home_pressed == end_pressed) // Proceed if either (not both) are pressed, otherwise early out
return 0.0f;
@@ -10706,9 +11195,9 @@ static float ImGui::NavUpdatePageUpPageDown()
if (window->DC.NavLayersActiveMask == 0x00 && window->DC.NavHasScroll)
{
// Fallback manual-scroll when window has no navigable item
- if (IsKeyPressed(io.KeyMap[ImGuiKey_PageUp], true))
+ if (IsKeyPressed(ImGuiKey_PageUp, true))
SetScrollY(window, window->Scroll.y - window->InnerRect.GetHeight());
- else if (IsKeyPressed(io.KeyMap[ImGuiKey_PageDown], true))
+ else if (IsKeyPressed(ImGuiKey_PageDown, true))
SetScrollY(window, window->Scroll.y + window->InnerRect.GetHeight());
else if (home_pressed)
SetScrollY(window, 0.0f);
@@ -10718,16 +11207,16 @@ static float ImGui::NavUpdatePageUpPageDown()
else
{
ImRect& nav_rect_rel = window->NavRectRel[g.NavLayer];
- const float page_offset_y = ImMax(0.0f, window->InnerRect.GetHeight() - window->CalcFontHeight() * 1.0f + nav_rect_rel.GetHeight());
+ const float page_offset_y = ImMax(0.0f, window->InnerRect.GetHeight() - window->CalcFontSize() * 1.0f + nav_rect_rel.GetHeight());
float nav_scoring_rect_offset_y = 0.0f;
- if (IsKeyPressed(io.KeyMap[ImGuiKey_PageUp], true))
+ if (IsKeyPressed(ImGuiKey_PageUp, true))
{
nav_scoring_rect_offset_y = -page_offset_y;
g.NavMoveDir = ImGuiDir_Down; // Because our scoring rect is offset up, we request the down direction (so we can always land on the last item)
g.NavMoveClipDir = ImGuiDir_Up;
g.NavMoveFlags = ImGuiNavMoveFlags_AllowCurrentNavId | ImGuiNavMoveFlags_AlsoScoreVisibleSet;
}
- else if (IsKeyPressed(io.KeyMap[ImGuiKey_PageDown], true))
+ else if (IsKeyPressed(ImGuiKey_PageDown, true))
{
nav_scoring_rect_offset_y = +page_offset_y;
g.NavMoveDir = ImGuiDir_Up; // Because our scoring rect is offset down, we request the up direction (so we can always land on the last item)
@@ -10892,7 +11381,7 @@ static void ImGui::NavUpdateWindowing()
// Start CTRL+Tab or Square+L/R window selection
const bool start_windowing_with_gamepad = allow_windowing && !g.NavWindowingTarget && IsNavInputTest(ImGuiNavInput_Menu, ImGuiInputReadMode_Pressed);
- const bool start_windowing_with_keyboard = allow_windowing && !g.NavWindowingTarget && io.KeyCtrl && IsKeyPressedMap(ImGuiKey_Tab);
+ const bool start_windowing_with_keyboard = allow_windowing && !g.NavWindowingTarget && io.KeyCtrl && IsKeyPressed(ImGuiKey_Tab);
if (start_windowing_with_gamepad || start_windowing_with_keyboard)
if (ImGuiWindow* window = g.NavWindow ? g.NavWindow : FindWindowNavFocusable(g.WindowsFocusOrder.Size - 1, -INT_MAX, -1))
{
@@ -10934,7 +11423,7 @@ static void ImGui::NavUpdateWindowing()
{
// Visuals only appears after a brief time after pressing TAB the first time, so that a fast CTRL+TAB doesn't add visual noise
g.NavWindowingHighlightAlpha = ImMax(g.NavWindowingHighlightAlpha, ImSaturate((g.NavWindowingTimer - NAV_WINDOWING_HIGHLIGHT_DELAY) / 0.05f)); // 1.0f
- if (IsKeyPressedMap(ImGuiKey_Tab, true))
+ if (IsKeyPressed(ImGuiKey_Tab, true))
NavUpdateWindowingHighlightWindow(io.KeyShift ? +1 : -1);
if (!io.KeyCtrl)
apply_focus_window = g.NavWindowingTarget;
@@ -11284,6 +11773,7 @@ bool ImGui::SetDragDropPayload(const char* type, const void* data, size_t data_s
}
payload.DataFrameCount = g.FrameCount;
+ // Return whether the payload has been accepted
return (g.DragDropAcceptFrameCount == g.FrameCount) || (g.DragDropAcceptFrameCount == g.FrameCount - 1);
}
@@ -11971,6 +12461,7 @@ static void WindowSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandl
buf->appendf("Collapsed=%d\n", settings->Collapsed);
if (settings->DockId != 0)
{
+ //buf->appendf("TabId=0x%08X\n", ImHashStr("#TAB", 4, settings->ID)); // window->TabId: this is not read back but writing it makes "debugging" the .ini data easier.
if (settings->DockOrder == -1)
buf->appendf("DockId=0x%08X\n", settings->DockId);
else
@@ -12162,7 +12653,7 @@ void ImGui::ScaleWindowsInViewport(ImGuiViewportP* viewport, float scale)
// If the backend doesn't set MouseLastHoveredViewport or doesn't honor ImGuiViewportFlags_NoInputs, we do a search ourselves.
// A) It won't take account of the possibility that non-imgui windows may be in-between our dragged window and our target window.
// B) It requires Platform_GetWindowFocus to be implemented by backend.
-static ImGuiViewportP* FindHoveredViewportFromPlatformWindowStack(const ImVec2 mouse_platform_pos)
+ImGuiViewportP* ImGui::FindHoveredViewportFromPlatformWindowStack(const ImVec2& mouse_platform_pos)
{
ImGuiContext& g = *GImGui;
ImGuiViewportP* best_candidate = NULL;
@@ -12314,17 +12805,14 @@ static void ImGui::UpdateViewportsNewFrame()
{
viewport_hovered = g.IO.MouseHoveredViewport ? (ImGuiViewportP*)FindViewportByID(g.IO.MouseHoveredViewport) : NULL;
if (viewport_hovered && (viewport_hovered->Flags & ImGuiViewportFlags_NoInputs))
- {
- // Backend failed at honoring its contract if it returned a viewport with the _NoInputs flag.
- IM_ASSERT(0);
- viewport_hovered = FindHoveredViewportFromPlatformWindowStack(g.IO.MousePos);
- }
+ viewport_hovered = FindHoveredViewportFromPlatformWindowStack(g.IO.MousePos); // Backend failed to handle _NoInputs viewport: revert to our fallback.
}
else
{
// If the backend doesn't know how to honor ImGuiViewportFlags_NoInputs, we do a search ourselves. Note that this search:
// A) won't take account of the possibility that non-imgui windows may be in-between our dragged window and our target window.
- // B) uses LastFrameAsRefViewport as a flawed replacement for the last time a window was focused (we could/should fix that by introducing Focus functions in PlatformIO)
+ // B) won't take account of how the backend apply parent<>child relationship to secondary viewports, which affects their Z order.
+ // C) uses LastFrameAsRefViewport as a flawed replacement for the last time a window was focused (we could/should fix that by introducing Focus functions in PlatformIO)
viewport_hovered = FindHoveredViewportFromPlatformWindowStack(g.IO.MousePos);
}
if (viewport_hovered != NULL)
@@ -12538,7 +13026,8 @@ static void ImGui::WindowSelectViewport(ImGuiWindow* window)
{
// Merge into host viewport?
// We cannot test window->ViewportOwned as it set lower in the function.
- bool try_to_merge_into_host_viewport = (window->Viewport && window == window->Viewport->Window && g.ActiveId == 0);
+ // Testing (g.ActiveId == 0 || g.ActiveIdAllowOverlap) to avoid merging during a short-term widget interaction. Main intent was to avoid during resize (see #4212)
+ bool try_to_merge_into_host_viewport = (window->Viewport && window == window->Viewport->Window && (g.ActiveId == 0 || g.ActiveIdAllowOverlap));
if (try_to_merge_into_host_viewport)
UpdateTryMergeWindowIntoHostViewports(window);
}
@@ -13580,7 +14069,7 @@ void ImGui::DockContextProcessDock(ImGuiContext* ctx, ImGuiDockRequest* req)
if (payload_node && payload_node->IsLeafNode())
next_selected_id = payload_node->TabBar->NextSelectedTabId ? payload_node->TabBar->NextSelectedTabId : payload_node->TabBar->SelectedTabId;
if (payload_node == NULL)
- next_selected_id = payload_window->ID;
+ next_selected_id = payload_window->TabId;
}
// FIXME-DOCK: When we are trying to dock an existing single-window node into a loose window, transfer Node ID as well
@@ -13857,7 +14346,7 @@ int ImGui::DockNodeGetTabOrder(ImGuiWindow* window)
ImGuiTabBar* tab_bar = window->DockNode->TabBar;
if (tab_bar == NULL)
return -1;
- ImGuiTabItem* tab = TabBarFindTabByID(tab_bar, window->ID);
+ ImGuiTabItem* tab = TabBarFindTabByID(tab_bar, window->TabId);
return tab ? tab_bar->GetTabOrder(tab) : -1;
}
@@ -13961,7 +14450,7 @@ static void ImGui::DockNodeRemoveWindow(ImGuiDockNode* node, ImGuiWindow* window
node->WantHiddenTabBarUpdate = true;
if (node->TabBar)
{
- TabBarRemoveTab(node->TabBar, window->ID);
+ TabBarRemoveTab(node->TabBar, window->TabId);
const int tab_count_threshold_for_tab_bar = node->IsCentralNode() ? 1 : 2;
if (node->Windows.Size < tab_count_threshold_for_tab_bar)
DockNodeRemoveTabBar(node);
@@ -14144,7 +14633,7 @@ static void ImGui::DockNodeUpdateFlagsAndCollapse(ImGuiDockNode* node)
bool node_was_active = (node->LastFrameActive + 1 == g.FrameCount);
bool remove = false;
remove |= node_was_active && (window->LastFrameActive + 1 < g.FrameCount);
- remove |= node_was_active && (node->WantCloseAll || node->WantCloseTabId == window->ID) && window->HasCloseButton && !(window->Flags & ImGuiWindowFlags_UnsavedDocument); // Submit all _expected_ closure from last frame
+ remove |= node_was_active && (node->WantCloseAll || node->WantCloseTabId == window->TabId) && window->HasCloseButton && !(window->Flags & ImGuiWindowFlags_UnsavedDocument); // Submit all _expected_ closure from last frame
remove |= (window->DockTabWantClose);
if (remove)
{
@@ -14490,7 +14979,8 @@ static void ImGui::DockNodeUpdate(ImGuiDockNode* node)
if (central_node_hole && !hole_rect.IsInverted())
{
SetWindowHitTestHole(host_window, hole_rect.Min, hole_rect.Max - hole_rect.Min);
- SetWindowHitTestHole(host_window->ParentWindow, hole_rect.Min, hole_rect.Max - hole_rect.Min);
+ if (host_window->ParentWindow)
+ SetWindowHitTestHole(host_window->ParentWindow, hole_rect.Min, hole_rect.Max - hole_rect.Min);
}
}
@@ -14676,7 +15166,7 @@ static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_w
if (is_focused || root_node->VisibleWindow == NULL)
root_node->VisibleWindow = node->VisibleWindow;
if (node->TabBar)
- node->TabBar->VisibleTabId = node->VisibleWindow->ID;
+ node->TabBar->VisibleTabId = node->VisibleWindow->TabId;
}
return;
}
@@ -14727,7 +15217,7 @@ static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_w
for (int window_n = 0; window_n < node->Windows.Size; window_n++)
{
ImGuiWindow* window = node->Windows[window_n];
- if (TabBarFindTabByID(tab_bar, window->ID) == NULL)
+ if (TabBarFindTabByID(tab_bar, window->TabId) == NULL)
TabBarAddTab(tab_bar, ImGuiTabItemFlags_Unsorted, window);
}
@@ -14772,7 +15262,7 @@ static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_w
if (tab_bar_is_recreated && TabBarFindTabByID(tab_bar, node->SelectedTabId) != NULL)
tab_bar->SelectedTabId = tab_bar->NextSelectedTabId = node->SelectedTabId;
else if (tab_bar->Tabs.Size > tabs_count_old)
- tab_bar->SelectedTabId = tab_bar->NextSelectedTabId = tab_bar->Tabs.back().Window->ID;
+ tab_bar->SelectedTabId = tab_bar->NextSelectedTabId = tab_bar->Tabs.back().Window->TabId;
// Begin tab bar
ImGuiTabBarFlags tab_bar_flags = ImGuiTabBarFlags_Reorderable | ImGuiTabBarFlags_AutoSelectNewTabs; // | ImGuiTabBarFlags_NoTabListScrollingButtons);
@@ -14792,7 +15282,7 @@ static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_w
for (int window_n = 0; window_n < node->Windows.Size; window_n++)
{
ImGuiWindow* window = node->Windows[window_n];
- if ((closed_all || closed_one == window->ID) && window->HasCloseButton && !(window->Flags & ImGuiWindowFlags_UnsavedDocument))
+ if ((closed_all || closed_one == window->TabId) && window->HasCloseButton && !(window->Flags & ImGuiWindowFlags_UnsavedDocument))
continue;
if (window->LastFrameActive + 1 >= g.FrameCount || !node_was_active)
{
@@ -14807,11 +15297,12 @@ static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_w
for (int color_n = 0; color_n < ImGuiWindowDockStyleCol_COUNT; color_n++)
g.Style.Colors[GWindowDockStyleColors[color_n]] = ColorConvertU32ToFloat4(window->DockStyle.Colors[color_n]);
+ // Note that TabItemEx() calls TabBarCalcTabID() so our tab item ID will ignore the current ID stack (rightly so)
bool tab_open = true;
TabItemEx(tab_bar, window->Name, window->HasCloseButton ? &tab_open : NULL, tab_item_flags, window);
if (!tab_open)
- node->WantCloseTabId = window->ID;
- if (tab_bar->VisibleTabId == window->ID)
+ node->WantCloseTabId = window->TabId;
+ if (tab_bar->VisibleTabId == window->TabId)
node->VisibleWindow = window;
// Store last item data so it can be queried with IsItemXXX functions after the user Begin() call
@@ -14820,7 +15311,7 @@ static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_w
// Update navigation ID on menu layer
if (g.NavWindow && g.NavWindow->RootWindow == window && (window->DC.NavLayersActiveMask & (1 << ImGuiNavLayer_Menu)) == 0)
- host_window->NavLastIds[1] = window->ID;
+ host_window->NavLastIds[1] = window->TabId;
}
}
@@ -14834,7 +15325,7 @@ static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_w
root_node->VisibleWindow = node->VisibleWindow;
// Close button (after VisibleWindow was updated)
- // Note that VisibleWindow may have been overrided by CTRL+Tabbing, so VisibleWindow->ID may be != from tab_bar->SelectedTabId
+ // Note that VisibleWindow may have been overrided by CTRL+Tabbing, so VisibleWindow->TabId may be != from tab_bar->SelectedTabId
const bool close_button_is_enabled = node->HasCloseButton && node->VisibleWindow && node->VisibleWindow->HasCloseButton;
const bool close_button_is_visible = node->HasCloseButton;
//const bool close_button_is_visible = close_button_is_enabled; // Most people would expect this behavior of not even showing the button (leaving a hole since we can't claim that space as other windows in the tba bar have one)
@@ -16448,7 +16939,7 @@ void ImGui::BeginDocked(ImGuiWindow* window, bool* p_open)
if (node->TabBar && window->WasActive)
window->DockOrder = (short)DockNodeGetTabOrder(window);
- if ((node->WantCloseAll || node->WantCloseTabId == window->ID) && p_open != NULL)
+ if ((node->WantCloseAll || node->WantCloseTabId == window->TabId) && p_open != NULL)
*p_open = false;
// Update ChildId to allow returning from Child to Parent with Escape
@@ -16914,6 +17405,49 @@ static void SetClipboardTextFn_DefaultImpl(void*, const char* text)
#endif
+// Win32 API IME support (for Asian languages, etc.)
+#if defined(_WIN32) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS) && !defined(IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS)
+
+#include <imm.h>
+#ifdef _MSC_VER
+#pragma comment(lib, "imm32")
+#endif
+
+static void SetPlatformImeDataFn_DefaultImpl(ImGuiViewport* viewport, ImGuiPlatformImeData* data)
+{
+ // Notify OS Input Method Editor of text input position
+ HWND hwnd = (HWND)viewport->PlatformHandleRaw;
+#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
+ if (hwnd == 0)
+ hwnd = (HWND)ImGui::GetIO().ImeWindowHandle;
+#endif
+ if (hwnd == 0)
+ return;
+
+ ::ImmAssociateContextEx(hwnd, NULL, data->WantVisible ? IACE_DEFAULT : 0);
+
+ if (HIMC himc = ::ImmGetContext(hwnd))
+ {
+ COMPOSITIONFORM composition_form = {};
+ composition_form.ptCurrentPos.x = (LONG)(data->InputPos.x - viewport->Pos.x);
+ composition_form.ptCurrentPos.y = (LONG)(data->InputPos.y - viewport->Pos.y);
+ composition_form.dwStyle = CFS_FORCE_POSITION;
+ ::ImmSetCompositionWindow(himc, &composition_form);
+ CANDIDATEFORM candidate_form = {};
+ candidate_form.dwStyle = CFS_CANDIDATEPOS;
+ candidate_form.ptCurrentPos.x = (LONG)(data->InputPos.x - viewport->Pos.x);
+ candidate_form.ptCurrentPos.y = (LONG)(data->InputPos.y - viewport->Pos.y);
+ ::ImmSetCandidateWindow(himc, &candidate_form);
+ ::ImmReleaseContext(hwnd, himc);
+ }
+}
+
+#else
+
+static void SetPlatformImeDataFn_DefaultImpl(ImGuiViewport*, ImGuiPlatformImeData*) {}
+
+#endif
+
//-----------------------------------------------------------------------------
// [SECTION] METRICS/DEBUGGER WINDOW
//-----------------------------------------------------------------------------
@@ -16963,7 +17497,7 @@ void ImGui::DebugRenderViewportThumbnail(ImDrawList* draw_list, ImGuiViewportP*
window->DrawList->AddRectFilled(thumb_r.Min, thumb_r.Max, GetColorU32(ImGuiCol_WindowBg, alpha_mul));
window->DrawList->AddRectFilled(title_r.Min, title_r.Max, GetColorU32(window_is_focused ? ImGuiCol_TitleBgActive : ImGuiCol_TitleBg, alpha_mul));
window->DrawList->AddRect(thumb_r.Min, thumb_r.Max, GetColorU32(ImGuiCol_Border, alpha_mul));
- window->DrawList->AddText(g.Font, g.FontSize, g.FontLineHeight, g.FontBaselineOffset, title_r.Min, GetColorU32(ImGuiCol_Text, alpha_mul), thumb_window->Name, FindRenderedTextEnd(thumb_window->Name));
+ window->DrawList->AddText(g.Font, g.FontSize * 1.0f, title_r.Min, GetColorU32(ImGuiCol_Text, alpha_mul), thumb_window->Name, FindRenderedTextEnd(thumb_window->Name));
}
draw_list->AddRect(bb.Min, bb.Max, GetColorU32(ImGuiCol_Border, alpha_mul));
}
@@ -17232,7 +17766,8 @@ void ImGui::ShowMetricsWindow(bool* p_open)
TreePop();
}
- if (TreeNode("Inferred order (front-to-back)"))
+ BulletText("MouseViewport: 0x%08X (UserHovered 0x%08X, LastHovered 0x%08X)", g.MouseViewport ? g.MouseViewport->ID : 0, g.IO.MouseHoveredViewport, g.MouseLastHoveredViewport ? g.MouseLastHoveredViewport->ID : 0);
+ if (TreeNode("Inferred Z order (front-to-back)"))
{
static ImVector<ImGuiViewportP*> viewports;
viewports.resize(g.Viewports.Size);
@@ -17385,8 +17920,6 @@ void ImGui::ShowMetricsWindow(bool* p_open)
// Misc Details
if (TreeNode("Internal state"))
{
- const char* input_source_names[] = { "None", "Mouse", "Keyboard", "Gamepad", "Nav", "Clipboard" }; IM_ASSERT(IM_ARRAYSIZE(input_source_names) == ImGuiInputSource_COUNT);
-
Text("WINDOWING");
Indent();
Text("HoveredWindow: '%s'", g.HoveredWindow ? g.HoveredWindow->Name : "NULL");
@@ -17399,9 +17932,13 @@ void ImGui::ShowMetricsWindow(bool* p_open)
Text("ITEMS");
Indent();
- Text("ActiveId: 0x%08X/0x%08X (%.2f sec), AllowOverlap: %d, Source: %s", g.ActiveId, g.ActiveIdPreviousFrame, g.ActiveIdTimer, g.ActiveIdAllowOverlap, input_source_names[g.ActiveIdSource]);
+ Text("ActiveId: 0x%08X/0x%08X (%.2f sec), AllowOverlap: %d, Source: %s", g.ActiveId, g.ActiveIdPreviousFrame, g.ActiveIdTimer, g.ActiveIdAllowOverlap, GetInputSourceName(g.ActiveIdSource));
Text("ActiveIdWindow: '%s'", g.ActiveIdWindow ? g.ActiveIdWindow->Name : "NULL");
- Text("ActiveIdUsing: Wheel: %d, NavDirMask: %X, NavInputMask: %X, KeyInputMask: %llX", g.ActiveIdUsingMouseWheel, g.ActiveIdUsingNavDirMask, g.ActiveIdUsingNavInputMask, g.ActiveIdUsingKeyInputMask);
+
+ int active_id_using_key_input_count = 0;
+ for (int n = 0; n < ImGuiKey_NamedKey_COUNT; n++)
+ active_id_using_key_input_count += g.ActiveIdUsingKeyInputMask[n] ? 1 : 0;
+ Text("ActiveIdUsing: Wheel: %d, NavDirMask: %X, NavInputMask: %X, KeyInputMask: %d key(s)", g.ActiveIdUsingMouseWheel, g.ActiveIdUsingNavDirMask, g.ActiveIdUsingNavInputMask, active_id_using_key_input_count);
Text("HoveredId: 0x%08X (%.2f sec), AllowOverlap: %d", g.HoveredIdPreviousFrame, g.HoveredIdTimer, g.HoveredIdAllowOverlap); // Not displaying g.HoveredId as it is update mid-frame
Text("DragDrop: %d, SourceId = 0x%08X, Payload \"%s\" (%d bytes)", g.DragDropActive, g.DragDropPayload.SourceId, g.DragDropPayload.DataType, g.DragDropPayload.DataSize);
Unindent();
@@ -17410,7 +17947,7 @@ void ImGui::ShowMetricsWindow(bool* p_open)
Indent();
Text("NavWindow: '%s'", g.NavWindow ? g.NavWindow->Name : "NULL");
Text("NavId: 0x%08X, NavLayer: %d", g.NavId, g.NavLayer);
- Text("NavInputSource: %s", input_source_names[g.NavInputSource]);
+ Text("NavInputSource: %s", GetInputSourceName(g.NavInputSource));
Text("NavActive: %d, NavVisible: %d", g.IO.NavActive, g.IO.NavVisible);
Text("NavActivateId/DownId/PressedId/InputId: %08X/%08X/%08X/%08X", g.NavActivateId, g.NavActivateDownId, g.NavActivatePressedId, g.NavActivateInputId);
Text("NavActivateFlags: %04X", g.NavActivateFlags);
@@ -17760,12 +18297,7 @@ void ImGui::DebugNodeFont(ImFont* font)
"You may oversample them to get some flexibility with scaling. "
"You can also render at multiple sizes and select which one to use at runtime.\n\n"
"(Glimmer of hope: the atlas system will be rewritten in the future to make scaling more flexible.)");
- SetNextItemWidth(GetFontSize() * 8);
- DragFloat("Extra line height", &font->ExtraLineHeight, 1.0f, -font->FontSize, FLT_MAX, "%g");
- SetNextItemWidth(GetFontSize() * 8);
- DragFloat("Baseline offset", &font->BaselineOffset, 0.1f, -FLT_MAX, FLT_MAX, "%g");
Text("Ascent: %f, Descent: %f, Height: %f", font->Ascent, font->Descent, font->Ascent - font->Descent);
- Text("Line Height: %f", font->FontSize + font->ExtraLineHeight);
char c_str[5];
Text("Fallback character: '%s' (U+%04X)", ImTextCharToUtf8(c_str, font->FallbackChar), font->FallbackChar);
Text("Ellipsis character: '%s' (U+%04X)", ImTextCharToUtf8(c_str, font->EllipsisChar), font->EllipsisChar);
@@ -17815,7 +18347,7 @@ void ImGui::DebugNodeFont(ImFont* font)
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_size, cell_p1, glyph_col, (ImWchar)(base + n));
+ font->RenderChar(draw_list, cell_size, cell_p1, glyph_col, (ImWchar)(base + n));
if (glyph && IsMouseHoveringRect(cell_p1, cell_p2))
{
BeginTooltip();
@@ -18042,7 +18574,7 @@ void ImGui::UpdateDebugToolItemPicker()
const ImGuiID hovered_id = g.HoveredIdPreviousFrame;
SetMouseCursor(ImGuiMouseCursor_Hand);
- if (IsKeyPressedMap(ImGuiKey_Escape))
+ if (IsKeyPressed(ImGuiKey_Escape))
g.DebugItemPickerActive = false;
if (IsMouseClicked(0) && hovered_id)
{