// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. using System.Collections.Generic; using FlaxEngine; namespace FlaxEditor.GUI.Docking { /// /// Master Dock Panel control used as a root control for dockable windows workspace. /// /// public class MasterDockPanel : DockPanel { /// /// Array with all created dock windows for that master panel. /// public readonly List Windows = new List(32); /// /// Array with all floating windows for that master panel. /// public readonly List FloatingPanels = new List(4); /// /// Gets the visible windows count. /// /// /// The visible windows count. /// public int VisibleWindowsCount { get { int result = 0; for (int i = 0; i < Windows.Count; i++) { if (Windows[i].Visible) result++; } return result; } } /// /// Initializes a new instance of the class. /// public MasterDockPanel() : base(null) { } /// /// Resets windows layout. /// public void ResetLayout() { // Close all windows var windows = Windows.ToArray(); for (int i = 0; i < windows.Length; i++) windows[i].Close(); // Ensure that has no docked windows var childPanels = ChildPanels.ToArray(); for (int i = 0; i < childPanels.Length; i++) childPanels[i].Dispose(); // Delete remaining controls (except tabs proxy) if (TabsProxy != null) TabsProxy.Parent = null; DisposeChildren(); if (TabsProxy != null) TabsProxy.Parent = this; } /// /// Performs hit test over dock panel. /// /// Screen space position to test. /// Floating window to omit during searching (and all docked to that one). /// Dock panel that has been hit or null if nothing found. public DockPanel HitTest(ref Float2 position, FloatWindowDockPanel excluded) { // Check all floating windows // TODO: gather windows order and take it into account when performing test for (int i = 0; i < FloatingPanels.Count; i++) { var win = FloatingPanels[i]; if (win.Visible && win != excluded) { var result = win.HitTest(ref position); if (result != null) return result; } } // Base return base.HitTest(ref position); } internal void LinkWindow(DockWindow window) { // Add to the windows list Windows.Add(window); } internal void UnlinkWindow(DockWindow window) { // Call event to the window window.OnUnlinkInternal(); // Prevent this action during disposing (we don't want to modify Windows list) if (IsDisposing) return; // Remove from the windows list Windows.Remove(window); } /// public override bool IsMaster => true; /// public override void OnDestroy() { base.OnDestroy(); Windows.Clear(); FloatingPanels.Clear(); } /// public override DockState TryGetDockState(out float splitterValue) { splitterValue = 0.5f; return DockState.DockFill; } } }