Esempio n. 1
0
        public static async Task <bool> EnableAsync(Window window, EdgeType direction)
        {
            if (direction.IsCorner())
            {
                throw new ArgumentException($"{nameof(direction)} cannot be a corner");
            }
            if (HiddenWindows.ContainsKey(window))
            {
                Notification($"{window.Title}\nis already in a hide animation");
                return(false);
            }

            if (direction.IsNone() is bool manual && manual)
            {
                direction = await GetInput();

                if (direction.IsNone())
                {
                    return(false);
                }
            }

            window.Restore();
            var monitor = window.Monitor.Area;
            var hider   = new WindowDocker(window);

            hider.IsAlwaysOnTop = window.IsAlwaysOnTop;
            hider.ActiveArea    = hider.HiddenArea = window.Area;

            hider.ActiveArea  = hider.ActiveArea.SetEdge(monitor.GetEdge(direction));
            hider.HiddenArea  = hider.HiddenArea.SetEdge(direction.Reverse(), monitor.GetEdge(direction).Pos);
            hider.PreviewArea = hider.HiddenArea.SetEdge(direction, direction.IsTopOrLeft() ? previewWidth : -previewWidth, relative: true);
            hider.PeekArea    = hider.HiddenArea.SetEdge(direction, direction.IsTopOrLeft() ? peekWidth : -peekWidth, relative: true);

            if (manual)
            {
                Notification("Hide animation set succesfully");
            }
            HiddenWindows.Add(window, hider);
            Program.OnExit += hider.Deactivate;
            window.SetAlwaysOnTop(true);
            hider.State = false;
            hider.Hide();
            hider.Loop();

            return(true);
        }