public void Shrink(ShrinkFromDirections direction, double amountInPx) { Log.InfoFormat("Shrink called with direction {0} and amount (px) {1}", direction, amountInPx); var windowState = getWindowState(); if (windowState == WindowStates.Maximised) return; var distanceToBottomBoundary = screenBoundsInDp.Bottom - (window.Top + window.ActualHeight); var yAdjustment = amountInPx / Graphics.DipScalingFactorY; var yAdjustmentFromBottom = distanceToBottomBoundary < 0 ? distanceToBottomBoundary : 0 - yAdjustment; var distanceToTopBoundary = window.Top - screenBoundsInDp.Top; var yAdjustmentFromTop = distanceToTopBoundary < 0 ? distanceToTopBoundary : 0 - yAdjustment; var distanceToLeftBoundary = window.Left - screenBoundsInDp.Left; var xAdjustment = amountInPx / Graphics.DipScalingFactorX; var xAdjustmentFromLeft = distanceToLeftBoundary < 0 ? distanceToLeftBoundary : 0 - xAdjustment; var distanceToRightBoundary = screenBoundsInDp.Right - (window.Left + window.ActualWidth); var xAdjustmentFromRight = distanceToRightBoundary < 0 ? distanceToRightBoundary : 0 - xAdjustment; switch (windowState) { case WindowStates.Floating: var maxFloatingHeightAdjustment = window.Height - ((MIN_FLOATING_HEIGHT_AS_PERCENTAGE_OF_SCREEN / 100) * screenBoundsInDp.Height); switch (direction) //Handle vertical adjustment { case ShrinkFromDirections.Bottom: case ShrinkFromDirections.BottomLeft: case ShrinkFromDirections.BottomRight: yAdjustmentFromBottom = yAdjustmentFromBottom.CoerceToLowerLimit(0 - maxFloatingHeightAdjustment); window.Height += yAdjustmentFromBottom; break; case ShrinkFromDirections.Top: case ShrinkFromDirections.TopLeft: case ShrinkFromDirections.TopRight: var heightBeforeAdjustment = window.ActualHeight; yAdjustmentFromTop = yAdjustmentFromTop.CoerceToLowerLimit(0 - maxFloatingHeightAdjustment); window.Height += yAdjustmentFromTop; var actualYAdjustmentToTop = window.ActualHeight - heightBeforeAdjustment; //WPF may have coerced the adjustment window.Top -= actualYAdjustmentToTop; break; } var maxFloatingWidthAdjustment = window.Width - ((MIN_FLOATING_WIDTH_AS_PERCENTAGE_OF_SCREEN / 100) * screenBoundsInDp.Width); switch (direction) //Handle horizontal adjustment { case ShrinkFromDirections.Left: case ShrinkFromDirections.BottomLeft: case ShrinkFromDirections.TopLeft: var widthBeforeAdjustment = window.ActualWidth; xAdjustmentFromLeft = xAdjustmentFromLeft.CoerceToLowerLimit(0 - maxFloatingWidthAdjustment); window.Width += xAdjustmentFromLeft; var actualXAdjustmentToLeft = window.ActualWidth - widthBeforeAdjustment; //WPF may have coerced the adjustment window.Left -= actualXAdjustmentToLeft; break; case ShrinkFromDirections.Right: case ShrinkFromDirections.BottomRight: case ShrinkFromDirections.TopRight: xAdjustmentFromRight = xAdjustmentFromRight.CoerceToLowerLimit(0 - maxFloatingWidthAdjustment); window.Width += xAdjustmentFromRight; break; } PersistSizeAndPosition(); break; case WindowStates.Docked: var dockPosition = getDockPosition(); var dockSize = getDockSize(); var adjustment = false; var maxFullDockHeightAdjustment = window.Height - ((MIN_FULL_DOCK_THICKNESS_AS_PERCENTAGE_OF_SCREEN / 100) * screenBoundsInDp.Height); var maxFullDockWidthAdjustment = window.Width - ((MIN_FULL_DOCK_THICKNESS_AS_PERCENTAGE_OF_SCREEN / 100) * screenBoundsInDp.Width); var maxCollapsedDockHeightAdjustment = window.Height - ((MIN_COLLAPSED_DOCK_THICKNESS_AS_PERCENTAGE_OF_FULL_DOCK_THICKNESS / 100) * ((getCollapsedDockThicknessAsPercentageOfFullDockThickness() / 100) * screenBoundsInDp.Height)); var maxCollapsedDockWidthAdjustment = window.Width - ((MIN_COLLAPSED_DOCK_THICKNESS_AS_PERCENTAGE_OF_FULL_DOCK_THICKNESS / 100) * ((getCollapsedDockThicknessAsPercentageOfFullDockThickness() / 100) * screenBoundsInDp.Width)); if (dockPosition == DockEdges.Top && (direction == ShrinkFromDirections.Bottom || direction == ShrinkFromDirections.BottomLeft || direction == ShrinkFromDirections.BottomRight)) { if (dockSize == DockSizes.Full) { yAdjustmentFromBottom = yAdjustmentFromBottom.CoerceToLowerLimit(0 - maxFullDockHeightAdjustment); saveFullDockThicknessAsPercentageOfScreen(((window.ActualHeight + yAdjustmentFromBottom) / screenBoundsInDp.Height) * 100); } else { yAdjustmentFromBottom = yAdjustmentFromBottom.CoerceToLowerLimit(0 - maxCollapsedDockHeightAdjustment); saveCollapsedDockThicknessAsPercentageOfFullDockThickness(((window.ActualHeight + yAdjustmentFromBottom) / screenBoundsInDp.Height) * getFullDockThicknessAsPercentageOfScreen()); } adjustment = true; } else if (dockPosition == DockEdges.Bottom && (direction == ShrinkFromDirections.Top || direction == ShrinkFromDirections.TopLeft || direction == ShrinkFromDirections.TopRight)) { if (dockSize == DockSizes.Full) { yAdjustmentFromTop = yAdjustmentFromTop.CoerceToLowerLimit(0 - maxFullDockHeightAdjustment); saveFullDockThicknessAsPercentageOfScreen(((window.ActualHeight + yAdjustmentFromTop) / screenBoundsInDp.Height) * 100); } else { yAdjustmentFromTop = yAdjustmentFromTop.CoerceToLowerLimit(0 - maxCollapsedDockHeightAdjustment); saveCollapsedDockThicknessAsPercentageOfFullDockThickness(((window.ActualHeight + yAdjustmentFromTop) / screenBoundsInDp.Height) * getFullDockThicknessAsPercentageOfScreen()); } adjustment = true; } else if (dockPosition == DockEdges.Left && (direction == ShrinkFromDirections.Right || direction == ShrinkFromDirections.TopRight || direction == ShrinkFromDirections.BottomRight)) { if (dockSize == DockSizes.Full) { xAdjustmentFromRight = xAdjustmentFromRight.CoerceToLowerLimit(0 - maxFullDockWidthAdjustment); saveFullDockThicknessAsPercentageOfScreen(((window.ActualWidth + xAdjustmentFromRight) / screenBoundsInDp.Width) * 100); } else { xAdjustmentFromRight = xAdjustmentFromRight.CoerceToLowerLimit(0 - maxCollapsedDockWidthAdjustment); saveCollapsedDockThicknessAsPercentageOfFullDockThickness(((window.ActualWidth + xAdjustmentFromRight) / screenBoundsInDp.Width) * getFullDockThicknessAsPercentageOfScreen()); } adjustment = true; } else if (dockPosition == DockEdges.Right && (direction == ShrinkFromDirections.Left || direction == ShrinkFromDirections.TopLeft || direction == ShrinkFromDirections.BottomLeft)) { if (dockSize == DockSizes.Full) { xAdjustmentFromLeft = xAdjustmentFromLeft.CoerceToLowerLimit(0 - maxFullDockWidthAdjustment); saveFullDockThicknessAsPercentageOfScreen(((window.ActualWidth + xAdjustmentFromLeft) / screenBoundsInDp.Width) * 100); } else { xAdjustmentFromLeft = xAdjustmentFromLeft.CoerceToLowerLimit(0 - maxCollapsedDockWidthAdjustment); saveCollapsedDockThicknessAsPercentageOfFullDockThickness(((window.ActualWidth + xAdjustmentFromLeft) / screenBoundsInDp.Width) * getFullDockThicknessAsPercentageOfScreen()); } adjustment = true; } if (adjustment) { var dockSizeAndPositionInPx = CalculateDockSizeAndPositionInPx(getDockPosition(), getDockSize()); SetAppBarSizeAndPosition(getDockPosition(), dockSizeAndPositionInPx); } break; } }
public void Shrink(ShrinkFromDirections direction, double amountInPx) { var windowState = getWindowState(); if (windowState == WindowStates.Maximised) return; var distanceToBottomBoundary = screenBoundsInDp.Bottom - (window.Top + window.ActualHeight); var yAdjustmentFromBottom = distanceToBottomBoundary < 0 ? distanceToBottomBoundary : 0 - (amountInPx / Graphics.DipScalingFactorY); var distanceToTopBoundary = window.Top - screenBoundsInDp.Top; var yAdjustmentFromTop = distanceToTopBoundary < 0 ? distanceToTopBoundary : 0 - (amountInPx / Graphics.DipScalingFactorY); var distanceToLeftBoundary = window.Left - screenBoundsInDp.Left; var xAdjustmentFromLeft = distanceToLeftBoundary < 0 ? distanceToLeftBoundary : 0 - (amountInPx / Graphics.DipScalingFactorX); var distanceToRightBoundary = screenBoundsInDp.Right - (window.Left + window.ActualWidth); var xAdjustmentFromRight = distanceToRightBoundary < 0 ? distanceToRightBoundary : 0 - (amountInPx / Graphics.DipScalingFactorX); switch (windowState) { case WindowStates.Floating: switch (direction) //Handle vertical adjustment { case ShrinkFromDirections.Bottom: case ShrinkFromDirections.BottomLeft: case ShrinkFromDirections.BottomRight: window.Height += yAdjustmentFromBottom; break; case ShrinkFromDirections.Top: case ShrinkFromDirections.TopLeft: case ShrinkFromDirections.TopRight: var heightBeforeAdjustment = window.ActualHeight; window.Height += yAdjustmentFromTop; var actualYAdjustmentToTop = window.ActualHeight - heightBeforeAdjustment; //WPF may have coerced the adjustment window.Top -= actualYAdjustmentToTop; break; } switch (direction) //Handle horizontal adjustment { case ShrinkFromDirections.Left: case ShrinkFromDirections.BottomLeft: case ShrinkFromDirections.TopLeft: var widthBeforeAdjustment = window.ActualWidth; window.Width += xAdjustmentFromLeft; var actualXAdjustmentToLeft = window.ActualWidth - widthBeforeAdjustment; //WPF may have coerced the adjustment window.Left -= actualXAdjustmentToLeft; break; case ShrinkFromDirections.Right: case ShrinkFromDirections.BottomRight: case ShrinkFromDirections.TopRight: window.Width += xAdjustmentFromRight; break; } PersistSizeAndPosition(); break; case WindowStates.Docked: var dockPosition = getDockPosition(); var dockSize = getDockSize(); var adjustment = false; if (dockPosition == DockEdges.Top && (direction == ShrinkFromDirections.Bottom || direction == ShrinkFromDirections.BottomLeft || direction == ShrinkFromDirections.BottomRight)) { if (dockSize == DockSizes.Full) { saveFullDockThicknessAsPercentageOfScreen(((window.ActualHeight + yAdjustmentFromBottom) / screenBoundsInDp.Height) * 100); } else { saveCollapsedDockThicknessAsPercentageOfFullDockThickness(((window.ActualHeight + yAdjustmentFromBottom) / screenBoundsInDp.Height) * getFullDockThicknessAsPercentageOfScreen()); } adjustment = true; } else if (dockPosition == DockEdges.Bottom && (direction == ShrinkFromDirections.Top || direction == ShrinkFromDirections.TopLeft || direction == ShrinkFromDirections.TopRight)) { if (dockSize == DockSizes.Full) { saveFullDockThicknessAsPercentageOfScreen(((window.ActualHeight + yAdjustmentFromTop) / screenBoundsInDp.Height) * 100); } else { saveCollapsedDockThicknessAsPercentageOfFullDockThickness(((window.ActualHeight + yAdjustmentFromTop) / screenBoundsInDp.Height) * getFullDockThicknessAsPercentageOfScreen()); } adjustment = true; } else if (dockPosition == DockEdges.Left && (direction == ShrinkFromDirections.Right || direction == ShrinkFromDirections.TopRight || direction == ShrinkFromDirections.BottomRight)) { if (dockSize == DockSizes.Full) { saveFullDockThicknessAsPercentageOfScreen(((window.ActualWidth + xAdjustmentFromRight) / screenBoundsInDp.Width) * 100); } else { saveCollapsedDockThicknessAsPercentageOfFullDockThickness(((window.ActualWidth + xAdjustmentFromRight) / screenBoundsInDp.Width) * getFullDockThicknessAsPercentageOfScreen()); } adjustment = true; } else if (dockPosition == DockEdges.Right && (direction == ShrinkFromDirections.Left || direction == ShrinkFromDirections.TopLeft || direction == ShrinkFromDirections.BottomLeft)) { if (dockSize == DockSizes.Full) { saveFullDockThicknessAsPercentageOfScreen(((window.ActualWidth + xAdjustmentFromLeft) / screenBoundsInDp.Width) * 100); } else { saveCollapsedDockThicknessAsPercentageOfFullDockThickness(((window.ActualWidth + xAdjustmentFromLeft) / screenBoundsInDp.Width) * getFullDockThicknessAsPercentageOfScreen()); } adjustment = true; } if (adjustment) { var dockSizeAndPositionInPx = CalculateDockSizeAndPositionInPx(getDockPosition(), getDockSize()); SetAppBarSizeAndPosition(getDockPosition(), dockSizeAndPositionInPx); } break; } }