mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-06 04:58:47 +02:00
Merge branch 'master' into docking
# Conflicts: # imgui.cpp # imgui_demo.cpp
This commit is contained in:
114
imgui.cpp
114
imgui.cpp
@ -375,14 +375,15 @@ CODE
|
||||
You can read releases logs https://github.com/ocornut/imgui/releases for more details.
|
||||
|
||||
(Docking/Viewport Branch)
|
||||
- 2019/XX/XX (1.XX) - when multi-viewports are enabled, all positions will be in your natural OS coordinates space. It means that:
|
||||
- 2020/XX/XX (1.XX) - when multi-viewports are enabled, all positions will be in your natural OS coordinates space. It means that:
|
||||
- reference to hard-coded positions such as in SetNextWindowPos(ImVec2(0,0)) are probably not what you want anymore.
|
||||
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.
|
||||
- 2019/XX/XX (1.XX) - Moved IME support functions from io.ImeSetInputScreenPosFn, io.ImeWindowHandle to the PlatformIO api.
|
||||
- 2020/XX/XX (1.XX) - Moved IME support functions from io.ImeSetInputScreenPosFn, io.ImeWindowHandle to the PlatformIO api.
|
||||
|
||||
|
||||
- 2020/06/23 (1.77) - removed BeginPopupContextWindow(const char*, int mouse_button, bool also_over_items) in favor of BeginPopupContextWindow(const char*, ImGuiPopupFlags flags) with ImGuiPopupFlags_NoOverItems.
|
||||
- 2020/06/15 (1.77) - renamed OpenPopupOnItemClick() to OpenPopupContextItem(). Kept inline redirection function (will obsolete).
|
||||
- 2020/06/15 (1.77) - removed CalcItemRectClosestPoint() entry point which was made obsolete and asserting in December 2017.
|
||||
- 2020/04/23 (1.77) - removed unnecessary ID (first arg) of ImFontAtlas::AddCustomRectRegular().
|
||||
@ -3313,11 +3314,21 @@ float ImGui::CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x)
|
||||
if (wrap_pos_x < 0.0f)
|
||||
return 0.0f;
|
||||
|
||||
ImGuiWindow* window = GImGui->CurrentWindow;
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImGuiWindow* window = g.CurrentWindow;
|
||||
if (wrap_pos_x == 0.0f)
|
||||
{
|
||||
// We could decide to setup a default wrapping max point for auto-resizing windows,
|
||||
// or have auto-wrap (with unspecified wrapping pos) behave as a ContentSize extending function?
|
||||
//if (window->Hidden && (window->Flags & ImGuiWindowFlags_AlwaysAutoResize))
|
||||
// wrap_pos_x = ImMax(window->WorkRect.Min.x + g.FontSize * 10.0f, window->WorkRect.Max.x);
|
||||
//else
|
||||
wrap_pos_x = window->WorkRect.Max.x;
|
||||
}
|
||||
else if (wrap_pos_x > 0.0f)
|
||||
{
|
||||
wrap_pos_x += window->Pos.x - window->Scroll.x; // wrap_pos_x is provided is window local space
|
||||
}
|
||||
|
||||
return ImMax(wrap_pos_x - pos.x, 1.0f);
|
||||
}
|
||||
@ -3608,7 +3619,7 @@ void ImGui::UpdateMouseMovingWindowEndFrame()
|
||||
// Handle the edge case of a popup being closed while clicking in its empty space.
|
||||
// If we try to focus it, FocusWindow() > ClosePopupsOverWindow() will accidentally close any parent popups because they are not linked together any more.
|
||||
ImGuiWindow* root_window = g.HoveredWindow ? g.HoveredWindow->RootWindowDockStop : NULL;
|
||||
const bool is_closed_popup = root_window && (root_window->Flags & ImGuiWindowFlags_Popup) && !IsPopupOpenAtAnyLevel(root_window->PopupId);
|
||||
const bool is_closed_popup = root_window && (root_window->Flags & ImGuiWindowFlags_Popup) && !IsPopupOpen(root_window->PopupId, ImGuiPopupFlags_AnyPopupLevel);
|
||||
|
||||
if (root_window != NULL && !is_closed_popup)
|
||||
{
|
||||
@ -8357,35 +8368,45 @@ void ImGui::SetTooltip(const char* fmt, ...)
|
||||
// [SECTION] POPUPS
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Return true if the popup is open at the current BeginPopup() level of the popup stack
|
||||
bool ImGui::IsPopupOpen(ImGuiID id)
|
||||
// Supported flags: ImGuiPopupFlags_AnyPopupId, ImGuiPopupFlags_AnyPopupLevel
|
||||
bool ImGui::IsPopupOpen(ImGuiID id, ImGuiPopupFlags popup_flags)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
return g.OpenPopupStack.Size > g.BeginPopupStack.Size && g.OpenPopupStack[g.BeginPopupStack.Size].PopupId == id;
|
||||
if (popup_flags & ImGuiPopupFlags_AnyPopupId)
|
||||
{
|
||||
// Return true if any popup is open at the current BeginPopup() level of the popup stack
|
||||
// This may be used to e.g. test for another popups already opened to handle popups priorities at the same level.
|
||||
IM_ASSERT(id == 0);
|
||||
if (popup_flags & ImGuiPopupFlags_AnyPopupLevel)
|
||||
return g.OpenPopupStack.Size > 0;
|
||||
else
|
||||
return g.OpenPopupStack.Size > g.BeginPopupStack.Size;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (popup_flags & ImGuiPopupFlags_AnyPopupLevel)
|
||||
{
|
||||
// Return true if the popup is open anywhere in the popup stack
|
||||
for (int n = 0; n < g.OpenPopupStack.Size; n++)
|
||||
if (g.OpenPopupStack[n].PopupId == id)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Return true if the popup is open at the current BeginPopup() level of the popup stack (this is the most-common query)
|
||||
return g.OpenPopupStack.Size > g.BeginPopupStack.Size && g.OpenPopupStack[g.BeginPopupStack.Size].PopupId == id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Return true if the popup is open at the current BeginPopup() level of the popup stack
|
||||
bool ImGui::IsPopupOpen(const char* str_id)
|
||||
bool ImGui::IsPopupOpen(const char* str_id, ImGuiPopupFlags popup_flags)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
return g.OpenPopupStack.Size > g.BeginPopupStack.Size && g.OpenPopupStack[g.BeginPopupStack.Size].PopupId == g.CurrentWindow->GetID(str_id);
|
||||
}
|
||||
|
||||
bool ImGui::IsPopupOpenAtAnyLevel(ImGuiID id)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
for (int n = 0; n < g.OpenPopupStack.Size; n++)
|
||||
if (g.OpenPopupStack[n].PopupId == id)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Return true if any popup is open at the current BeginPopup() level of the popup stack
|
||||
// This may be used to e.g. test for another popups already opened in the same frame to handle popups priorities at the same level.
|
||||
bool ImGui::IsAnyPopupOpen()
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
return g.OpenPopupStack.Size > g.BeginPopupStack.Size;
|
||||
ImGuiID id = (popup_flags & ImGuiPopupFlags_AnyPopupId) ? 0 : g.CurrentWindow->GetID(str_id);
|
||||
if ((popup_flags & ImGuiPopupFlags_AnyPopupLevel) && id != 0)
|
||||
IM_ASSERT(0 && "Cannot use IsPopupOpen() with a string id and ImGuiPopupFlags_AnyPopupLevel."); // But non-string version is legal and used internally
|
||||
return IsPopupOpen(id, popup_flags);
|
||||
}
|
||||
|
||||
ImGuiWindow* ImGui::GetTopMostPopupModal()
|
||||
@ -8398,21 +8419,26 @@ ImGuiWindow* ImGui::GetTopMostPopupModal()
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void ImGui::OpenPopup(const char* str_id)
|
||||
void ImGui::OpenPopup(const char* str_id, ImGuiPopupFlags popup_flags)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
OpenPopupEx(g.CurrentWindow->GetID(str_id));
|
||||
OpenPopupEx(g.CurrentWindow->GetID(str_id), popup_flags);
|
||||
}
|
||||
|
||||
// Mark popup as open (toggle toward open state).
|
||||
// Popups are closed when user click outside, or activate a pressable item, or CloseCurrentPopup() is called within a BeginPopup()/EndPopup() block.
|
||||
// Popup identifiers are relative to the current ID-stack (so OpenPopup and BeginPopup needs to be at the same level).
|
||||
// One open popup per level of the popup hierarchy (NB: when assigning we reset the Window member of ImGuiPopupRef to NULL)
|
||||
void ImGui::OpenPopupEx(ImGuiID id)
|
||||
void ImGui::OpenPopupEx(ImGuiID id, ImGuiPopupFlags popup_flags)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImGuiWindow* parent_window = g.CurrentWindow;
|
||||
int current_stack_size = g.BeginPopupStack.Size;
|
||||
const int current_stack_size = g.BeginPopupStack.Size;
|
||||
|
||||
if (popup_flags & ImGuiPopupFlags_NoOpenOverExistingPopup)
|
||||
if (IsPopupOpen(0u, ImGuiPopupFlags_AnyPopupId))
|
||||
return;
|
||||
|
||||
ImGuiPopupData popup_ref; // Tagged as new ref as Window will be set back to NULL if we write this into OpenPopupStack.
|
||||
popup_ref.PopupId = id;
|
||||
popup_ref.Window = NULL;
|
||||
@ -8550,7 +8576,7 @@ void ImGui::CloseCurrentPopup()
|
||||
bool ImGui::BeginPopupEx(ImGuiID id, ImGuiWindowFlags flags)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
if (!IsPopupOpen(id))
|
||||
if (!IsPopupOpen(id, ImGuiPopupFlags_None))
|
||||
{
|
||||
g.NextWindowData.ClearFlags(); // We behave like Begin() and need to consume those values
|
||||
return false;
|
||||
@ -8589,7 +8615,7 @@ bool ImGui::BeginPopupModal(const char* name, bool* p_open, ImGuiWindowFlags fla
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImGuiWindow* window = g.CurrentWindow;
|
||||
const ImGuiID id = window->GetID(name);
|
||||
if (!IsPopupOpen(id))
|
||||
if (!IsPopupOpen(id, ImGuiPopupFlags_None))
|
||||
{
|
||||
g.NextWindowData.ClearFlags(); // We behave like Begin() and need to consume those values
|
||||
return false;
|
||||
@ -8635,14 +8661,15 @@ void ImGui::EndPopup()
|
||||
g.WithinEndChild = false;
|
||||
}
|
||||
|
||||
bool ImGui::OpenPopupContextItem(const char* str_id, ImGuiMouseButton mouse_button)
|
||||
bool ImGui::OpenPopupContextItem(const char* str_id, ImGuiPopupFlags popup_flags)
|
||||
{
|
||||
ImGuiWindow* window = GImGui->CurrentWindow;
|
||||
int mouse_button = (popup_flags & ImGuiPopupFlags_MouseButtonMask_);
|
||||
if (IsMouseReleased(mouse_button) && IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup))
|
||||
{
|
||||
ImGuiID id = str_id ? window->GetID(str_id) : window->DC.LastItemId; // If user hasn't passed an ID, we can use the LastItemID. Using LastItemID as a Popup ID won't conflict!
|
||||
IM_ASSERT(id != 0); // You cannot pass a NULL str_id if the last item has no identifier (e.g. a Text() item)
|
||||
OpenPopupEx(id);
|
||||
OpenPopupEx(id, popup_flags);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -8653,39 +8680,42 @@ bool ImGui::OpenPopupContextItem(const char* str_id, ImGuiMouseButton mouse_butt
|
||||
// - You may want to handle this on user side if you have specific needs (e.g. tweaking IsItemHovered() parameters).
|
||||
// - This is essentially the same as calling OpenPopupContextItem() + BeginPopup() but written to avoid
|
||||
// computing the ID twice because BeginPopupContextXXX functions are called very frequently.
|
||||
bool ImGui::BeginPopupContextItem(const char* str_id, ImGuiMouseButton mouse_button)
|
||||
bool ImGui::BeginPopupContextItem(const char* str_id, ImGuiPopupFlags popup_flags)
|
||||
{
|
||||
ImGuiWindow* window = GImGui->CurrentWindow;
|
||||
if (window->SkipItems)
|
||||
return false;
|
||||
ImGuiID id = str_id ? window->GetID(str_id) : window->DC.LastItemId; // If user hasn't passed an ID, we can use the LastItemID. Using LastItemID as a Popup ID won't conflict!
|
||||
IM_ASSERT(id != 0); // You cannot pass a NULL str_id if the last item has no identifier (e.g. a Text() item)
|
||||
int mouse_button = (popup_flags & ImGuiPopupFlags_MouseButtonMask_);
|
||||
if (IsMouseReleased(mouse_button) && IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup))
|
||||
OpenPopupEx(id);
|
||||
OpenPopupEx(id, popup_flags);
|
||||
return BeginPopupEx(id, ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoSavedSettings);
|
||||
}
|
||||
|
||||
bool ImGui::BeginPopupContextWindow(const char* str_id, ImGuiMouseButton mouse_button, bool also_over_items)
|
||||
bool ImGui::BeginPopupContextWindow(const char* str_id, ImGuiPopupFlags popup_flags)
|
||||
{
|
||||
ImGuiWindow* window = GImGui->CurrentWindow;
|
||||
if (!str_id)
|
||||
str_id = "window_context";
|
||||
ImGuiID id = window->GetID(str_id);
|
||||
int mouse_button = (popup_flags & ImGuiPopupFlags_MouseButtonMask_);
|
||||
if (IsMouseReleased(mouse_button) && IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup))
|
||||
if (also_over_items || !IsAnyItemHovered())
|
||||
OpenPopupEx(id);
|
||||
if (!(popup_flags & ImGuiPopupFlags_NoOpenOverItems) || !IsAnyItemHovered())
|
||||
OpenPopupEx(id, popup_flags);
|
||||
return BeginPopupEx(id, ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoSavedSettings);
|
||||
}
|
||||
|
||||
bool ImGui::BeginPopupContextVoid(const char* str_id, ImGuiMouseButton mouse_button)
|
||||
bool ImGui::BeginPopupContextVoid(const char* str_id, ImGuiPopupFlags popup_flags)
|
||||
{
|
||||
ImGuiWindow* window = GImGui->CurrentWindow;
|
||||
if (!str_id)
|
||||
str_id = "void_context";
|
||||
ImGuiID id = window->GetID(str_id);
|
||||
int mouse_button = (popup_flags & ImGuiPopupFlags_MouseButtonMask_);
|
||||
if (IsMouseReleased(mouse_button) && !IsWindowHovered(ImGuiHoveredFlags_AnyWindow))
|
||||
if (GetTopMostPopupModal() == NULL)
|
||||
OpenPopupEx(id);
|
||||
OpenPopupEx(id, popup_flags);
|
||||
return BeginPopupEx(id, ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoSavedSettings);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user