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(10,FontStyle.Bold); private readonly Font _compactChartFont=Brand.Font(6.5f); 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(); } private void SetStatusTitleFont(float size) { if(CompactPresentation && ReferenceEquals(_statusTitle.Font,_compactStatusFont))return; if(!CompactPresentation && !ReferenceEquals(_statusTitle.Font,_compactStatusFont) && Math.Abs(_statusTitle.Font.SizeInPoints-size)<.1f)return; var previous=_statusTitle.Font; _statusTitle.Font=CompactPresentation?_compactStatusFont:Brand.Font(size,FontStyle.Bold); if(!ReferenceEquals(previous,_compactStatusFont))previous.Dispose(); } private void ApplyCompactTypography() { void Visit(Control parent) { 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(6.5f, original.SizeInPoints * .78f), original.Style)); _presentationFonts.Add(control, fonts); } control.Font = CompactPresentation ? fonts.Compact! : fonts.Original; Visit(control); } } 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(10),S(5),S(34),S(37)); else if(control is Label label && label.Text=="纵横家")control.Bounds=new(S(52),S(5),S(180),S(25)); else control.Bounds=new(S(53),S(28),S(260),S(15)); } _headerPoem.Visible=false; LayoutWindowChrome(); } 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)); _statusDot.Bounds=R(10,8,24,24); _connectButton.Bounds=new(_statusCard.Width-S(68),S(7),S(60),S(26)); _statusTitle.Bounds=new(S(42),S(1),_statusCard.Width-S(116),S(21)); _statusDetail.Bounds=new(S(42),S(22),_statusCard.Width-S(116),S(15)); _nodeIcon.Visible=_modeIcon.Visible=false; _nodeHeading.Bounds=R(8,0,122,15); _nodeHeading.Text="工作节点"; _connectionModeCombo.Bounds=new(_nodeCard.Width-S(102),S(1),S(96),S(18)); _manualNodeCombo.Bounds=new(S(8),S(22),_nodeCard.Width-S(16),S(19)); _currentNodeLabel.Bounds=new(S(8),S(23),_nodeCard.Width-S(16),S(17)); _scheduleBadge.Visible=false; _routeHeading.Bounds=new(S(8),0,_modeCard.Width-S(16),S(14)); _routeCombo.Bounds=new(S(8),S(14),_modeCard.Width-S(16),S(20)); _routeReadOnly.Bounds=_routeCombo.Bounds; _trafficIcon.Visible=_dailyIcon.Visible=_tailnetTrafficIcon.Visible=false; _trafficHeading.Bounds=new(S(6),0,_trafficCard.Width-S(12),S(13)); _dailyHeading.Bounds=new(S(7),S(2),_dailyCard.Width-S(14),S(17)); _tailnetTrafficHeading.Bounds=new(S(6),0,_tailnetTrafficCard.Width-S(12),S(13)); if(_tailnetTrafficVisible) { var width=(_tailnetTrafficCard.Width-S(8))/2; _tailnetUploadMetric.Bounds=new(S(4),S(11),width-S(1),S(18)); _tailnetDownloadMetric.Bounds=new(S(4)+width,S(11),width-S(1),S(18)); } _trendHeading.Bounds=new(S(6),0,_speedTrendCard.Width-S(88),S(15)); _historyRangeCombo.Bounds=new(_speedTrendCard.Width-S(82),0,S(77),S(19)); _trafficChart.Font=_compactChartFont; _trafficChart.Bounds=new(S(1),S(18),_speedTrendCard.Width-S(3),Math.Max(S(30),_speedTrendCard.Height-S(19))); _uploadLegend.Visible=_downloadLegend.Visible=_historyStatus.Visible=false; _sampleLabel.Visible=false; _planLabel.Bounds=new(0,0,_footer.Width-S(75),S(11)); _expiryLabel.Bounds=new(_footer.Width-S(72),0,S(72),S(11)); _footerCompanySite.Bounds=new(0,S(11),S(210),S(11)); _footerHint.Bounds=new(_footer.Width-S(205),S(11),S(205),S(11)); _footerPoem.Visible=false; _dashboardBody.Size=_dashboardView.ClientSize; _dashboardBody.Location=Point.Empty; } }