mirror of
https://github.com/ocornut/imgui.git
synced 2024-12-03 05:29:10 +08:00
Docking: Added io.ConfigDockingTransparentPayload option (to use with ImGuiConfigFlags_ViewportsNoMerge)
This commit is contained in:
parent
3bcc25f588
commit
19d17ed274
47
imgui.cpp
47
imgui.cpp
@ -920,6 +920,9 @@ static const float NAV_WINDOWING_LIST_APPEAR_DELAY = 0.15f; // Time
|
||||
static const float RESIZE_WINDOWS_FROM_EDGES_HALF_THICKNESS = 4.0f; // Extend outside and inside windows. Affect FindHoveredWindow().
|
||||
static const float RESIZE_WINDOWS_FROM_EDGES_FEEDBACK_TIMER = 0.04f; // Reduce visual noise by only highlighting the border after a certain time.
|
||||
|
||||
// Docking
|
||||
static const float DOCKING_TRANSPARENT_PAYLOAD_ALPHA = 0.50f; // For use with io.ConfigDockingTransparentPayload. Apply to Viewport _or_ WindowBg in host viewport.
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// [SECTION] FORWARD DECLARATIONS
|
||||
//-------------------------------------------------------------------------
|
||||
@ -1114,6 +1117,7 @@ ImGuiIO::ImGuiIO()
|
||||
|
||||
// Miscellaneous configuration options
|
||||
ConfigDockingWithShift = false;
|
||||
ConfigDockingTransparentPayload = false;
|
||||
#ifdef __APPLE__
|
||||
ConfigMacOSXBehaviors = true; // Set Mac OS X style defaults based on __APPLE__ compile time flag
|
||||
#else
|
||||
@ -3281,6 +3285,8 @@ void ImGui::NewFrame()
|
||||
IM_ASSERT(g.PlatformIO.Platform_GetWindowSize != NULL && "Platform init didn't install handlers?");
|
||||
IM_ASSERT(g.PlatformIO.Platform_SetWindowSize != NULL && "Platform init didn't install handlers?");
|
||||
IM_ASSERT((g.Viewports[0]->PlatformUserData != NULL || g.Viewports[0]->PlatformHandle != NULL) && "Platform init didn't setup main viewport.");
|
||||
if (g.IO.ConfigDockingTransparentPayload && (g.IO.ConfigFlags & ImGuiConfigFlags_DockingEnable))
|
||||
IM_ASSERT(g.PlatformIO.Platform_SetWindowAlpha != NULL && "Platform_SetWindowAlpha handler is required to use io.ConfigDockingTransparent!");
|
||||
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||
IM_ASSERT(g.IO.RenderDrawListsFn == NULL); // Call ImGui::Render() then pass ImGui::GetDrawData() yourself to your render function!
|
||||
#endif
|
||||
@ -5367,13 +5373,29 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
||||
// Window background
|
||||
if (!(flags & ImGuiWindowFlags_NoBackground))
|
||||
{
|
||||
bool is_docking_transparent_payload = false;
|
||||
if (g.DragDropActive && (g.FrameCount - g.DragDropAcceptFrameCount) <= 1 && g.IO.ConfigDockingTransparentPayload)
|
||||
if (g.DragDropPayload.IsDataType(IMGUI_PAYLOAD_TYPE_WINDOW) && *(ImGuiWindow**)g.DragDropPayload.Data == window)
|
||||
is_docking_transparent_payload = true;
|
||||
|
||||
ImU32 bg_col = GetColorU32(GetWindowBgColorIdxFromFlags(flags));
|
||||
if (g.NextWindowData.BgAlphaCond != 0)
|
||||
bg_col = (bg_col & ~IM_COL32_A_MASK) | (IM_F32_TO_INT8_SAT(g.NextWindowData.BgAlphaVal) << IM_COL32_A_SHIFT);
|
||||
if (window->ViewportOwned)
|
||||
{
|
||||
//window->Viewport->Alpha = ((bg_col & IM_COL32_A_MASK) >> IM_COL32_A_SHIFT) / 255.0f;
|
||||
// No alpha
|
||||
bg_col = (bg_col | IM_COL32_A_MASK);
|
||||
if (is_docking_transparent_payload)
|
||||
window->Viewport->Alpha *= DOCKING_TRANSPARENT_PAYLOAD_ALPHA;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Adjust alpha. For docking
|
||||
float alpha = 1.0f;
|
||||
if (g.NextWindowData.BgAlphaCond != 0)
|
||||
alpha = g.NextWindowData.BgAlphaVal;
|
||||
if (is_docking_transparent_payload)
|
||||
alpha *= DOCKING_TRANSPARENT_PAYLOAD_ALPHA;
|
||||
if (alpha != 1.0f)
|
||||
bg_col = (bg_col & ~IM_COL32_A_MASK) | (IM_F32_TO_INT8_SAT(alpha) << IM_COL32_A_SHIFT);
|
||||
}
|
||||
window->DrawList->AddRectFilled(window->Pos + ImVec2(0, window->TitleBarHeight()), window->Pos + window->Size, bg_col, window_rounding, (flags & ImGuiWindowFlags_NoTitleBar) ? ImDrawCornerFlags_All : ImDrawCornerFlags_Bot);
|
||||
}
|
||||
@ -7534,7 +7556,7 @@ static void ImGui::UpdateViewports()
|
||||
if (g.PlatformIO.Platform_GetWindowMinimized && (n == 0 || viewport->CreatedPlatformWindow))
|
||||
viewport->PlatformIsMinimized = g.PlatformIO.Platform_GetWindowMinimized(viewport);
|
||||
|
||||
// Apply Position and Size (from Platform Window to ImGui) if requested.
|
||||
// Update Position and Size (from Platform Window to ImGui) if requested.
|
||||
// We do it early in the frame instead of waiting for UpdatePlatformWindows() to avoid a frame of lag when moving/resizing using OS facilities.
|
||||
if (!viewport->PlatformIsMinimized)
|
||||
{
|
||||
@ -7548,6 +7570,9 @@ static void ImGui::UpdateViewports()
|
||||
viewport->PlatformMonitor = FindPlatformMonitorForRect(viewport->GetRect());
|
||||
}
|
||||
|
||||
// Reset alpha every frame. Users of transparency (docking) needs to request a lower alpha back.
|
||||
viewport->Alpha = 1.0f;
|
||||
|
||||
// Translate imgui windows when a Host Viewport has been moved
|
||||
// (This additionally keeps windows at the same place when ImGuiConfigFlags_ViewportsEnable is toggled!)
|
||||
ImVec2 viewport_delta = viewport->Pos - viewport->LastPos;
|
||||
@ -11352,19 +11377,23 @@ static void ImGui::DockNodePreviewDockRender(ImGuiWindow* host_window, ImGuiDock
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
|
||||
// With this option, we only display the preview on the target viewport, and the payload viewport is made transparent.
|
||||
// To compensate for the single layer obstructed by the payload, we'll increase the alpha of the preview nodes.
|
||||
const bool is_transparent_payload = g.IO.ConfigDockingTransparentPayload;
|
||||
|
||||
// In case the two windows involved are on different viewports, we will draw the overlay on each of them.
|
||||
int overlay_draw_lists_count = 0;
|
||||
ImDrawList* overlay_draw_lists[2];
|
||||
overlay_draw_lists[overlay_draw_lists_count++] = GetOverlayDrawList(host_window->Viewport);
|
||||
if (host_window->Viewport != root_payload->Viewport)
|
||||
if (host_window->Viewport != root_payload->Viewport && !is_transparent_payload)
|
||||
overlay_draw_lists[overlay_draw_lists_count++] = GetOverlayDrawList(root_payload->Viewport);
|
||||
|
||||
// Draw main preview rectangle
|
||||
const ImU32 overlay_col_tabs = GetColorU32(ImGuiCol_TabActive);
|
||||
const ImU32 overlay_col_main = GetColorU32(ImGuiCol_DockingPreview, 0.40f);
|
||||
const ImU32 overlay_col_drop = GetColorU32(ImGuiCol_DockingPreview, 0.70f);
|
||||
const ImU32 overlay_col_drop_hovered = GetColorU32(ImGuiCol_DockingPreview);
|
||||
const ImU32 overlay_col_lines = GetColorU32(ImGuiCol_NavWindowingHighlight, 0.60f);
|
||||
const ImU32 overlay_col_main = GetColorU32(ImGuiCol_DockingPreview, is_transparent_payload ? 0.60f : 0.40f);
|
||||
const ImU32 overlay_col_drop = GetColorU32(ImGuiCol_DockingPreview, is_transparent_payload ? 0.90f : 0.70f);
|
||||
const ImU32 overlay_col_drop_hovered = GetColorU32(ImGuiCol_DockingPreview, is_transparent_payload ? 1.20f : 1.00f);
|
||||
const ImU32 overlay_col_lines = GetColorU32(ImGuiCol_NavWindowingHighlight, is_transparent_payload ? 0.80f : 0.60f);
|
||||
|
||||
// Display area preview
|
||||
const bool can_preview_tabs = (root_payload->DockNodeAsHost == NULL || root_payload->DockNodeAsHost->Windows.Size > 0);
|
||||
|
11
imgui.h
11
imgui.h
@ -1275,11 +1275,12 @@ struct ImGuiIO
|
||||
ImVec2 DisplayFramebufferScale; // = (1.0f,1.0f) // For retina display or other situations where window coordinates are different from framebuffer coordinates. User storage only, presently not used by ImGui.
|
||||
|
||||
// Miscellaneous configuration options
|
||||
bool MouseDrawCursor; // = false // Request ImGui to draw a mouse cursor for you (if you are on a platform without a mouse cursor). Cannot be easily renamed to 'io.ConfigXXX' because this is frequently used by back-end implementations.
|
||||
bool ConfigDockingWithShift; // = false // Enable docking with holding Shift key (reduce visual noise, allows dropping in wider space)
|
||||
bool ConfigMacOSXBehaviors; // = defined(__APPLE__) // OS X style: Text editing cursor movement using Alt instead of Ctrl, Shortcuts using Cmd/Super instead of Ctrl, Line/Text Start and End using Cmd+Arrows instead of Home/End, Double click selects by word instead of selecting whole text, Multi-selection in lists uses Cmd/Super instead of Ctrl (was called io.OptMacOSXBehaviors prior to 1.63)
|
||||
bool ConfigInputTextCursorBlink; // = true // Set to false to disable blinking cursor, for users who consider it distracting. (was called: io.OptCursorBlink prior to 1.63)
|
||||
bool ConfigResizeWindowsFromEdges; // = true // [BETA] Enable resizing of windows from their edges and from the lower-left corner. This requires (io.BackendFlags & ImGuiBackendFlags_HasMouseCursors) because it needs mouse cursor feedback. (This used to be the ImGuiWindowFlags_ResizeFromAnySide flag)
|
||||
bool MouseDrawCursor; // = false // Request ImGui to draw a mouse cursor for you (if you are on a platform without a mouse cursor). Cannot be easily renamed to 'io.ConfigXXX' because this is frequently used by back-end implementations.
|
||||
bool ConfigDockingWithShift; // = false // Enable docking with holding Shift key (reduce visual noise, allows dropping in wider space)
|
||||
bool ConfigDockingTransparentPayload; // = false // [BETA] Make window or viewport transparent when docking and only display docking boxes on the target viewport. Useful if rendering of multiple viewport can be synced. Best used with ImGuiConfigFlags_ViewportsNoMerge.
|
||||
bool ConfigMacOSXBehaviors; // = defined(__APPLE__) // OS X style: Text editing cursor movement using Alt instead of Ctrl, Shortcuts using Cmd/Super instead of Ctrl, Line/Text Start and End using Cmd+Arrows instead of Home/End, Double click selects by word instead of selecting whole text, Multi-selection in lists uses Cmd/Super instead of Ctrl (was called io.OptMacOSXBehaviors prior to 1.63)
|
||||
bool ConfigInputTextCursorBlink; // = true // Set to false to disable blinking cursor, for users who consider it distracting. (was called: io.OptCursorBlink prior to 1.63)
|
||||
bool ConfigResizeWindowsFromEdges; // = true // [BETA] Enable resizing of windows from their edges and from the lower-left corner. This requires (io.BackendFlags & ImGuiBackendFlags_HasMouseCursors) because it needs mouse cursor feedback. (This used to be the ImGuiWindowFlags_ResizeFromAnySide flag)
|
||||
|
||||
//------------------------------------------------------------------
|
||||
// Settings (User Functions)
|
||||
|
@ -1490,6 +1490,7 @@ namespace ImGui
|
||||
inline bool IsNavInputPressedAnyOfTwo(ImGuiNavInput n1, ImGuiNavInput n2, ImGuiInputReadMode mode) { return (GetNavInputAmount(n1, mode) + GetNavInputAmount(n2, mode)) > 0.0f; }
|
||||
|
||||
// Docking
|
||||
// (some functions are only declared in imgui.cpp, see Docking section)
|
||||
IMGUI_API void DockContextInitialize(ImGuiContext* ctx);
|
||||
IMGUI_API void DockContextShutdown(ImGuiContext* ctx);
|
||||
IMGUI_API void DockContextOnLoadSettings(ImGuiContext* ctx);
|
||||
|
Loading…
Reference in New Issue
Block a user