mirror of
https://github.com/Drezil/imgui.git
synced 2024-12-18 22:26:34 +00:00
Misc tweaks - mostly toward minimizing diff in upcoming backport merge of a few viewport structures in master
This commit is contained in:
parent
6f5f80a544
commit
2a5eaf239f
69
imgui.cpp
69
imgui.cpp
@ -3451,7 +3451,8 @@ ImGuiPlatformIO& ImGui::GetPlatformIO()
|
||||
ImDrawData* ImGui::GetDrawData()
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
return g.Viewports[0]->DrawDataP.Valid ? &g.Viewports[0]->DrawDataP : NULL;
|
||||
ImGuiViewportP* viewport = g.Viewports[0];
|
||||
return viewport->DrawDataP.Valid ? &viewport->DrawDataP : NULL;
|
||||
}
|
||||
|
||||
double ImGui::GetTime()
|
||||
@ -3478,12 +3479,12 @@ static ImDrawList* GetViewportDrawList(ImGuiViewportP* viewport, size_t drawlist
|
||||
}
|
||||
|
||||
// Our ImDrawList system requires that there is always a command
|
||||
if (viewport->LastFrameDrawLists[drawlist_no] != g.FrameCount)
|
||||
if (viewport->DrawListsLastFrame[drawlist_no] != g.FrameCount)
|
||||
{
|
||||
draw_list->_ResetForNewFrame();
|
||||
draw_list->PushTextureID(g.IO.Fonts->TexID);
|
||||
draw_list->PushClipRect(viewport->Pos, viewport->Pos + viewport->Size, false);
|
||||
viewport->LastFrameDrawLists[drawlist_no] = g.FrameCount;
|
||||
viewport->DrawListsLastFrame[drawlist_no] = g.FrameCount;
|
||||
}
|
||||
return draw_list;
|
||||
}
|
||||
@ -3495,8 +3496,8 @@ ImDrawList* ImGui::GetBackgroundDrawList(ImGuiViewport* viewport)
|
||||
|
||||
ImDrawList* ImGui::GetBackgroundDrawList()
|
||||
{
|
||||
ImGuiWindow* window = GImGui->CurrentWindow;
|
||||
return GetBackgroundDrawList(window->Viewport);
|
||||
ImGuiContext& g = *GImGui;
|
||||
return GetBackgroundDrawList(g.CurrentWindow->Viewport);
|
||||
}
|
||||
|
||||
ImDrawList* ImGui::GetForegroundDrawList(ImGuiViewport* viewport)
|
||||
@ -3506,8 +3507,8 @@ ImDrawList* ImGui::GetForegroundDrawList(ImGuiViewport* viewport)
|
||||
|
||||
ImDrawList* ImGui::GetForegroundDrawList()
|
||||
{
|
||||
ImGuiWindow* window = GImGui->CurrentWindow;
|
||||
return GetForegroundDrawList(window->Viewport);
|
||||
ImGuiContext& g = *GImGui;
|
||||
return GetForegroundDrawList(g.CurrentWindow->Viewport);
|
||||
}
|
||||
|
||||
ImDrawListSharedData* ImGui::GetDrawListSharedData()
|
||||
@ -3635,7 +3636,7 @@ void ImGui::UpdateMouseMovingWindowEndFrame()
|
||||
if (g.NavWindow && g.NavWindow->Appearing)
|
||||
return;
|
||||
|
||||
// Click on void to focus window and start moving
|
||||
// Click on empty space to focus window and start moving
|
||||
// (after we're done with all our widgets, so e.g. clicking on docking tab-bar which have set HoveredId already and not get us here!)
|
||||
if (g.IO.MouseClicked[0])
|
||||
{
|
||||
@ -4005,7 +4006,7 @@ void ImGui::NewFrame()
|
||||
ImRect virtual_space(FLT_MAX, FLT_MAX, -FLT_MAX, -FLT_MAX);
|
||||
for (int n = 0; n < g.Viewports.Size; n++)
|
||||
virtual_space.Add(g.Viewports[n]->GetMainRect());
|
||||
g.DrawListSharedData.ClipRectFullscreen = ImVec4(virtual_space.Min.x, virtual_space.Min.y, virtual_space.Max.x, virtual_space.Max.y);
|
||||
g.DrawListSharedData.ClipRectFullscreen = virtual_space.ToVec4();
|
||||
g.DrawListSharedData.CurveTessellationTol = g.Style.CurveTessellationTol;
|
||||
g.DrawListSharedData.SetCircleSegmentMaxError(g.Style.CircleSegmentMaxError);
|
||||
g.DrawListSharedData.InitialFlags = ImDrawListFlags_None;
|
||||
@ -4391,8 +4392,9 @@ static void AddDrawListToDrawData(ImVector<ImDrawList*>* out_list, ImDrawList* d
|
||||
static void AddWindowToDrawData(ImGuiWindow* window, int layer)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImGuiViewportP* viewport = window->Viewport;
|
||||
g.IO.MetricsRenderWindows++;
|
||||
AddDrawListToDrawData(&window->Viewport->DrawDataBuilder.Layers[layer], window->DrawList);
|
||||
AddDrawListToDrawData(&viewport->DrawDataBuilder.Layers[layer], window->DrawList);
|
||||
for (int i = 0; i < window->DC.ChildWindows.Size; i++)
|
||||
{
|
||||
ImGuiWindow* child = window->DC.ChildWindows[i];
|
||||
@ -4435,6 +4437,7 @@ static void SetupViewportDrawData(ImGuiViewportP* viewport, ImVector<ImDrawList*
|
||||
// it earlier in the pipeline, rather than pretend to hide the data at the end of the pipeline.
|
||||
const bool is_minimized = (viewport->Flags & ImGuiViewportFlags_Minimized) != 0;
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
ImDrawData* draw_data = &viewport->DrawDataP;
|
||||
viewport->DrawData = draw_data; // Make publicly accessible
|
||||
draw_data->Valid = true;
|
||||
@ -4443,7 +4446,7 @@ static void SetupViewportDrawData(ImGuiViewportP* viewport, ImVector<ImDrawList*
|
||||
draw_data->TotalVtxCount = draw_data->TotalIdxCount = 0;
|
||||
draw_data->DisplayPos = viewport->Pos;
|
||||
draw_data->DisplaySize = is_minimized ? ImVec2(0.0f, 0.0f) : viewport->Size;
|
||||
draw_data->FramebufferScale = ImGui::GetIO().DisplayFramebufferScale; // FIXME-VIEWPORT: This may vary on a per-monitor/viewport basis?
|
||||
draw_data->FramebufferScale = io.DisplayFramebufferScale; // FIXME-VIEWPORT: This may vary on a per-monitor/viewport basis?
|
||||
draw_data->OwnerViewport = viewport;
|
||||
for (int n = 0; n < draw_lists->Size; n++)
|
||||
{
|
||||
@ -5460,7 +5463,7 @@ static ImVec2 CalcWindowAutoFitSize(ImGuiWindow* window, const ImVec2& size_cont
|
||||
const int monitor_idx = window->ViewportAllowPlatformMonitorExtend;
|
||||
if (monitor_idx >= 0 && monitor_idx < g.PlatformIO.Monitors.Size)
|
||||
avail_size = g.PlatformIO.Monitors[monitor_idx].WorkSize;
|
||||
ImVec2 size_auto_fit = ImClamp(size_desired, size_min, ImMax(size_min, avail_size - g.Style.DisplaySafeAreaPadding * 2.0f));
|
||||
ImVec2 size_auto_fit = ImClamp(size_desired, size_min, ImMax(size_min, avail_size - style.DisplaySafeAreaPadding * 2.0f));
|
||||
|
||||
// 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.
|
||||
@ -9079,8 +9082,7 @@ ImRect ImGui::GetWindowAllowedExtentRect(ImGuiWindow* window)
|
||||
else
|
||||
{
|
||||
// Use the full viewport area (not work area) for popups
|
||||
r_screen.Min = window->Viewport->Pos;
|
||||
r_screen.Max = window->Viewport->Pos + window->Viewport->Size;
|
||||
r_screen = window->Viewport->GetMainRect();
|
||||
}
|
||||
ImVec2 padding = g.Style.DisplaySafeAreaPadding;
|
||||
r_screen.Expand(ImVec2((r_screen.GetWidth() > padding.x * 2) ? -padding.x : 0.0f, (r_screen.GetHeight() > padding.y * 2) ? -padding.y : 0.0f));
|
||||
@ -9090,13 +9092,14 @@ ImRect ImGui::GetWindowAllowedExtentRect(ImGuiWindow* window)
|
||||
ImVec2 ImGui::FindBestWindowPosForPopup(ImGuiWindow* window)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
|
||||
ImRect r_outer = GetWindowAllowedExtentRect(window);
|
||||
if (window->Flags & ImGuiWindowFlags_ChildMenu)
|
||||
{
|
||||
// Child menus typically request _any_ position within the parent menu item, and then we move the new menu outside the parent bounds.
|
||||
// This is how we end up with child menus appearing (most-commonly) on the right of the parent menu.
|
||||
ImGuiWindow* parent_window = window->ParentWindow;
|
||||
float horizontal_overlap = g.Style.ItemInnerSpacing.x; // We want some overlap to convey the relative depth of each menu (currently the amount of overlap is hard-coded to style.ItemSpacing.x).
|
||||
ImRect r_outer = GetWindowAllowedExtentRect(window);
|
||||
ImRect r_avoid;
|
||||
if (parent_window->DC.MenuBarAppending)
|
||||
r_avoid = ImRect(-FLT_MAX, parent_window->ClipRect.Min.y, FLT_MAX, parent_window->ClipRect.Max.y); // Avoid parent menu-bar. If we wanted multi-line menu-bar, we may instead want to have the calling window setup e.g. a NextWindowData.PosConstraintAvoidRect field
|
||||
@ -9106,7 +9109,6 @@ ImVec2 ImGui::FindBestWindowPosForPopup(ImGuiWindow* window)
|
||||
}
|
||||
if (window->Flags & ImGuiWindowFlags_Popup)
|
||||
{
|
||||
ImRect r_outer = GetWindowAllowedExtentRect(window);
|
||||
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);
|
||||
}
|
||||
@ -9115,7 +9117,6 @@ ImVec2 ImGui::FindBestWindowPosForPopup(ImGuiWindow* window)
|
||||
// Position tooltip (always follows mouse)
|
||||
float sc = g.Style.MouseCursorScale;
|
||||
ImVec2 ref_pos = NavCalcPreferredRefPos();
|
||||
ImRect r_outer = GetWindowAllowedExtentRect(window);
|
||||
ImRect r_avoid;
|
||||
if (!g.NavDisableHighlight && g.NavDisableMouseHover && !(g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableSetMousePos))
|
||||
r_avoid = ImRect(ref_pos.x - 16, ref_pos.y - 8, ref_pos.x + 16, ref_pos.y + 8);
|
||||
@ -9529,8 +9530,8 @@ static ImVec2 ImGui::NavCalcPreferredRefPos()
|
||||
// When navigation is active and mouse is disabled, decide on an arbitrary position around the bottom left of the currently navigated item.
|
||||
const ImRect& rect_rel = g.NavWindow->NavRectRel[g.NavLayer];
|
||||
ImVec2 pos = g.NavWindow->Pos + ImVec2(rect_rel.Min.x + ImMin(g.Style.FramePadding.x * 4, rect_rel.GetWidth()), rect_rel.Max.y - ImMin(g.Style.FramePadding.y, rect_rel.GetHeight()));
|
||||
ImRect visible_rect = g.NavWindow->Viewport->GetMainRect();
|
||||
return ImFloor(ImClamp(pos, visible_rect.Min, visible_rect.Max)); // ImFloor() is important because non-integer mouse position application in backend might be lossy and result in undesirable non-zero delta.
|
||||
ImGuiViewport* viewport = g.NavWindow->Viewport;
|
||||
return ImFloor(ImClamp(pos, viewport->Pos, viewport->Pos + viewport->Size)); // ImFloor() is important because non-integer mouse position application in backend might be lossy and result in undesirable non-zero delta.
|
||||
}
|
||||
}
|
||||
|
||||
@ -10275,7 +10276,7 @@ void ImGui::NavUpdateWindowingOverlay()
|
||||
g.NavWindowingListWindow = FindWindowByName("###NavWindowingList");
|
||||
const ImGuiViewport* viewport = /*g.NavWindow ? g.NavWindow->Viewport :*/ GetMainViewport();
|
||||
SetNextWindowSizeConstraints(ImVec2(viewport->Size.x * 0.20f, viewport->Size.y * 0.20f), ImVec2(FLT_MAX, FLT_MAX));
|
||||
SetNextWindowPos(viewport->Pos + viewport->Size * 0.5f, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
|
||||
SetNextWindowPos(viewport->GetCenter(), ImGuiCond_Always, ImVec2(0.5f, 0.5f));
|
||||
PushStyleVar(ImGuiStyleVar_WindowPadding, g.Style.WindowPadding * 2.0f);
|
||||
Begin("###NavWindowingList", NULL, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings);
|
||||
for (int n = g.WindowsFocusOrder.Size - 1; n >= 0; n--)
|
||||
@ -15809,9 +15810,7 @@ static void RenderViewportThumbnail(ImDrawList* draw_list, ImGuiViewportP* viewp
|
||||
for (int i = 0; i != g.Windows.Size; i++)
|
||||
{
|
||||
ImGuiWindow* thumb_window = g.Windows[i];
|
||||
if (!thumb_window->WasActive || ((thumb_window->Flags & ImGuiWindowFlags_ChildWindow)))
|
||||
continue;
|
||||
if (thumb_window->SkipItems && (thumb_window->Flags & ImGuiWindowFlags_ChildWindow)) // FIXME-DOCK: Skip hidden docked windows. Identify those betters.
|
||||
if (!thumb_window->WasActive || (thumb_window->Flags & ImGuiWindowFlags_ChildWindow))
|
||||
continue;
|
||||
if (thumb_window->Viewport != viewport)
|
||||
continue;
|
||||
@ -15840,14 +15839,10 @@ static void RenderViewportsThumbnails()
|
||||
// We don't display full monitor bounds (we could, but it often looks awkward), instead we display just enough to cover all of our viewports.
|
||||
float SCALE = 1.0f / 8.0f;
|
||||
ImRect bb_full;
|
||||
//for (int n = 0; n < g.PlatformIO.Monitors.Size; n++)
|
||||
// bb_full.Add(GetPlatformMonitorMainRect(g.PlatformIO.Monitors[n]));
|
||||
for (int n = 0; n < g.Viewports.Size; n++)
|
||||
bb_full.Add(g.Viewports[n]->GetMainRect());
|
||||
ImVec2 p = window->DC.CursorPos;
|
||||
ImVec2 off = p - bb_full.Min * SCALE;
|
||||
//for (int n = 0; n < g.PlatformIO.Monitors.Size; n++)
|
||||
// window->DrawList->AddRect(off + g.PlatformIO.Monitors[n].MainPos * SCALE, off + (g.PlatformIO.Monitors[n].MainPos + g.PlatformIO.Monitors[n].MainSize) * SCALE, ImGui::GetColorU32(ImGuiCol_Border));
|
||||
for (int n = 0; n < g.Viewports.Size; n++)
|
||||
{
|
||||
ImGuiViewportP* viewport = g.Viewports[n];
|
||||
@ -16019,7 +16014,7 @@ void ImGui::ShowMetricsWindow(bool* p_open)
|
||||
DebugNodeWindowsList(&g.Windows, "Windows");
|
||||
//DebugNodeWindowsList(&g.WindowsFocusOrder, "WindowsFocusOrder");
|
||||
|
||||
// Drawlists
|
||||
// DrawLists
|
||||
int drawlist_count = 0;
|
||||
for (int viewport_i = 0; viewport_i < g.Viewports.Size; viewport_i++)
|
||||
drawlist_count += g.Viewports[viewport_i]->DrawDataBuilder.GetDrawListCount();
|
||||
@ -16033,7 +16028,7 @@ void ImGui::ShowMetricsWindow(bool* p_open)
|
||||
for (int draw_list_i = 0; draw_list_i < viewport->DrawDataBuilder.Layers[layer_i].Size; draw_list_i++)
|
||||
{
|
||||
if (!viewport_has_drawlist)
|
||||
ImGui::Text("Active DrawLists in Viewport #%d, ID: 0x%08X", viewport->Idx, viewport->ID);
|
||||
Text("Active DrawLists in Viewport #%d, ID: 0x%08X", viewport->Idx, viewport->ID);
|
||||
viewport_has_drawlist = true;
|
||||
DebugNodeDrawList(NULL, viewport, viewport->DrawDataBuilder.Layers[layer_i][draw_list_i], "DrawList");
|
||||
}
|
||||
@ -16047,8 +16042,9 @@ void ImGui::ShowMetricsWindow(bool* p_open)
|
||||
Indent(GetTreeNodeToLabelSpacing());
|
||||
RenderViewportsThumbnails();
|
||||
Unindent(GetTreeNodeToLabelSpacing());
|
||||
|
||||
bool open = TreeNode("Monitors", "Monitors (%d)", g.PlatformIO.Monitors.Size);
|
||||
ImGui::SameLine();
|
||||
SameLine();
|
||||
MetricsHelpMarker("Dear ImGui uses monitor data:\n- to query DPI settings on a per monitor basis\n- to position popup/tooltips so they don't straddle monitors.");
|
||||
if (open)
|
||||
{
|
||||
@ -16062,6 +16058,7 @@ void ImGui::ShowMetricsWindow(bool* p_open)
|
||||
}
|
||||
TreePop();
|
||||
}
|
||||
|
||||
for (int i = 0; i < g.Viewports.Size; i++)
|
||||
DebugNodeViewport(g.Viewports[i]);
|
||||
TreePop();
|
||||
@ -16155,14 +16152,14 @@ void ImGui::ShowMetricsWindow(bool* p_open)
|
||||
#endif // #ifdef IMGUI_HAS_TABLE
|
||||
|
||||
#ifdef IMGUI_HAS_DOCK
|
||||
if (ImGui::TreeNode("SettingsDocking", "Settings packed data: Docking"))
|
||||
if (TreeNode("SettingsDocking", "Settings packed data: Docking"))
|
||||
{
|
||||
ImGuiDockContext* dc = &g.DockContext;
|
||||
ImGui::Text("In SettingsWindows:");
|
||||
Text("In SettingsWindows:");
|
||||
for (ImGuiWindowSettings* settings = g.SettingsWindows.begin(); settings != NULL; settings = g.SettingsWindows.next_chunk(settings))
|
||||
if (settings->DockId != 0)
|
||||
ImGui::BulletText("Window '%s' -> DockId %08X", settings->GetName(), settings->DockId);
|
||||
ImGui::Text("In SettingsNodes:");
|
||||
BulletText("Window '%s' -> DockId %08X", settings->GetName(), settings->DockId);
|
||||
Text("In SettingsNodes:");
|
||||
for (int n = 0; n < dc->NodesSettings.Size; n++)
|
||||
{
|
||||
ImGuiDockNodeSettings* settings = &dc->NodesSettings[n];
|
||||
@ -16174,9 +16171,9 @@ void ImGui::ShowMetricsWindow(bool* p_open)
|
||||
else if (ImGuiWindowSettings* window_settings = FindWindowSettings(settings->SelectedWindowId))
|
||||
selected_tab_name = window_settings->GetName();
|
||||
}
|
||||
ImGui::BulletText("Node %08X, Parent %08X, SelectedTab %08X ('%s')", settings->ID, settings->ParentNodeId, settings->SelectedWindowId, selected_tab_name ? selected_tab_name : settings->SelectedWindowId ? "N/A" : "");
|
||||
BulletText("Node %08X, Parent %08X, SelectedTab %08X ('%s')", settings->ID, settings->ParentNodeId, settings->SelectedWindowId, selected_tab_name ? selected_tab_name : settings->SelectedWindowId ? "N/A" : "");
|
||||
}
|
||||
ImGui::TreePop();
|
||||
TreePop();
|
||||
}
|
||||
#endif // #ifdef IMGUI_HAS_DOCK
|
||||
|
||||
|
4
imgui.h
4
imgui.h
@ -427,8 +427,8 @@ namespace ImGui
|
||||
IMGUI_API void SetCursorPosX(float local_x); // GetWindowPos() + GetCursorPos() == GetCursorScreenPos() etc.)
|
||||
IMGUI_API void SetCursorPosY(float local_y); //
|
||||
IMGUI_API ImVec2 GetCursorStartPos(); // initial cursor position in window coordinates
|
||||
IMGUI_API ImVec2 GetCursorScreenPos(); // cursor position in absolute screen coordinates (0..io.DisplaySize) or natural OS coordinates when using multiple viewport. Useful to work with ImDrawList API.
|
||||
IMGUI_API void SetCursorScreenPos(const ImVec2& pos); // cursor position in absolute screen coordinates (0..io.DisplaySize) or natural OS coordinates when using multiple viewport.
|
||||
IMGUI_API ImVec2 GetCursorScreenPos(); // cursor position in absolute coordinates (useful to work with ImDrawList API). generally top-left == GetMainViewport()->Pos == (0,0) in single viewport mode, and bottom-right == GetMainViewport()->Pos+Size == io.DisplaySize in single-viewport mode.
|
||||
IMGUI_API void SetCursorScreenPos(const ImVec2& pos); // cursor position in absolute coordinates
|
||||
IMGUI_API void AlignTextToFramePadding(); // vertically align upcoming text baseline to FramePadding.y so that it will align properly to regularly framed items (call if you have text on a line before a framed item)
|
||||
IMGUI_API float GetTextLineHeight(); // ~ FontSize
|
||||
IMGUI_API float GetTextLineHeightWithSpacing(); // ~ FontSize + style.ItemSpacing.y (distance in pixels between 2 consecutive lines of text)
|
||||
|
@ -3291,9 +3291,6 @@ static void ShowDemoWindowPopups()
|
||||
|
||||
// Always center this window when appearing
|
||||
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
|
||||
//ImVec2 parent_pos = ImGui::GetWindowPos();
|
||||
//ImVec2 parent_size = ImGui::GetWindowSize();
|
||||
//ImVec2 center(parent_pos.x + parent_size.x * 0.5f, parent_pos.y + parent_size.y * 0.5f);
|
||||
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
|
||||
|
||||
if (ImGui::BeginPopupModal("Delete?", NULL, ImGuiWindowFlags_AlwaysAutoResize))
|
||||
@ -7068,21 +7065,23 @@ static void ShowExampleAppConstrainedResize(bool* p_open)
|
||||
// + a context-menu to choose which corner of the screen to use.
|
||||
static void ShowExampleAppSimpleOverlay(bool* p_open)
|
||||
{
|
||||
// FIXME-VIEWPORT: Select a default viewport
|
||||
const float DISTANCE = 10.0f;
|
||||
static int corner = 0;
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav;
|
||||
if (corner != -1)
|
||||
{
|
||||
window_flags |= ImGuiWindowFlags_NoMove;
|
||||
const float PAD = 10.0f;
|
||||
const ImGuiViewport* viewport = ImGui::GetMainViewport();
|
||||
ImVec2 work_area_pos = viewport->WorkPos; // Use work area to avoid menu-bar/task-bar, if any!
|
||||
ImVec2 work_area_size = viewport->WorkSize;
|
||||
ImVec2 window_pos = ImVec2((corner & 1) ? (work_area_pos.x + work_area_size.x - DISTANCE) : (work_area_pos.x + DISTANCE), (corner & 2) ? (work_area_pos.y + work_area_size.y - DISTANCE) : (work_area_pos.y + DISTANCE));
|
||||
ImVec2 window_pos_pivot = ImVec2((corner & 1) ? 1.0f : 0.0f, (corner & 2) ? 1.0f : 0.0f);
|
||||
ImVec2 work_pos = viewport->WorkPos; // Use work area to avoid menu-bar/task-bar, if any!
|
||||
ImVec2 work_size = viewport->WorkSize;
|
||||
ImVec2 window_pos, window_pos_pivot;
|
||||
window_pos.x = (corner & 1) ? (work_pos.x + work_size.x - PAD) : (work_pos.x + PAD);
|
||||
window_pos.y = (corner & 2) ? (work_pos.y + work_size.y - PAD) : (work_pos.y + PAD);
|
||||
window_pos_pivot.x = (corner & 1) ? 1.0f : 0.0f;
|
||||
window_pos_pivot.y = (corner & 2) ? 1.0f : 0.0f;
|
||||
ImGui::SetNextWindowPos(window_pos, ImGuiCond_Always, window_pos_pivot);
|
||||
ImGui::SetNextWindowViewport(viewport->ID);
|
||||
window_flags |= ImGuiWindowFlags_NoMove;
|
||||
}
|
||||
ImGui::SetNextWindowBgAlpha(0.35f); // Transparent background
|
||||
if (ImGui::Begin("Example: Simple overlay", p_open, window_flags))
|
||||
@ -7114,10 +7113,12 @@ static void ShowExampleAppSimpleOverlay(bool* p_open)
|
||||
// Demonstrate creating a window covering the entire screen/viewport
|
||||
static void ShowExampleAppFullscreen(bool* p_open)
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
// May use viewport->WorkPos and viewport->WorkSize to avoid menu-bar/task-bar
|
||||
const ImGuiViewport* viewport = ImGui::GetMainViewport();
|
||||
ImGui::SetNextWindowPos(viewport->Pos);
|
||||
ImGui::SetNextWindowSize(viewport->Size);
|
||||
|
||||
static ImGuiWindowFlags flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings;
|
||||
ImGui::SetNextWindowPos(ImVec2(0, 0));
|
||||
ImGui::SetNextWindowSize(io.DisplaySize);
|
||||
if (ImGui::Begin("Example: Fullscreen window", p_open, flags))
|
||||
{
|
||||
ImGui::CheckboxFlags("ImGuiWindowFlags_NoBackground", &flags, ImGuiWindowFlags_NoBackground);
|
||||
@ -7140,16 +7141,19 @@ static void ShowExampleAppFullscreen(bool* p_open)
|
||||
// Read FAQ section "How can I have multiple widgets with the same label?" for details.
|
||||
static void ShowExampleAppWindowTitles(bool*)
|
||||
{
|
||||
ImGuiViewport* viewport = ImGui::GetMainViewport();
|
||||
ImVec2 base_pos = viewport->WorkPos;
|
||||
|
||||
// By default, Windows are uniquely identified by their title.
|
||||
// You can use the "##" and "###" markers to manipulate the display/ID.
|
||||
|
||||
// Using "##" to display same title but have unique identifier.
|
||||
ImGui::SetNextWindowPos(ImVec2(100, 100), ImGuiCond_FirstUseEver);
|
||||
ImGui::SetNextWindowPos(ImVec2(base_pos.x + 100, base_pos.y + 100), ImGuiCond_FirstUseEver);
|
||||
ImGui::Begin("Same title as another window##1");
|
||||
ImGui::Text("This is window 1.\nMy title is the same as window 2, but my identifier is unique.");
|
||||
ImGui::End();
|
||||
|
||||
ImGui::SetNextWindowPos(ImVec2(100, 200), ImGuiCond_FirstUseEver);
|
||||
ImGui::SetNextWindowPos(ImVec2(base_pos.x + 100, base_pos.y + 200), ImGuiCond_FirstUseEver);
|
||||
ImGui::Begin("Same title as another window##2");
|
||||
ImGui::Text("This is window 2.\nMy title is the same as window 1, but my identifier is unique.");
|
||||
ImGui::End();
|
||||
@ -7157,7 +7161,7 @@ static void ShowExampleAppWindowTitles(bool*)
|
||||
// Using "###" to display a changing title but keep a static identifier "AnimatedTitle"
|
||||
char buf[128];
|
||||
sprintf(buf, "Animated title %c %d###AnimatedTitle", "|/-\\"[(int)(ImGui::GetTime() / 0.25f) & 3], ImGui::GetFrameCount());
|
||||
ImGui::SetNextWindowPos(ImVec2(100, 300), ImGuiCond_FirstUseEver);
|
||||
ImGui::SetNextWindowPos(ImVec2(base_pos.x + 100, base_pos.y + 300), ImGuiCond_FirstUseEver);
|
||||
ImGui::Begin(buf);
|
||||
ImGui::Text("This window has a changing title.");
|
||||
ImGui::End();
|
||||
|
@ -1296,21 +1296,21 @@ struct ImGuiDockContext
|
||||
#ifdef IMGUI_HAS_VIEWPORT
|
||||
|
||||
// ImGuiViewport Private/Internals fields (cardinal sin: we are using inheritance!)
|
||||
// Note that every instance of ImGuiViewport is in fact a ImGuiViewportP.
|
||||
// Every instance of ImGuiViewport is in fact a ImGuiViewportP.
|
||||
struct ImGuiViewportP : public ImGuiViewport
|
||||
{
|
||||
int Idx;
|
||||
int LastFrameActive; // Last frame number this viewport was activated by a window
|
||||
int LastFrameDrawLists[2]; // Last frame number the background (0) and foreground (1) draw lists were used
|
||||
int LastFrontMostStampCount; // Last stamp number from when a window hosted by this viewport was made front-most (by comparing this value between two viewport we have an implicit viewport z-order
|
||||
int LastFrameActive; // Last frame number this viewport was activated by a window
|
||||
int LastFrontMostStampCount;// Last stamp number from when a window hosted by this viewport was made front-most (by comparing this value between two viewport we have an implicit viewport z-order
|
||||
ImGuiID LastNameHash;
|
||||
ImVec2 LastPos;
|
||||
float Alpha; // Window opacity (when dragging dockable windows/viewports we make them transparent)
|
||||
float Alpha; // Window opacity (when dragging dockable windows/viewports we make them transparent)
|
||||
float LastAlpha;
|
||||
short PlatformMonitor;
|
||||
bool PlatformWindowCreated;
|
||||
ImGuiWindow* Window; // Set when the viewport is owned by a window (and ImGuiViewportFlags_CanHostOtherWindows is NOT set)
|
||||
ImDrawList* DrawLists[2]; // Convenience background (0) and foreground (1) draw lists. We use them to draw software mouser cursor when io.MouseDrawCursor is set and to draw most debug overlays.
|
||||
ImGuiWindow* Window; // Set when the viewport is owned by a window (and ImGuiViewportFlags_CanHostOtherWindows is NOT set)
|
||||
int DrawListsLastFrame[2]; // Last frame number the background (0) and foreground (1) draw lists were used
|
||||
ImDrawList* DrawLists[2]; // Convenience background (0) and foreground (1) draw lists. We use them to draw software mouser cursor when io.MouseDrawCursor is set and to draw most debug overlays.
|
||||
ImDrawData DrawDataP;
|
||||
ImDrawDataBuilder DrawDataBuilder;
|
||||
ImVec2 LastPlatformPos;
|
||||
@ -1321,7 +1321,7 @@ struct ImGuiViewportP : public ImGuiViewport
|
||||
ImVec2 CurrWorkOffsetMin; // Work Area: Offset being built/increased during current frame
|
||||
ImVec2 CurrWorkOffsetMax; // Work Area: Offset being built/decreased during current frame
|
||||
|
||||
ImGuiViewportP() { Idx = -1; LastFrameActive = LastFrameDrawLists[0] = LastFrameDrawLists[1] = LastFrontMostStampCount = -1; LastNameHash = 0; Alpha = LastAlpha = 1.0f; PlatformMonitor = -1; PlatformWindowCreated = false; Window = NULL; DrawLists[0] = DrawLists[1] = NULL; LastPlatformPos = LastPlatformSize = LastRendererSize = ImVec2(FLT_MAX, FLT_MAX); }
|
||||
ImGuiViewportP() { Idx = -1; LastFrameActive = DrawListsLastFrame[0] = DrawListsLastFrame[1] = LastFrontMostStampCount = -1; LastNameHash = 0; Alpha = LastAlpha = 1.0f; PlatformMonitor = -1; PlatformWindowCreated = false; Window = NULL; DrawLists[0] = DrawLists[1] = NULL; LastPlatformPos = LastPlatformSize = LastRendererSize = ImVec2(FLT_MAX, FLT_MAX); }
|
||||
~ImGuiViewportP() { if (DrawLists[0]) IM_DELETE(DrawLists[0]); if (DrawLists[1]) IM_DELETE(DrawLists[1]); }
|
||||
ImRect GetMainRect() const { return ImRect(Pos.x, Pos.y, Pos.x + Size.x, Pos.y + Size.y); }
|
||||
ImRect GetWorkRect() const { return ImRect(WorkPos.x, WorkPos.y, WorkPos.x + WorkSize.x, WorkPos.y + WorkSize.y); }
|
||||
@ -2439,9 +2439,9 @@ namespace ImGui
|
||||
IMGUI_API void CallContextHooks(ImGuiContext* context, ImGuiContextHookType type);
|
||||
|
||||
// Viewports
|
||||
IMGUI_API void TranslateWindowsInViewport(ImGuiViewportP* viewport, const ImVec2& old_pos, const ImVec2& new_pos);
|
||||
IMGUI_API void ScaleWindowsInViewport(ImGuiViewportP* viewport, float scale);
|
||||
IMGUI_API void DestroyPlatformWindow(ImGuiViewportP* viewport);
|
||||
IMGUI_API void TranslateWindowsInViewport(ImGuiViewportP* viewport, const ImVec2& old_pos, const ImVec2& new_pos);
|
||||
IMGUI_API void ScaleWindowsInViewport(ImGuiViewportP* viewport, float scale);
|
||||
IMGUI_API void DestroyPlatformWindow(ImGuiViewportP* viewport);
|
||||
|
||||
// Settings
|
||||
IMGUI_API void MarkIniSettingsDirty();
|
||||
|
@ -6592,7 +6592,8 @@ bool ImGui::BeginMainMenuBar()
|
||||
if (menu_bar_window == NULL || menu_bar_window->BeginCount == 0)
|
||||
{
|
||||
// Set window position
|
||||
// We don't attempt to calculate our height ahead, as it depends on the per-viewport font size. However menu-bar will affect the minimum window size so we'll get the right height.
|
||||
// We don't attempt to calculate our height ahead, as it depends on the per-viewport font size.
|
||||
// However menu-bar will affect the minimum window size so we'll get the right height.
|
||||
ImVec2 menu_bar_pos = viewport->Pos + viewport->CurrWorkOffsetMin;
|
||||
ImVec2 menu_bar_size = ImVec2(viewport->Size.x - viewport->CurrWorkOffsetMin.x + viewport->CurrWorkOffsetMax.x, 1.0f);
|
||||
SetNextWindowPos(menu_bar_pos);
|
||||
@ -6602,7 +6603,7 @@ bool ImGui::BeginMainMenuBar()
|
||||
// Create window
|
||||
SetNextWindowViewport(viewport->ID); // Enforce viewport so we don't create our own viewport when ImGuiConfigFlags_ViewportsNoMerge is set.
|
||||
PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
|
||||
PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2(0, 0)); // Lift normal size constraint, however the presence of a menu-bar will give us the minimum height we want.
|
||||
PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2(0, 0)); // Lift normal size constraint, however the presence of a menu-bar will give us the minimum height we want.
|
||||
ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_MenuBar;
|
||||
bool is_open = Begin("##MainMenuBar", NULL, window_flags) && BeginMenuBar();
|
||||
PopStyleVar(2);
|
||||
|
Loading…
Reference in New Issue
Block a user