2.6 KiB
2.6 KiB
Docking Layout Design
Overview
A custom WinUI 3 docking layout system for GhostEngine's editor, inspired by WinUI.Dock but tailored to support Unity/Blender-style region highlighting and dynamic tab creation.
Architecture & Components
The system uses a UI-driven approach where custom controls manage their own state and visual tree.
DockingLayout: The root control. Manages the overall state, drag-and-drop coordination, and floating windows.DockPanel: A container that splits its area horizontally or vertically (using aGridwithGridSplitters).DockGroup: A container that holds multiple documents, rendered as a WinUI 3TabView.DockDocument: The actual content item, representing a single tab and its payload.FloatingWindow: A separate WinUIWindowthat hosts a minimalDockingLayoutinternally for torn-off tabs.DockRegionHighlight: A visual overlay control (e.g., a semi-transparent blue rectangle) used during drag-and-drop to show exactly where the drop will occur (Left, Right, Top, Bottom, or Center).
Drag and Drop Flow
- Start: Dragging a
TabViewIteminitiates a drag operation. We store a reference to the draggedDockDocument. - Over: As the pointer moves over a
DockGrouporDockPanel, we calculate the relative pointer position to determine the target region (Left 25%, Right 25%, Top 25%, Bottom 25%, or Center 50%). We display theDockRegionHighlightover that specific area. - Drop:
- If dropped on an edge region (Left/Right/Top/Bottom), we split the target container: we create a new
DockPanel, move the existing content to one side, and place the dragged document on the other. - If dropped in the Center of a
DockGroup, we add the document as a new tab to that group. - If dropped outside the main window bounds, we create a new
FloatingWindowand place the document inside it.
- If dropped on an edge region (Left/Right/Top/Bottom), we split the target container: we create a new
Dynamic Creation API
The DockingLayout will expose methods to allow programmatically adding new panels or tabs at runtime (e.g., for a "plus icon" scenario).
public void AddDocument(DockDocument document, DockTarget target, DockGroup? targetGroup = null);
Implementation Details
- The controls will be created under
src\Editor\Ghost.Editor\View\Controls\Docking\. - We will use WinUI 3's built-in drag and drop APIs (
CanDrag,DragStarting,AllowDrop,DragOver,Drop). - The
DockRegionHighlightwill be aBorderorRectangleadded to theDockingLayout's visual tree (e.g., in aPopupor an overlayGrid) and positioned absolutely based on the current drag target.