Private/Presentation/ResponsiveLayout.ps1
|
function Get-ResponsiveLayoutPlan { [CmdletBinding()] param( [Parameter(Mandatory)] [ValidateRange(1, [double]::MaxValue)] [double]$WorkAreaWidthPixels, [Parameter(Mandatory)] [ValidateRange(1, [double]::MaxValue)] [double]$WorkAreaHeightPixels, [ValidateRange(0.1, [double]::MaxValue)] [double]$DpiScaleX = 1, [ValidateRange(0.1, [double]::MaxValue)] [double]$DpiScaleY = 1 ) $widthDip = [int][Math]::Floor($WorkAreaWidthPixels / $DpiScaleX) $heightDip = [int][Math]::Floor($WorkAreaHeightPixels / $DpiScaleY) $belowSupportedWorkArea = $widthDip -lt 800 -or $heightDip -lt 500 $isCompact = $widthDip -lt 1050 -or $heightDip -lt 650 $mode = if ($isCompact) { 'Compact' } elseif ($widthDip -lt 1600 -or $heightDip -lt 900) { 'Standard' } else { 'Wide' } [pscustomobject]@{ LayoutMode = $mode WorkAreaWidthDip = $widthDip WorkAreaHeightDip = $heightDip IsBelowSupportedWorkArea = $belowSupportedWorkArea PrimaryControlsReachable = -not $belowSupportedWorkArea SidePanelMode = if ($isCompact) { 'collapsed' } else { 'docked' } DashboardTopMinHeight = if ($isCompact) { 140 } else { 200 } DashboardBottomMinHeight = if ($isCompact) { 120 } else { 200 } } } function Set-ResponsiveDashboardLayout { [CmdletBinding()] param( [Parameter(Mandatory)] [psobject]$LayoutPlan, [Parameter(Mandatory)] [System.Windows.Controls.Grid]$DashboardGrid, [Parameter(Mandatory)] [System.Windows.Controls.Border]$MarketDataPanel, [Parameter(Mandatory)] [System.Windows.FrameworkElement]$WorldClocksPanel, [switch]$ShowMarketData, [switch]$ShowWorldClocks ) if ($DashboardGrid.ColumnDefinitions.Count -lt 2) { throw 'The responsive dashboard grid must define a main column and a world-clocks column.' } $DashboardGrid.ColumnDefinitions[1].Width = if ($ShowWorldClocks) { [System.Windows.GridLength]::new(200) } else { [System.Windows.GridLength]::new(0) } $WorldClocksPanel.Visibility = if ($ShowWorldClocks) { 'Visible' } else { 'Collapsed' } $MarketDataPanel.Visibility = if ($ShowMarketData) { 'Visible' } else { 'Collapsed' } if ($DashboardGrid.RowDefinitions.Count -ge 3) { $DashboardGrid.RowDefinitions[0].MinHeight = $LayoutPlan.DashboardTopMinHeight $DashboardGrid.RowDefinitions[2].MinHeight = $LayoutPlan.DashboardBottomMinHeight } $LayoutPlan } function Get-MarketDataPanelWidth { <# .SYNOPSIS Returns a clamped market data panel width after a resize drag. #> param( [Parameter(Mandatory)][double]$CurrentWidth, [Parameter(Mandatory)][double]$HorizontalChange, [double]$AvailableWidth = 0, [double]$MinimumWidth = 260 ) $maximum = if ($AvailableWidth -gt 0) { [Math]::Max($MinimumWidth, $AvailableWidth * 0.8) } else { [double]::MaxValue } [Math]::Round([Math]::Min($maximum, [Math]::Max($MinimumWidth, $CurrentWidth + $HorizontalChange))) } |