Windows 0.3.0 clean next-generation source delta; no private history or other platform changes
This commit is contained in:
@@ -4,27 +4,23 @@ internal sealed partial class MainForm
|
||||
{
|
||||
// Presentation only. These controls never read adapter/counter state and
|
||||
// never change proxy, account, session totals or route decisions.
|
||||
private readonly CardPanel _tailnetTrafficCard = new() { MetricBand = true };
|
||||
private readonly CardPanel _tailnetTrafficCard = new();
|
||||
private readonly MetricCard _tailnetUploadMetric = new("上传速度", DashboardIcon.Upload) { Embedded = true };
|
||||
private readonly MetricCard _tailnetDownloadMetric = new("下载速度", DashboardIcon.Download) { Embedded = true };
|
||||
private readonly TrafficChart _tailnetTrafficChart = new();
|
||||
private readonly DashboardGlyph _tailnetTrafficIcon = new(DashboardIcon.Chart);
|
||||
private readonly Label _tailnetTrafficHeading = new(), _tailnetSampleLabel = new();
|
||||
private readonly Label _tailnetUploadLegend = new(), _tailnetDownloadLegend = new();
|
||||
private bool _tailnetTrafficVisible;
|
||||
|
||||
private void BuildTailnetTrafficCard()
|
||||
{
|
||||
ConfigureLabel(_tailnetTrafficHeading, "Tailscale 实时网速", Brand.Font(9.5f, FontStyle.Bold), Brand.Text);
|
||||
ConfigureLabel(_tailnetTrafficHeading, "Tailscale 实时速度", Brand.Font(9.5f, FontStyle.Bold), Brand.Text);
|
||||
ConfigureLabel(_tailnetSampleLabel, "等待流量采样", Brand.Font(7.5f), Brand.Muted);
|
||||
_tailnetSampleLabel.TextAlign = ContentAlignment.MiddleRight;
|
||||
_tailnetSampleLabel.AutoEllipsis = true;
|
||||
ConfigureLabel(_tailnetUploadLegend, "● 上传 —", Brand.Font(8), Brand.RoyalBlue);
|
||||
ConfigureLabel(_tailnetDownloadLegend, "● 下载 —", Brand.Font(8), Brand.Cyan);
|
||||
_tailnetTrafficCard.AccessibleName = "Tailscale 实时网速";
|
||||
_tailnetTrafficCard.AccessibleDescription = "仅纵横家当前 Tailscale 代理链路;已计入代理总流量,不代表所有 Tailscale 网卡或整机流量。";
|
||||
_tailnetTrafficCard.Controls.AddRange([_tailnetTrafficIcon, _tailnetTrafficHeading, _tailnetSampleLabel,
|
||||
_tailnetUploadMetric, _tailnetDownloadMetric, _tailnetTrafficChart, _tailnetUploadLegend, _tailnetDownloadLegend]);
|
||||
_tailnetUploadMetric, _tailnetDownloadMetric]);
|
||||
_tailnetTrafficCard.Visible = false;
|
||||
_dashboardBody.Controls.Add(_tailnetTrafficCard);
|
||||
ResetTailnetTraffic();
|
||||
@@ -50,33 +46,29 @@ internal sealed partial class MainForm
|
||||
_tailnetUploadMetric.SetBytes(up, speed: true, hint: "已计入代理总流量");
|
||||
_tailnetDownloadMetric.SetBytes(down, speed: true, hint: "已计入代理总流量");
|
||||
_tailnetSampleLabel.Text = "仅纵横家链路 · " + sampling;
|
||||
_tailnetUploadLegend.Text = up.HasValue ? $"● 上传 {FormatBytes((long)up.Value)}/s" : "● 上传 —";
|
||||
_tailnetDownloadLegend.Text = down.HasValue ? $"● 下载 {FormatBytes((long)down.Value)}/s" : "● 下载 —";
|
||||
if (up.HasValue && down.HasValue) _tailnetTrafficChart.Add(up.Value, down.Value);
|
||||
else _tailnetTrafficChart.Reset();
|
||||
}
|
||||
|
||||
internal void ResetTailnetTraffic()
|
||||
{
|
||||
_tailnetTrafficChart.Reset();
|
||||
DisplayTailnetTraffic(null, null, "等待 Tailscale 流量采样");
|
||||
}
|
||||
|
||||
private void LayoutTailnetTrafficCard(Rectangle bounds)
|
||||
private void LayoutTailnetTrafficCard(Rectangle bounds, float verticalScale)
|
||||
{
|
||||
_tailnetTrafficCard.Visible = _tailnetTrafficVisible;
|
||||
if (!_tailnetTrafficVisible) { _tailnetTrafficCard.Bounds = Rectangle.Empty; return; }
|
||||
_tailnetTrafficCard.Bounds = bounds;
|
||||
int S(int value) => ScaleLogical(value);
|
||||
_tailnetTrafficIcon.Bounds = new Rectangle(S(15), S(10), S(20), S(20));
|
||||
_tailnetTrafficHeading.Bounds = new Rectangle(S(42), S(8), S(132), S(26));
|
||||
_tailnetSampleLabel.Bounds = new Rectangle(S(178), S(10), Math.Max(1, bounds.Width - S(192)), S(22));
|
||||
var metricWidth = (bounds.Width - S(28)) / 2;
|
||||
_tailnetUploadMetric.Bounds = new Rectangle(S(14), S(43), metricWidth - S(2), S(82));
|
||||
_tailnetDownloadMetric.Bounds = new Rectangle(S(14) + metricWidth, S(43), metricWidth - S(2), S(82));
|
||||
_tailnetTrafficChart.Bounds = new Rectangle(S(13), S(132), bounds.Width - S(26), S(106));
|
||||
var legendWidth = (bounds.Width - S(40)) / 2;
|
||||
_tailnetUploadLegend.Bounds = new Rectangle(S(20), S(248), legendWidth, S(19));
|
||||
_tailnetDownloadLegend.Bounds = new Rectangle(S(20) + legendWidth, S(248), legendWidth, S(19));
|
||||
int Y(int value) => Math.Max(0, (int)Math.Floor(S(value) * verticalScale));
|
||||
_tailnetTrafficIcon.Bounds = new Rectangle(S(15), Y(8), S(20), Y(20));
|
||||
_tailnetTrafficHeading.Bounds = new Rectangle(S(42), Y(6), Math.Max(1, bounds.Width - S(52)), Y(26));
|
||||
// Scope remains accessible, without repeating long disclaimers inside
|
||||
// a small speed section. These are the same already-accounted bytes.
|
||||
_tailnetSampleLabel.Visible = false;
|
||||
var metricWidth = (bounds.Width - S(20)) / 2;
|
||||
var metricTop = Math.Max(Y(38), (bounds.Height - Y(82)) / 2);
|
||||
var metricHeight = Math.Min(Y(82), bounds.Height - Y(44));
|
||||
_tailnetUploadMetric.Bounds = new Rectangle(S(10), metricTop, metricWidth - S(1), metricHeight);
|
||||
_tailnetDownloadMetric.Bounds = new Rectangle(S(10) + metricWidth, metricTop, metricWidth - S(1), metricHeight);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user