namespace UCVL.VPNPlus; internal sealed partial class MainForm { // A compact logical canvas; native DPI scaling still happens exactly once. private bool CompactPresentation => ClientSize.Width < ScaleLogical(720) || ClientSize.Height < ScaleLogical(550); private readonly Font _compactStatusFont=Brand.Font(9.5f,FontStyle.Bold); private readonly Font _compactChartFont=Brand.Font(7.5f); private readonly Font _compactRowFont=Brand.Font(8f,FontStyle.Bold); private readonly Dictionary _presentationFonts = new(); private bool _presentationFontsDisposed; protected override void Dispose(bool disposing) { base.Dispose(disposing); if(!disposing || _presentationFontsDisposed)return; _presentationFontsDisposed=true; foreach(var fonts in _presentationFonts.Values)fonts.Compact?.Dispose(); _presentationFonts.Clear(); _compactStatusFont.Dispose(); _compactChartFont.Dispose(); _compactRowFont.Dispose(); } private void SetStatusTitleFont(float size) { if(ReferenceEquals(_statusTitle.Font,_compactStatusFont))return; var previous=_statusTitle.Font; _statusTitle.Font=_compactStatusFont; if(!ReferenceEquals(previous,_compactStatusFont))previous.Dispose(); } private void ApplyCompactTypography() { void Visit(Control parent, bool dashboardTypography=false) { foreach (Control control in parent.Controls) { if (control is CaptionButton || ReferenceEquals(control,_statusTitle)) continue; if (!_presentationFonts.TryGetValue(control, out var fonts)) { var original = control.Font; fonts = (original, new Font(original.FontFamily, Math.Max(7.5f, original.SizeInPoints * .78f), original.Style)); _presentationFonts.Add(control, fonts); } var dashboard = dashboardTypography || ReferenceEquals(control,_dashboardBody) || ReferenceEquals(control,_welcomeLabel) || ReferenceEquals(control,_logoutButton); control.Font = CompactPresentation || dashboard ? fonts.Compact! : fonts.Original; Visit(control,dashboard); } } Visit(this); } private void LayoutCompactHeader() { int S(int n) => ScaleLogical(n); _brandHeader.Height=S(48); foreach(Control control in _brandHeader.Controls) { if(control.Tag is not Rectangle)continue; if(control is PictureBox)control.Bounds=new(S(8),S(6),S(34),S(36)); else if(control is Label label && label.Text=="纵横家")control.Bounds=new(S(48),S(6),S(176),S(26)); else control.Bounds=new(S(49),S(31),S(180),S(14)); } _headerPoem.Visible=false; LayoutWindowChrome(); if (_welcomeLabel.Parent == _brandHeader) { _welcomeLabel.Visible=_dashboardView.Visible; _logoutButton.Visible=_dashboardView.Visible; } } private void LayoutCompactLogin() { int S(int n)=>ScaleLogical(n); _loginView.Size=new(S(400),S(280)); foreach(Control control in _loginView.Controls) if(control.Tag is Rectangle r) control.Bounds=new(S((int)Math.Round(r.X*400d/440)),S((int)Math.Round(r.Y*.72)), S((int)Math.Round(r.Width*400d/440)),S(Math.Max(14,(int)Math.Round(r.Height*.72)))); // Text boxes and the primary action keep comfortable compact hit areas. _loginText.Parent!.Bounds=new(S(25),S(65),S(350),S(29)); _passwordText.Parent!.Bounds=new(S(25),S(117),S(350),S(29)); _loginButton.Bounds=new(S(25),S(160),S(350),S(31)); var flags=TextFormatFlags.SingleLine; var prompt=TextRenderer.MeasureText(_registerPrompt.Text,_registerPrompt.Font,Size.Empty,flags); var link=TextRenderer.MeasureText(_registerLink.Text,_registerLink.Font,Size.Empty,flags); var rowWidth=prompt.Width+link.Width+S(16); var left=(_loginView.Width-rowWidth)/2; _registerPrompt.Bounds=new(left,S(199),prompt.Width+S(4),S(20)); _registerLink.Bounds=new(_registerPrompt.Right+S(8),S(199),link.Width+S(4),S(20)); foreach(Control control in _loginView.Controls) { if(control is Label label && label.Text.StartsWith("浏览器完成注册"))control.Bounds=new(S(20),S(226),S(360),S(18)); } _loginError.Bounds=new(S(20),S(248),S(360),S(24)); _loginView.Left=Math.Max(S(8),(_content.Width-_loginView.Width)/2); _loginView.Top=Math.Max(S(8),(_content.Height-_loginView.Height)/2); } private void LayoutCompactDashboard(DashboardGeometry layout) { int S(int n)=>ScaleLogical(n); Rectangle R(int x,int y,int w,int h)=>new(S(x),S(y),S(w),S(h)); if (CompactPresentation) { _welcomeLabel.Parent=_brandHeader; _logoutButton.Parent=_brandHeader; var caption = _windowChrome!.MinimizeButton.Bounds; _logoutButton.Bounds=new(caption.Left-S(72),caption.Top,S(64),caption.Height); _welcomeLabel.Bounds=new(_logoutButton.Left-S(126),caption.Top,S(118),caption.Height); _welcomeLabel.Visible=_logoutButton.Visible=_dashboardView.Visible; _accountLabel.Visible=_identityBadge.Visible=false; } else { _welcomeLabel.Parent=_dashboardBody; _logoutButton.Parent=_dashboardBody; _welcomeLabel.Bounds=layout.WelcomeLabel; _logoutButton.Bounds=layout.LogoutButton; _welcomeLabel.Visible=_logoutButton.Visible=_accountLabel.Visible=_identityBadge.Visible=true; } _statusDot.Bounds=R(10,4,22,22); _connectButton.Bounds=new(_statusCard.Width-S(80),S(3),S(70),S(24)); _statusTitle.Bounds=new(S(40),0,_statusCard.Width-S(130),S(16)); _statusDetail.Bounds=new(S(40),S(16),_statusCard.Width-S(130),S(13)); _nodeIcon.Visible=_modeIcon.Visible=false; _scheduleBadge.Visible=false; var leftWidth=_modeCard.Left-S(8); _selectionHeading.Bounds=R(10,1,27,20); _routeHeading.Bounds=R(10,23,27,20); _routeHeading.Text="模式"; var fieldLeft=S(38); var fieldWidth=leftWidth-fieldLeft; var splitWidth=Math.Max(S(84),(fieldWidth-S(4))/2); _connectionModeCombo.Bounds=new(fieldLeft,S(1),_manualNodeCombo.Visible?splitWidth:fieldWidth,S(20)); _manualNodeCombo.Bounds=new(_connectionModeCombo.Right+S(4),S(1),Math.Max(S(60),fieldWidth-splitWidth-S(4)),S(20)); _routeCombo.Bounds=new(fieldLeft,S(23),fieldWidth,S(20)); _nodeHeading.Text="节点"; _nodeHeading.Bounds=R(8,1,27,20); _currentNodeLabel.Bounds=new(S(39),S(1),_modeCard.Width-S(41),S(20)); _actualModeHeading.Bounds=R(8,23,27,20); _routeReadOnly.Bounds=new(S(39),S(23),_modeCard.Width-S(41),S(20)); foreach(var label in new[]{_selectionHeading,_routeHeading,_nodeHeading,_actualModeHeading,_currentNodeLabel}) { label.TextAlign=ContentAlignment.MiddleLeft; label.Padding=Padding.Empty; } _trafficIcon.Visible=_dailyIcon.Visible=_tailnetTrafficIcon.Visible=false; _trafficHeading.Bounds=new(S(10),0,S(106),_trafficCard.Height-S(2)); _dailyHeading.Bounds=new(S(10),0,S(106),_dailyCard.Height-S(2)); _tailnetTrafficHeading.Text="Tailscale 速度"; _tailnetTrafficHeading.Bounds=new(S(10),0,S(106),_tailnetTrafficCard.Height-S(2)); foreach(var heading in new[]{_trafficHeading,_tailnetTrafficHeading,_dailyHeading}) { heading.Font=_compactRowFont; heading.TextAlign=ContentAlignment.MiddleLeft; } if(_tailnetTrafficVisible) { _tailnetUploadMetric.Bounds=_uploadMetric.Bounds; _tailnetDownloadMetric.Bounds=_downloadMetric.Bounds; } _trendHeading.Bounds=new(S(10),S(2),_speedTrendCard.Width-S(120),S(20)); _trendHeading.TextAlign=ContentAlignment.MiddleLeft; _historyRangeCombo.Bounds=new(_speedTrendCard.Width-S(98),S(2),S(88),S(20)); _trafficChart.Font=_compactChartFont; _trafficChart.Bounds=new(S(8),S(24),_speedTrendCard.Width-S(16),Math.Max(S(22),_speedTrendCard.Height-S(28))); _uploadLegend.Visible=_downloadLegend.Visible=_historyStatus.Visible=false; _sampleLabel.Visible=false; _planLabel.Visible=false; _expiryLabel.Bounds=new(0,0,S(96),S(17)); _footerCompanySite.Bounds=new(S(100),0,S(145),S(17)); _footerHint.Bounds=new(_footer.Width-S(212),0,S(212),S(17)); _footerPoem.Visible=false; _footerHint.Visible=true; _dashboardBody.Size=_dashboardView.ClientSize; _dashboardBody.Location=Point.Empty; } }