mirror of
https://github.com/ocornut/imgui.git
synced 2026-01-09 23:03:12 +00:00
Merge branch 'master' into docking
This commit is contained in:
65
imgui.cpp
65
imgui.cpp
@@ -439,6 +439,7 @@ CODE
|
||||
If you query mouse positions to interact with non-imgui coordinates you will need to offset them, e.g. subtract GetWindowViewport()->Pos.
|
||||
|
||||
- 2024/05/22 (1.90.7) - inputs (internals): renamed ImGuiKeyOwner_None to ImGuiKeyOwner_NoOwner, to make use more explicit and reduce confusion with the default it is a non-zero value and cannot be the default value (never made public, but disclosing as I expect a few users caught on owner-aware inputs).
|
||||
- inputs (internals): renamed ImGuiInputFlags_RouteGlobalLow -> ImGuiInputFlags_RouteGlobal, ImGuiInputFlags_RouteGlobal -> ImGuiInputFlags_RouteGlobalOverFocused, ImGuiInputFlags_RouteGlobalHigh -> ImGuiInputFlags_RouteGlobalHighest.
|
||||
- inputs (internals): Shortcut(), SetShortcutRouting(): swapped last two parameters order in function signatures:
|
||||
- old: Shortcut(ImGuiKeyChord key_chord, ImGuiID owner_id = 0, ImGuiInputFlags flags = 0);
|
||||
- new: Shortcut(ImGuiKeyChord key_chord, ImGuiInputFlags flags = 0, ImGuiID owner_id = 0);
|
||||
@@ -6143,10 +6144,18 @@ static ImVec2 CalcWindowAutoFitSize(ImGuiWindow* window, const ImVec2& size_cont
|
||||
size_max = g.PlatformIO.Monitors[monitor_idx].WorkSize - style.DisplaySafeAreaPadding * 2.0f;
|
||||
ImVec2 size_auto_fit = ImClamp(size_desired, size_min, ImMax(size_min, size_max));
|
||||
|
||||
// FIXME: CalcWindowAutoFitSize() doesn't take into account that only one axis may be auto-fit when calculating scrollbars,
|
||||
// we may need to compute/store three variants of size_auto_fit, for x/y/xy.
|
||||
// Here we implement a workaround for child windows only, but a full solution would apply to normal windows as well:
|
||||
if ((window->ChildFlags & ImGuiChildFlags_ResizeX) && !(window->ChildFlags & ImGuiChildFlags_ResizeY))
|
||||
size_auto_fit.y = window->SizeFull.y;
|
||||
else if (!(window->ChildFlags & ImGuiChildFlags_ResizeX) && (window->ChildFlags & ImGuiChildFlags_ResizeY))
|
||||
size_auto_fit.x = window->SizeFull.x;
|
||||
|
||||
// When the window cannot fit all contents (either because of constraints, either because screen is too small),
|
||||
// we are growing the size on the other axis to compensate for expected scrollbar. FIXME: Might turn bigger than ViewportSize-WindowPadding.
|
||||
ImVec2 size_auto_fit_after_constraint = CalcWindowSizeAfterConstraint(window, size_auto_fit);
|
||||
bool will_have_scrollbar_x = (size_auto_fit_after_constraint.x - size_pad.x - decoration_w_without_scrollbars < size_contents.x && !(window->Flags & ImGuiWindowFlags_NoScrollbar) && (window->Flags & ImGuiWindowFlags_HorizontalScrollbar)) || (window->Flags & ImGuiWindowFlags_AlwaysHorizontalScrollbar);
|
||||
bool will_have_scrollbar_x = (size_auto_fit_after_constraint.x - size_pad.x - decoration_w_without_scrollbars < size_contents.x && !(window->Flags & ImGuiWindowFlags_NoScrollbar) && (window->Flags & ImGuiWindowFlags_HorizontalScrollbar)) || (window->Flags & ImGuiWindowFlags_AlwaysHorizontalScrollbar);
|
||||
bool will_have_scrollbar_y = (size_auto_fit_after_constraint.y - size_pad.y - decoration_h_without_scrollbars < size_contents.y && !(window->Flags & ImGuiWindowFlags_NoScrollbar)) || (window->Flags & ImGuiWindowFlags_AlwaysVerticalScrollbar);
|
||||
if (will_have_scrollbar_x)
|
||||
size_auto_fit.y += style.ScrollbarSize;
|
||||
@@ -6358,6 +6367,7 @@ static int ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& si
|
||||
if (held && g.IO.MouseDoubleClicked[0])
|
||||
{
|
||||
// Double-clicking bottom or right border auto-fit on this axis
|
||||
// FIXME: CalcWindowAutoFitSize() doesn't take into account that only one side may be auto-fit when calculating scrollbars.
|
||||
// FIXME: Support top and right borders: rework CalcResizePosSizeFromAnyCorner() to be reusable in both cases.
|
||||
if (border_n == 1 || border_n == 3) // Right and bottom border
|
||||
{
|
||||
@@ -9219,8 +9229,8 @@ ImGuiKeyRoutingData* ImGui::GetShortcutRoutingData(ImGuiKeyChord key_chord)
|
||||
}
|
||||
|
||||
// Current score encoding (lower is highest priority):
|
||||
// - 0: ImGuiInputFlags_RouteGlobalHighest
|
||||
// - 1: ImGuiInputFlags_RouteFocused (if item active)
|
||||
// - 0: ImGuiInputFlags_RouteGlobalOverActive
|
||||
// - 1: ImGuiInputFlags_ActiveItem or ImGuiInputFlags_RouteFocused (if item active)
|
||||
// - 2: ImGuiInputFlags_RouteGlobalOverFocused
|
||||
// - 3+: ImGuiInputFlags_RouteFocused (if window in focus-stack)
|
||||
// - 254: ImGuiInputFlags_RouteGlobal
|
||||
@@ -9228,10 +9238,9 @@ ImGuiKeyRoutingData* ImGui::GetShortcutRoutingData(ImGuiKeyChord key_chord)
|
||||
// 'flags' should include an explicit routing policy
|
||||
static int CalcRoutingScore(ImGuiID focus_scope_id, ImGuiID owner_id, ImGuiInputFlags flags)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
if (flags & ImGuiInputFlags_RouteFocused)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
|
||||
// ActiveID gets top priority
|
||||
// (we don't check g.ActiveIdUsingAllKeys here. Routing is applied but if input ownership is tested later it may discard it)
|
||||
if (owner_id != 0 && g.ActiveId == owner_id)
|
||||
@@ -9252,12 +9261,19 @@ static int CalcRoutingScore(ImGuiID focus_scope_id, ImGuiID owner_id, ImGuiInput
|
||||
|
||||
return 255;
|
||||
}
|
||||
|
||||
// ImGuiInputFlags_RouteGlobalHighest is default, so calls without flags are not conditional
|
||||
if (flags & ImGuiInputFlags_RouteGlobalOverFocused)
|
||||
if (flags & ImGuiInputFlags_RouteActive)
|
||||
{
|
||||
if (owner_id != 0 && g.ActiveId == owner_id)
|
||||
return 1;
|
||||
return 255;
|
||||
}
|
||||
if (flags & ImGuiInputFlags_RouteOverFocused)
|
||||
return 2;
|
||||
if (flags & ImGuiInputFlags_RouteGlobal)
|
||||
return 254;
|
||||
if (flags & ImGuiInputFlags_RouteOverActive)
|
||||
return 0;
|
||||
IM_ASSERT(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -9284,11 +9300,13 @@ static bool IsKeyChordPotentiallyCharInput(ImGuiKeyChord key_chord)
|
||||
// - Routes and key ownership are attributed at the beginning of next frame based on best score and mod state.
|
||||
// (Conceptually this does a "Submit for next frame" + "Test for current frame".
|
||||
// As such, it could be called TrySetXXX or SubmitXXX, or the Submit and Test operations should be separate.)
|
||||
bool ImGui::SetShortcutRouting(ImGuiKeyChord key_chord, ImGuiInputFlags flags, ImGuiID owner_id, ImGuiID focus_scope_id)
|
||||
bool ImGui::SetShortcutRouting(ImGuiKeyChord key_chord, ImGuiInputFlags flags, ImGuiID owner_id)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
IM_ASSERT(ImIsPowerOfTwo(flags & ImGuiInputFlags_RouteTypeMask_)); // Check that only 1 routing flag is used
|
||||
IM_ASSERT(owner_id != ImGuiKeyOwner_Any && owner_id != ImGuiKeyOwner_NoOwner);
|
||||
if (flags & (ImGuiInputFlags_RouteOverFocused | ImGuiInputFlags_RouteOverActive | ImGuiInputFlags_RouteUnlessBgFocused))
|
||||
IM_ASSERT(flags & ImGuiInputFlags_RouteGlobal);
|
||||
|
||||
// Add ImGuiMod_XXXX when a corresponding ImGuiKey_LeftXXX/ImGuiKey_RightXXX is specified.
|
||||
key_chord = FixupKeyChord(key_chord);
|
||||
@@ -9308,7 +9326,7 @@ bool ImGui::SetShortcutRouting(ImGuiKeyChord key_chord, ImGuiInputFlags flags, I
|
||||
return true;
|
||||
}
|
||||
|
||||
// Specific culling when there's an active.
|
||||
// Specific culling when there's an active item.
|
||||
if (g.ActiveId != 0 && g.ActiveId != owner_id)
|
||||
{
|
||||
// Cull shortcuts with no modifiers when it could generate a character.
|
||||
@@ -9322,8 +9340,11 @@ bool ImGui::SetShortcutRouting(ImGuiKeyChord key_chord, ImGuiInputFlags flags, I
|
||||
return false;
|
||||
}
|
||||
|
||||
if (flags & ImGuiInputFlags_RouteActive)
|
||||
return false;
|
||||
|
||||
// ActiveIdUsingAllKeyboardKeys trumps all for ActiveId
|
||||
if ((flags & ImGuiInputFlags_RouteGlobalHighest) == 0 && g.ActiveIdUsingAllKeyboardKeys)
|
||||
if ((flags & ImGuiInputFlags_RouteOverActive) == 0 && g.ActiveIdUsingAllKeyboardKeys)
|
||||
{
|
||||
ImGuiKey key = (ImGuiKey)(key_chord & ~ImGuiMod_Mask_);
|
||||
if (key == ImGuiKey_None)
|
||||
@@ -9333,6 +9354,11 @@ bool ImGui::SetShortcutRouting(ImGuiKeyChord key_chord, ImGuiInputFlags flags, I
|
||||
}
|
||||
}
|
||||
|
||||
// Where do we evaluate route for?
|
||||
ImGuiID focus_scope_id = g.CurrentFocusScopeId;
|
||||
if (flags & ImGuiInputFlags_RouteFromRootWindow)
|
||||
focus_scope_id = g.CurrentWindow->RootWindow->ID; // See PushFocusScope() call in Begin()
|
||||
|
||||
const int score = CalcRoutingScore(focus_scope_id, owner_id, flags);
|
||||
IMGUI_DEBUG_LOG_INPUTROUTING("SetShortcutRouting(%s, flags=%04X, owner_id=0x%08X) -> score %d\n", GetKeyChordName(key_chord), flags, owner_id, score);
|
||||
if (score == 255)
|
||||
@@ -10350,7 +10376,7 @@ bool ImGui::Shortcut(ImGuiKeyChord key_chord, ImGuiInputFlags flags)
|
||||
|
||||
bool ImGui::Shortcut(ImGuiKeyChord key_chord, ImGuiInputFlags flags, ImGuiID owner_id)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
//ImGuiContext& g = *GImGui;
|
||||
//IMGUI_DEBUG_LOG("Shortcut(%s, flags=%X, owner_id=0x%08X)\n", GetKeyChordName(key_chord, g.TempBuffer.Data, g.TempBuffer.Size), flags, owner_id);
|
||||
|
||||
// When using (owner_id == 0/Any): SetShortcutRouting() will use CurrentFocusScopeId and filter with this, so IsKeyPressed() is fine with he 0/Any.
|
||||
@@ -10362,13 +10388,8 @@ bool ImGui::Shortcut(ImGuiKeyChord key_chord, ImGuiInputFlags flags, ImGuiID own
|
||||
if (owner_id == ImGuiKeyOwner_Any || owner_id == ImGuiKeyOwner_NoOwner)
|
||||
owner_id = GetRoutingIdFromOwnerId(owner_id);
|
||||
|
||||
// Where do we evaluate route for?
|
||||
ImGuiID focus_scope_id = g.CurrentFocusScopeId;
|
||||
if (flags & ImGuiInputFlags_RouteFromRootWindow)
|
||||
focus_scope_id = g.CurrentWindow->RootWindow->ID; // See PushFocusScope() call in Begin()
|
||||
|
||||
// Submit route
|
||||
if (!SetShortcutRouting(key_chord, flags, owner_id, focus_scope_id))
|
||||
if (!SetShortcutRouting(key_chord, flags, owner_id))
|
||||
return false;
|
||||
|
||||
// Default repeat behavior for Shortcut()
|
||||
@@ -10378,6 +10399,10 @@ bool ImGui::Shortcut(ImGuiKeyChord key_chord, ImGuiInputFlags flags, ImGuiID own
|
||||
|
||||
if (!IsKeyChordPressed(key_chord, flags, owner_id))
|
||||
return false;
|
||||
|
||||
// Claim mods during the press
|
||||
SetKeyOwnersForKeyChord(key_chord & ImGuiMod_Mask_, owner_id);
|
||||
|
||||
IM_ASSERT((flags & ~ImGuiInputFlags_SupportedByShortcut) == 0); // Passing flags not supported by this function!
|
||||
return true;
|
||||
}
|
||||
@@ -13537,7 +13562,7 @@ static void ImGui::NavUpdateWindowing()
|
||||
g.NavWindowingToggleLayer = start_windowing_with_gamepad ? true : false; // Gamepad starts toggling layer
|
||||
g.NavInputSource = start_windowing_with_keyboard ? ImGuiInputSource_Keyboard : ImGuiInputSource_Gamepad;
|
||||
|
||||
// Manually register ownership of our mods. Using ImGuiInputFlags_RouteGlobalHighest in the Shortcut() calls instead would probably be correct but may have more side-effects.
|
||||
// Manually register ownership of our mods. Using a global route in the Shortcut() calls instead would probably be correct but may have more side-effects.
|
||||
if (keyboard_next_window || keyboard_prev_window)
|
||||
SetKeyOwnersForKeyChord((g.ConfigNavWindowingKeyNext | g.ConfigNavWindowingKeyPrev) & ImGuiMod_Mask_, owner_id);
|
||||
}
|
||||
@@ -21730,7 +21755,7 @@ void ImGui::ShowIDStackToolWindow(bool* p_open)
|
||||
Checkbox("Ctrl+C: copy path to clipboard", &tool->CopyToClipboardOnCtrlC);
|
||||
SameLine();
|
||||
TextColored((time_since_copy >= 0.0f && time_since_copy < 0.75f && ImFmod(time_since_copy, 0.25f) < 0.25f * 0.5f) ? ImVec4(1.f, 1.f, 0.3f, 1.f) : ImVec4(), "*COPIED*");
|
||||
if (tool->CopyToClipboardOnCtrlC && Shortcut(ImGuiMod_Ctrl | ImGuiKey_C, ImGuiInputFlags_RouteGlobalOverFocused))
|
||||
if (tool->CopyToClipboardOnCtrlC && Shortcut(ImGuiMod_Ctrl | ImGuiKey_C, ImGuiInputFlags_RouteGlobal | ImGuiInputFlags_RouteOverFocused))
|
||||
{
|
||||
tool->CopyToClipboardLastTime = (float)g.Time;
|
||||
char* p = g.TempBuffer.Data;
|
||||
|
||||
Reference in New Issue
Block a user