2026-11-13 10:35:04 +08:00
|
|
|
namespace UCVL.VPNPlus;
|
2026-11-02 04:13:58 +00:00
|
|
|
|
|
|
|
|
internal sealed partial class MainForm
|
|
|
|
|
{
|
|
|
|
|
// A compact logical canvas; native DPI scaling still happens exactly once.
|
2026-11-13 10:35:04 +08:00
|
|
|
private bool WideDashboardPresentation => ClientSize.Width >= ScaleLogical(840) && ClientSize.Height >= ScaleLogical(480);
|
|
|
|
|
private bool CompactPresentation => !WideDashboardPresentation;
|
2026-11-03 15:15:23 +00:00
|
|
|
private readonly Font _compactStatusFont=Brand.Font(9.5f,FontStyle.Bold);
|
2026-11-15 22:17:39 +08:00
|
|
|
private readonly Font _wideStatusFont=Brand.Font(17f,FontStyle.Bold);
|
|
|
|
|
private readonly Font _denseStatusFont=Brand.Font(15f,FontStyle.Bold);
|
2026-11-13 10:35:04 +08:00
|
|
|
private readonly Font _wideChartFont=Brand.Font(9f);
|
2026-11-03 15:15:23 +00:00
|
|
|
private readonly Font _compactChartFont=Brand.Font(7.5f);
|
2026-11-13 10:35:04 +08:00
|
|
|
private readonly Font _compactFieldFont=Brand.Font(7.5f, FontStyle.Bold);
|
|
|
|
|
private readonly Font _compactStatusDetailFont=Brand.Font(7.5f);
|
2026-11-05 03:41:46 +00:00
|
|
|
private readonly Font _compactRowFont=Brand.Font(8f,FontStyle.Bold);
|
2026-11-13 10:35:04 +08:00
|
|
|
private readonly Font _narrowNodeFont=Brand.Font(9.5f, FontStyle.Bold);
|
|
|
|
|
private readonly Font _minimumNodeFont=Brand.Font(8.5f, FontStyle.Bold);
|
2026-11-02 04:13:58 +00:00
|
|
|
private readonly Dictionary<Control, (Font Original, Font? Compact)> _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();
|
2026-11-13 10:35:04 +08:00
|
|
|
_wideStatusFont.Dispose();
|
|
|
|
|
_denseStatusFont.Dispose();
|
|
|
|
|
_wideChartFont.Dispose();
|
2026-11-02 04:13:58 +00:00
|
|
|
_compactChartFont.Dispose();
|
2026-11-13 10:35:04 +08:00
|
|
|
_compactFieldFont.Dispose();
|
|
|
|
|
_compactStatusDetailFont.Dispose();
|
2026-11-05 03:41:46 +00:00
|
|
|
_compactRowFont.Dispose();
|
2026-11-13 10:35:04 +08:00
|
|
|
_narrowNodeFont.Dispose();
|
|
|
|
|
_minimumNodeFont.Dispose();
|
2026-11-02 04:13:58 +00:00
|
|
|
}
|
2026-11-13 10:35:04 +08:00
|
|
|
private void SetStatusTitleFont(bool wide, bool dense)
|
2026-11-02 04:13:58 +00:00
|
|
|
{
|
2026-11-13 10:35:04 +08:00
|
|
|
var selected = wide ? dense ? _denseStatusFont : _wideStatusFont : _compactStatusFont;
|
|
|
|
|
if (ReferenceEquals(_statusTitle.Font, selected)) return;
|
2026-11-02 04:13:58 +00:00
|
|
|
var previous=_statusTitle.Font;
|
2026-11-13 10:35:04 +08:00
|
|
|
_statusTitle.Font = selected;
|
|
|
|
|
if (!ReferenceEquals(previous, _compactStatusFont) && !ReferenceEquals(previous, _wideStatusFont)
|
|
|
|
|
&& !ReferenceEquals(previous, _denseStatusFont))
|
|
|
|
|
previous.Dispose();
|
2026-11-02 04:13:58 +00:00
|
|
|
}
|
|
|
|
|
private void ApplyCompactTypography()
|
|
|
|
|
{
|
2026-11-13 10:35:04 +08:00
|
|
|
void Visit(Control parent)
|
2026-11-02 04:13:58 +00:00
|
|
|
{
|
|
|
|
|
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;
|
2026-11-03 15:15:23 +00:00
|
|
|
fonts = (original, new Font(original.FontFamily, Math.Max(7.5f, original.SizeInPoints * .78f), original.Style));
|
2026-11-02 04:13:58 +00:00
|
|
|
_presentationFonts.Add(control, fonts);
|
|
|
|
|
}
|
2026-11-13 10:35:04 +08:00
|
|
|
control.Font = CompactPresentation ? fonts.Compact! : fonts.Original;
|
|
|
|
|
Visit(control);
|
2026-11-02 04:13:58 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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;
|
2026-11-05 03:41:46 +00:00
|
|
|
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));
|
2026-11-02 04:13:58 +00:00
|
|
|
}
|
|
|
|
|
_headerPoem.Visible=false;
|
|
|
|
|
LayoutWindowChrome();
|
2026-11-03 15:15:23 +00:00
|
|
|
if (_welcomeLabel.Parent == _brandHeader)
|
|
|
|
|
{
|
2026-11-15 22:17:39 +08:00
|
|
|
_welcomeLabel.Visible=false;
|
2026-11-03 15:15:23 +00:00
|
|
|
_logoutButton.Visible=_dashboardView.Visible;
|
|
|
|
|
}
|
2026-11-02 04:13:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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));
|
2026-11-03 15:15:23 +00:00
|
|
|
if (CompactPresentation)
|
|
|
|
|
{
|
|
|
|
|
_welcomeLabel.Parent=_brandHeader;
|
|
|
|
|
_logoutButton.Parent=_brandHeader;
|
2026-11-15 22:17:39 +08:00
|
|
|
_welcomeLabel.Visible=false;
|
|
|
|
|
_logoutButton.Visible=_dashboardView.Visible;
|
2026-11-13 10:35:04 +08:00
|
|
|
LayoutCompactDashboardActions();
|
2026-11-03 15:15:23 +00:00
|
|
|
_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);
|
2026-11-05 03:41:46 +00:00
|
|
|
_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));
|
2026-11-13 10:35:04 +08:00
|
|
|
_statusDetail.Font = _compactStatusDetailFont;
|
2026-11-02 04:13:58 +00:00
|
|
|
_nodeIcon.Visible=_modeIcon.Visible=false;
|
|
|
|
|
_scheduleBadge.Visible=false;
|
2026-11-03 15:15:23 +00:00
|
|
|
var leftWidth=_modeCard.Left-S(8);
|
2026-11-15 22:17:39 +08:00
|
|
|
_selectionHeading.Bounds=R(10,2,34,20);
|
|
|
|
|
_routeHeading.Bounds=R(10,22,34,20);
|
2026-11-03 15:15:23 +00:00
|
|
|
_routeHeading.Text="模式";
|
2026-11-15 22:17:39 +08:00
|
|
|
var fieldLeft=S(44); var fieldWidth=leftWidth-fieldLeft;
|
2026-11-03 15:15:23 +00:00
|
|
|
var splitWidth=Math.Max(S(84),(fieldWidth-S(4))/2);
|
2026-11-15 22:17:39 +08:00
|
|
|
_connectionModeCombo.Bounds=new(fieldLeft,S(2),_manualNodeCombo.Visible?splitWidth:fieldWidth,S(20));
|
|
|
|
|
_manualNodeCombo.Bounds=new(_connectionModeCombo.Right+S(4),S(2),Math.Max(S(60),fieldWidth-splitWidth-S(4)),S(20));
|
|
|
|
|
_routeCombo.Bounds=new(fieldLeft,S(22),fieldWidth,S(20));
|
2026-11-03 15:15:23 +00:00
|
|
|
_nodeHeading.Text="节点";
|
2026-11-15 22:17:39 +08:00
|
|
|
_nodeHeading.Bounds=R(10,2,34,20);
|
|
|
|
|
_currentNodeLabel.Bounds=new(fieldLeft,S(2),_modeCard.Width-fieldLeft-S(2),S(20));
|
|
|
|
|
_actualModeHeading.Bounds=R(10,22,34,20);
|
|
|
|
|
_routeReadOnly.Bounds=new(fieldLeft,S(22),_modeCard.Width-fieldLeft-S(2),S(20));
|
2026-11-05 03:41:46 +00:00
|
|
|
foreach(var label in new[]{_selectionHeading,_routeHeading,_nodeHeading,_actualModeHeading,_currentNodeLabel})
|
|
|
|
|
{ label.TextAlign=ContentAlignment.MiddleLeft; label.Padding=Padding.Empty; }
|
2026-11-13 10:35:04 +08:00
|
|
|
_selectionHeading.Font = _routeHeading.Font = _nodeHeading.Font = _actualModeHeading.Font = _compactFieldFont;
|
2026-11-06 10:54:33 +00:00
|
|
|
_trafficCard.Visible=_tailnetTrafficCard.Visible=false;
|
2026-11-02 04:13:58 +00:00
|
|
|
_trafficIcon.Visible=_dailyIcon.Visible=_tailnetTrafficIcon.Visible=false;
|
2026-11-05 03:41:46 +00:00
|
|
|
_trafficHeading.Bounds=new(S(10),0,S(106),_trafficCard.Height-S(2));
|
|
|
|
|
_dailyHeading.Bounds=new(S(10),0,S(106),_dailyCard.Height-S(2));
|
2026-11-03 15:15:23 +00:00
|
|
|
_tailnetTrafficHeading.Text="Tailscale 速度";
|
2026-11-05 03:41:46 +00:00
|
|
|
_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; }
|
2026-11-02 04:13:58 +00:00
|
|
|
if(_tailnetTrafficVisible)
|
|
|
|
|
{
|
2026-11-03 15:15:23 +00:00
|
|
|
_tailnetUploadMetric.Bounds=_uploadMetric.Bounds;
|
|
|
|
|
_tailnetDownloadMetric.Bounds=_downloadMetric.Bounds;
|
2026-11-02 04:13:58 +00:00
|
|
|
}
|
2026-11-15 22:17:39 +08:00
|
|
|
_trendHeading.Text = !_selectionUiConnected ? "本机代理趋势" :
|
|
|
|
|
_currentNodeUsesTailnet ? "代理趋势 · Tailscale" : "代理趋势 · 公网入口";
|
|
|
|
|
var headerTop = S(2);
|
|
|
|
|
var headerHeight = S(20);
|
|
|
|
|
var inset = S(10);
|
|
|
|
|
var headingWidth = S(116);
|
|
|
|
|
var rangeWidth = S(78);
|
|
|
|
|
var rangeLeft = _speedTrendCard.Width - rangeWidth - inset;
|
|
|
|
|
_trendHeading.Bounds = new(inset, headerTop, headingWidth, headerHeight);
|
2026-11-05 03:41:46 +00:00
|
|
|
_trendHeading.TextAlign=ContentAlignment.MiddleLeft;
|
2026-11-15 22:17:39 +08:00
|
|
|
_historyRangeCombo.Bounds = new(rangeLeft, headerTop, rangeWidth, headerHeight);
|
|
|
|
|
var legendLeft = _trendHeading.Right + S(4);
|
|
|
|
|
var legendWidth = Math.Max(1, (rangeLeft - S(5) - legendLeft) / 2);
|
|
|
|
|
_uploadLegend.Bounds = new(legendLeft, headerTop, legendWidth, headerHeight);
|
|
|
|
|
_downloadLegend.Bounds = new(_uploadLegend.Right, headerTop, legendWidth, headerHeight);
|
2026-11-06 10:54:33 +00:00
|
|
|
_uploadLegend.TextAlign=_downloadLegend.TextAlign=ContentAlignment.MiddleLeft;
|
|
|
|
|
_uploadLegend.Visible=_downloadLegend.Visible=true;
|
2026-11-02 04:13:58 +00:00
|
|
|
_trafficChart.Font=_compactChartFont;
|
2026-11-15 22:17:39 +08:00
|
|
|
_trafficChart.Bounds = new(S(8), S(23), _speedTrendCard.Width - S(16), Math.Max(1, _speedTrendCard.Height - S(27)));
|
2026-11-06 10:54:33 +00:00
|
|
|
_historyStatus.Visible=false;
|
2026-11-02 04:13:58 +00:00
|
|
|
_sampleLabel.Visible=false;
|
2026-11-03 15:15:23 +00:00
|
|
|
_planLabel.Visible=false;
|
2026-11-13 10:35:04 +08:00
|
|
|
var footerHeight = Math.Max(S(15), _footer.Height - S(1));
|
|
|
|
|
_expiryLabel.Bounds=new(S(10),0,S(96),footerHeight);
|
|
|
|
|
_footerCompanySite.Bounds=new(S(107),0,S(145),footerHeight);
|
|
|
|
|
_footerHint.Bounds=new(_footer.Width-S(197),0,S(187),footerHeight);
|
2026-11-02 04:13:58 +00:00
|
|
|
_footerPoem.Visible=false;
|
2026-11-03 15:15:23 +00:00
|
|
|
_footerHint.Visible=true;
|
2026-11-02 04:13:58 +00:00
|
|
|
_dashboardBody.Size=_dashboardView.ClientSize;
|
|
|
|
|
_dashboardBody.Location=Point.Empty;
|
2026-11-13 10:35:04 +08:00
|
|
|
LayoutCompactDashboardActions();
|
2026-11-02 04:13:58 +00:00
|
|
|
}
|
|
|
|
|
}
|