167 lines
8.5 KiB
C#
167 lines
8.5 KiB
C#
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 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();
|
|
_compactChartFont.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(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();
|
|
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;
|
|
_welcomeLabel.Bounds=new(_brandHeader.Width-S(226),S(5),S(172),S(20));
|
|
_logoutButton.Bounds=new(_brandHeader.Width-S(128),S(28),S(72),S(19));
|
|
_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(4),S(70),S(24));
|
|
_statusTitle.Bounds=new(S(40),S(1),_statusCard.Width-S(130),S(17));
|
|
_statusDetail.Bounds=new(S(40),S(17),_statusCard.Width-S(130),S(14));
|
|
_nodeIcon.Visible=_modeIcon.Visible=false;
|
|
_scheduleBadge.Visible=false;
|
|
var leftWidth=_modeCard.Left-S(8);
|
|
_selectionHeading.Bounds=R(10,3,27,20);
|
|
_routeHeading.Bounds=R(10,25,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(3),_manualNodeCombo.Visible?splitWidth:fieldWidth,S(20));
|
|
_manualNodeCombo.Bounds=new(_connectionModeCombo.Right+S(4),S(3),Math.Max(S(60),fieldWidth-splitWidth-S(4)),S(20));
|
|
_routeCombo.Bounds=new(fieldLeft,S(25),fieldWidth,S(20));
|
|
_nodeHeading.Text="节点";
|
|
_nodeHeading.Bounds=R(8,0,27,20);
|
|
_currentNodeLabel.Bounds=new(S(39),0,_modeCard.Width-S(41),S(20));
|
|
_actualModeHeading.Bounds=R(8,22,27,20);
|
|
_routeReadOnly.Bounds=new(S(39),S(22),_modeCard.Width-S(41),S(20));
|
|
_trafficIcon.Visible=_dailyIcon.Visible=_tailnetTrafficIcon.Visible=false;
|
|
_trafficHeading.Bounds=new(S(10),0,S(96),_trafficCard.Height-S(2));
|
|
_dailyHeading.Bounds=new(S(10),0,S(56),_dailyCard.Height-S(2));
|
|
_tailnetTrafficHeading.Text="Tailscale 速度";
|
|
_tailnetTrafficHeading.Bounds=new(S(10),0,S(96),_tailnetTrafficCard.Height-S(2));
|
|
if(_tailnetTrafficVisible)
|
|
{
|
|
_tailnetUploadMetric.Bounds=_uploadMetric.Bounds;
|
|
_tailnetDownloadMetric.Bounds=_downloadMetric.Bounds;
|
|
}
|
|
var rail=CompactPresentation && _speedTrendCard.Height<S(100);
|
|
_trendHeading.Bounds=rail?R(10,6,90,20):new(S(10),S(1),_speedTrendCard.Width-S(210),S(20));
|
|
_historyRangeCombo.Bounds=rail?R(8,30,88,20):new(_speedTrendCard.Width-S(98),S(2),S(88),S(20));
|
|
_trafficChart.Font=_compactChartFont;
|
|
_trafficChart.Bounds=rail?new(S(104),S(1),_speedTrendCard.Width-S(108),_speedTrendCard.Height-S(3))
|
|
:new(S(2),S(21),_speedTrendCard.Width-S(4),Math.Max(S(22),_speedTrendCard.Height-S(23)));
|
|
_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;
|
|
}
|
|
}
|