Publish Zonghengjia Windows 0.3.18 client source

This commit is contained in:
2026-11-15 22:17:39 +08:00
parent ebec81ceb1
commit eb90ef4042
15 changed files with 1575 additions and 1680 deletions
+85 -220
View File
@@ -1,44 +1,24 @@
using System.Drawing.Drawing2D;
namespace UCVL.VPNPlus;
internal sealed partial class MainForm
{
private readonly CardPanel _wideMonitor = new() { Visible = false };
private readonly TrendSummaryPanel _wideSummary = new() { Visible = false };
private readonly Label _wideSummaryState = new(), _wideSidebarPlan = new(), _wideFooterState = new();
private readonly DashboardGlyph _wideFooterClock = new(DashboardIcon.History);
private readonly DashboardGlyph _wideFooterShield = new(DashboardIcon.Shield);
private readonly CardPanel _wideMonitor = new() { Visible = false, Embedded = true };
private readonly Label _wideSummaryState = new();
private readonly RoundedButton _wideUpload = new(), _wideDownload = new();
private readonly DashboardFeature[] _wideFeatures =
[
new(DashboardIcon.Server, "线路调度", "自动分配或手动选择"),
new(DashboardIcon.Shield, "入口验证", "Tailscale 与青岛公网", true),
new(DashboardIcon.Layers, "灵活代理", "以已生效的模式为准", true),
];
private bool _wideDashboardBuilt;
private TrafficChartSeries _wideSeries = TrafficChartSeries.Upload;
private TrafficChartSeries _wideSeries = TrafficChartSeries.Both;
private void BuildWideDashboard()
{
_wideMonitor.AccessibleName = "连接状态和流量监控";
_dashboardBody.Controls.Add(_wideMonitor);
ConfigureLabel(_wideSummaryState, "", Brand.Font(10, FontStyle.Bold), Brand.Text);
ConfigureLabel(_wideSidebarPlan, "", Brand.Font(8), Brand.Muted);
ConfigureLabel(_wideFooterState, "", Brand.Font(9.5f, FontStyle.Bold), Brand.Text);
foreach (var label in new[] { _wideSummaryState, _wideSidebarPlan, _wideFooterState })
{
label.AutoEllipsis = true;
label.TextAlign = ContentAlignment.MiddleLeft;
}
_wideSummary.Controls.Add(_wideSummaryState);
_nodeCard.Controls.Add(_wideSummary);
_nodeCard.Controls.Add(_wideSidebarPlan);
_nodeCard.Controls.AddRange(_wideFeatures);
ConfigureLabel(_wideSummaryState, "", Brand.Font(8, FontStyle.Bold), Brand.Muted);
_wideSummaryState.AutoEllipsis = true;
_wideSummaryState.TextAlign = ContentAlignment.MiddleRight;
_modeCard.Controls.Add(_wideSummaryState);
_connectionModeCombo.LeadingIcon = DashboardIcon.Settings;
_routeCombo.LeadingIcon = DashboardIcon.Layers;
_manualNodeCombo.LeadingIcon = DashboardIcon.Server;
_footer.Controls.AddRange([_wideFooterClock, _wideFooterShield, _wideFooterState]);
_modeCard.Controls.AddRange([_nodeIcon, _modeIcon]);
ConfigureSecondaryButton(_wideUpload, "↑ 上传 —", Point.Empty, new(144, 29));
ConfigureSecondaryButton(_wideDownload, "↓ 下载 —", Point.Empty, new(144, 29));
@@ -53,20 +33,20 @@ internal sealed partial class MainForm
private void SelectWideTrafficSeries(TrafficChartSeries series)
{
_wideSeries = series;
_wideSeries = _wideSeries == series ? TrafficChartSeries.Both : series;
ApplyWideTrafficSeries(WideDashboardPresentation);
}
private void ApplyWideTrafficSeries(bool wide)
{
_trafficChart.DisplayedSeries = wide ? _wideSeries : TrafficChartSeries.Both;
UpdateTab(_wideUpload, _wideSeries == TrafficChartSeries.Upload);
UpdateTab(_wideDownload, _wideSeries == TrafficChartSeries.Download);
static void UpdateTab(RoundedButton button, bool selected)
UpdateTab(_wideUpload, Brand.RoyalBlue, _wideSeries != TrafficChartSeries.Download);
UpdateTab(_wideDownload, TrafficChart.DownloadColor, _wideSeries != TrafficChartSeries.Upload);
static void UpdateTab(RoundedButton button, Color accent, bool visible)
{
button.BackColor = selected ? Brand.RoyalBlue : Color.White;
button.ForeColor = selected ? Color.White : Brand.DeepBlue;
button.AccessibleDescription = selected ? "当前显示" : "点击切换";
button.BackColor = Color.White;
button.ForeColor = visible ? accent : Brand.Muted;
button.AccessibleDescription = visible ? "曲线可见,点击切换" : "曲线已隐藏,点击显示";
}
}
@@ -77,31 +57,20 @@ internal sealed partial class MainForm
{
if (!ReferenceEquals(control.Parent, parent)) control.Parent = parent;
}
Move(_modeCard, wide ? _wideMonitor : _nodeCard);
Move(_speedTrendCard, wide ? _wideMonitor : _dashboardBody);
Move(_dailyCard, wide ? _wideMonitor : _dashboardBody);
Move(_nodeTrafficPanel, wide ? _wideMonitor : _dashboardBody);
Move(_trendHeading, wide ? _wideSummary : _speedTrendCard);
var rangeParent = wide ? _modeCard : _speedTrendCard;
if (_historyRangeCombo.Parent != rangeParent)
{
_historyRangeCombo.DroppedDown = false;
Move(_historyRangeCombo, rangeParent);
}
_wideMonitor.Visible = wide;
_wideSummary.Visible = _wideSidebarPlan.Visible = wide;
_wideSummaryState.Visible = wide;
_wideUpload.Visible = _wideDownload.Visible = wide;
_wideFooterClock.Visible = _wideFooterShield.Visible = _wideFooterState.Visible = wide;
_footerCompanySite.Visible = !wide;
_dailyIcon.Visible = wide;
foreach (var feature in _wideFeatures) feature.Visible = wide;
_usageMetric.InlineTotal = _sessionMetric.InlineTotal = wide;
_statusCard.WideBanner = wide;
_statusCard.WideBanner = false;
_connectButton.Capsule = wide;
_nodeCard.GlassRim = _wideMonitor.GlassRim = _wideSummary.GlassRim
= _speedTrendCard.GlassRim = _dailyCard.GlassRim = _footer.GlassRim = wide;
_nodeCard.GlassRim = _speedTrendCard.GlassRim = _dailyCard.GlassRim = _footer.GlassRim = wide;
_uploadLegend.Visible = _downloadLegend.Visible = !wide;
_historyStatus.Visible = wide;
_historyStatus.Visible = false;
ApplyWideTrafficSeries(wide);
RefreshConnectionAppearance();
}
@@ -110,13 +79,13 @@ internal sealed partial class MainForm
{
int S(int value) => ScaleLogical(value);
var dense = viewport.Height < S(465);
var layout = DashboardWideLayout.Calculate(viewport, DeviceDpi, _canViewNodeTraffic);
var layout = DashboardWideLayout.Calculate(viewport, DeviceDpi, _canViewNodeTraffic, _manualNodeCombo.Visible);
_dashboardBody.Bounds = new Rectangle(Point.Empty, viewport);
if (_welcomeLabel.Parent != _dashboardBody) _welcomeLabel.Parent = _dashboardBody;
if (_logoutButton.Parent != _dashboardBody) _logoutButton.Parent = _dashboardBody;
_welcomeLabel.Visible = _logoutButton.Visible = _accountLabel.Visible = _identityBadge.Visible = false;
_statusCard.Bounds = layout.Banner;
_nodeCard.Bounds = layout.Sidebar;
_nodeCard.Bounds = layout.Configuration;
_wideMonitor.Bounds = layout.Monitor;
_modeCard.Bounds = layout.State;
_speedTrendCard.Bounds = layout.Trend;
@@ -127,114 +96,85 @@ internal sealed partial class MainForm
_tailnetSampleLabel.Visible = false;
var bannerHeight = _statusCard.Height;
var actionWidth = S(dense ? 132 : 158);
var actionHeight = S(dense ? 36 : 42);
var shieldSize = S(dense ? 43 : 52);
_statusDot.Bounds = new Rectangle(S(22), (bannerHeight - shieldSize) / 2, shieldSize, shieldSize);
_connectButton.Bounds = new Rectangle(_statusCard.Width - actionWidth - S(22), (bannerHeight - actionHeight) / 2, actionWidth, actionHeight);
var statusLeft = S(dense ? 77 : 90);
var statusWidth = _connectButton.Left - statusLeft - S(13);
_statusTitle.Bounds = new Rectangle(statusLeft, bannerHeight / 2 - S(dense ? 24 : 30), statusWidth, S(dense ? 26 : 33));
_statusDetail.Bounds = new Rectangle(statusLeft + S(2), bannerHeight / 2 + S(dense ? 1 : 4), statusWidth, S(dense ? 20 : 23));
var actionWidth = S(dense ? 120 : 138);
var actionHeight = S(dense ? 34 : 38);
var shieldSize = S(dense ? 36 : 42);
var pad = S(dense ? 14 : 18);
_statusDot.Bounds = new Rectangle(pad, (bannerHeight - shieldSize) / 2, shieldSize, shieldSize);
_connectButton.Bounds = new Rectangle(_statusCard.Width - actionWidth - pad, (bannerHeight - actionHeight) / 2, actionWidth, actionHeight);
var statusLeft = _statusDot.Right + S(12);
var statusWidth = _connectButton.Left - statusLeft - S(12);
_statusTitle.Bounds = new Rectangle(statusLeft, bannerHeight / 2 - S(dense ? 22 : 26), statusWidth, S(dense ? 25 : 29));
_statusDetail.Bounds = new Rectangle(statusLeft, bannerHeight / 2 + S(2), statusWidth, S(20));
var sidebarWidth = _nodeCard.Width;
var selectorWidth = sidebarWidth - S(75);
var firstRow = S(dense ? 9 : 15);
var rowStep = S(dense ? 33 : 40);
var rowHeight = S(dense ? 28 : 32);
_selectionHeading.Bounds = new Rectangle(S(15), firstRow, S(47), rowHeight);
_routeHeading.Bounds = new Rectangle(S(15), firstRow + rowStep, S(47), rowHeight);
var rowHeight = S(dense ? 26 : 31);
var fieldHeight = rowHeight - S(3);
var firstRow = layout.State.Top;
var valueLeft = pad + S(43);
var fieldWidth = layout.State.Left - valueLeft - S(16);
_selectionHeading.Bounds = new Rectangle(pad, firstRow, S(39), fieldHeight);
_routeHeading.Bounds = new Rectangle(pad, firstRow + rowHeight, S(39), fieldHeight);
_routeHeading.Text = "模式";
_selectionHeading.TextAlign = _routeHeading.TextAlign = ContentAlignment.MiddleLeft;
_connectionModeCombo.Bounds = new Rectangle(S(60), firstRow, selectorWidth, rowHeight);
_routeCombo.Bounds = new Rectangle(S(60), firstRow + rowStep, selectorWidth, rowHeight);
_manualNodeCombo.Bounds = new Rectangle(S(60), firstRow + 2 * rowStep, selectorWidth, S(29));
var summaryTop = firstRow + (_manualNodeCombo.Visible ? 3 : 2) * rowStep + S(3);
var remaining = _nodeCard.Height - summaryTop - S(24);
var summaryHeight = Math.Clamp(remaining / 3, S(dense ? 55 : 65), S(115));
_wideSummary.Bounds = new Rectangle(S(10), summaryTop, sidebarWidth - S(20), summaryHeight);
_trendHeading.Text = "本机代理趋势";
_trendHeading.Bounds = new Rectangle(S(13), S(8), _wideSummary.Width - S(26), S(22));
_trendHeading.TextAlign = ContentAlignment.MiddleLeft;
_wideSummaryState.Bounds = new Rectangle(S(13), S(31), _wideSummary.Width - S(26), S(22));
_wideSidebarPlan.Bounds = new Rectangle(S(14), _nodeCard.Height - S(25), sidebarWidth - S(28), S(16));
var featureTop = _wideSummary.Bottom + S(5);
var featureHeight = Math.Min(S(66), (_wideSidebarPlan.Top - featureTop - S(4)) / _wideFeatures.Length);
for (var index = 0; index < _wideFeatures.Length; index++)
{
var feature = _wideFeatures[index];
feature.Visible = featureHeight >= S(30);
if (feature.Visible) feature.Bounds = new Rectangle(S(12), featureTop + index * featureHeight, sidebarWidth - S(24), featureHeight);
}
_connectionModeCombo.Bounds = new Rectangle(valueLeft, firstRow, fieldWidth, fieldHeight);
_routeCombo.Bounds = new Rectangle(valueLeft, firstRow + rowHeight, fieldWidth, fieldHeight);
_manualNodeCombo.Bounds = new Rectangle(valueLeft, firstRow + 2 * rowHeight, fieldWidth, fieldHeight);
var stateHeight = _modeCard.Height;
var rangeWidth = S(129);
var statesWidth = _modeCard.Width - rangeWidth - S(23);
using var metrics = _modeCard.CreateGraphics();
int TextWidth(string text, Font font) => TextRenderer.MeasureText(metrics, text, font,
Size.Empty, TextFormatFlags.SingleLine).Width;
var headingLeft = S(34);
var headingWidth = Math.Max(S(40), Math.Max(TextWidth("节点", _nodeHeading.Font),
TextWidth("模式", _actualModeHeading.Font)) + S(2));
var valueInset = headingLeft + headingWidth;
var modeWidth = Math.Clamp(TextWidth(_routeReadOnly.Text, _routeReadOnly.Font) + S(6), S(79), S(146));
var splitLimit = Math.Max(valueInset + S(35), statesWidth - valueInset - modeWidth);
var nodeRoom = splitLimit - valueInset - S(4);
var nodeText = _selectionUiConnected && !string.IsNullOrWhiteSpace(_currentNodeName) ? _currentNodeName : _currentNodeLabel.Text;
var nodeFont = _currentNodeLabel.Font;
if (TextWidth(nodeText, nodeFont) > nodeRoom)
{
// The sidebar already identifies the active transport. Omit its
// duplicate suffix here if it would crowd out the actual name.
if (_selectionUiConnected && _currentNodeUsesTailnet && !string.IsNullOrWhiteSpace(_currentNodeBaseName))
nodeText = _currentNodeBaseName;
if (TextWidth(nodeText, nodeFont) > nodeRoom)
nodeFont = TextWidth(nodeText, _narrowNodeFont) <= nodeRoom ? _narrowNodeFont : _minimumNodeFont;
}
_currentNodeLabel.Text = nodeText;
_currentNodeLabel.Font = nodeFont;
var split = Math.Min(splitLimit, Math.Max(statesWidth / 2, valueInset + TextWidth(nodeText, nodeFont) + S(4)));
_historyRangeCombo.Bounds = new Rectangle(_modeCard.Width - rangeWidth - S(6), (stateHeight - S(31)) / 2, rangeWidth, S(31));
_nodeIcon.Bounds = new Rectangle(S(7), (stateHeight - S(26)) / 2, S(26), S(26));
var headingLeft = S(12);
var headingWidth = S(45);
var stateValueLeft = headingLeft + headingWidth;
var entryWidth = _selectionUiConnected ? S(105) : 0;
var stateWidth = _modeCard.Width - stateValueLeft - S(8);
_nodeHeading.Text = "节点";
_nodeHeading.Bounds = new Rectangle(headingLeft, 0, headingWidth, stateHeight);
_currentNodeLabel.Bounds = new Rectangle(valueInset, 0, Math.Max(S(31), split - valueInset - S(4)), stateHeight);
_modeIcon.Bounds = new Rectangle(split + S(7), (stateHeight - S(25)) / 2, S(25), S(25));
_actualModeHeading.Bounds = new Rectangle(split + headingLeft, 0, headingWidth, stateHeight);
_routeReadOnly.Bounds = new Rectangle(split + valueInset, 0, Math.Max(S(35), statesWidth - split - valueInset), stateHeight);
_nodeIcon.Visible = _modeIcon.Visible = true;
_nodeHeading.Bounds = new Rectangle(headingLeft, 0, headingWidth, fieldHeight);
_currentNodeLabel.Bounds = new Rectangle(stateValueLeft, 0, stateWidth - entryWidth, fieldHeight);
_actualModeHeading.Bounds = new Rectangle(headingLeft, rowHeight, headingWidth, fieldHeight);
_routeReadOnly.Bounds = new Rectangle(stateValueLeft, rowHeight, stateWidth, fieldHeight);
_wideSummaryState.Bounds = new Rectangle(_modeCard.Width - entryWidth - S(8), 0, entryWidth, fieldHeight);
_wideSummaryState.Visible = _selectionUiConnected;
if (_selectionUiConnected && !string.IsNullOrWhiteSpace(_currentNodeBaseName))
_currentNodeLabel.Text = _currentNodeBaseName;
using (var metrics = _modeCard.CreateGraphics())
{
int NodeWidth(Font font) => TextRenderer.MeasureText(metrics, _currentNodeLabel.Text, font,
Size.Empty, TextFormatFlags.SingleLine).Width;
if (NodeWidth(_currentNodeLabel.Font) > _currentNodeLabel.Width)
_currentNodeLabel.Font = NodeWidth(_narrowNodeFont) <= _currentNodeLabel.Width ? _narrowNodeFont : _minimumNodeFont;
}
_nodeIcon.Visible = _modeIcon.Visible = false;
_nodeHeading.TextAlign = _actualModeHeading.TextAlign = ContentAlignment.MiddleLeft;
var trendWidth = _speedTrendCard.Width;
var tabWidth = Math.Min(S(164), (trendWidth - S(30)) / 2);
var tabTop = S(dense ? 6 : 9);
var tabHeight = S(dense ? 26 : 31);
_wideUpload.Bounds = new Rectangle(S(12), tabTop, tabWidth, tabHeight);
_wideDownload.Bounds = new Rectangle(_wideUpload.Right + S(4), tabTop, tabWidth, tabHeight);
_historyStatus.Bounds = new Rectangle(_wideDownload.Right + S(6), tabTop, Math.Max(1, trendWidth - _wideDownload.Right - S(18)), tabHeight);
_historyStatus.Text = "实时代理采样";
var tabTop = S(7);
var tabHeight = S(dense ? 24 : 28);
var rangeWidth = S(128);
var tabWidth = S(135);
_historyRangeCombo.Bounds = new Rectangle(trendWidth - pad - rangeWidth, tabTop, rangeWidth, tabHeight);
_wideDownload.Bounds = new Rectangle(_historyRangeCombo.Left - S(14) - tabWidth, tabTop, tabWidth, tabHeight);
_wideUpload.Bounds = new Rectangle(_wideDownload.Left - S(5) - tabWidth, tabTop, tabWidth, tabHeight);
_trendHeading.Text = "本机代理趋势";
_trendHeading.Bounds = new Rectangle(pad, tabTop, _wideUpload.Left - pad - S(8), tabHeight);
_trendHeading.TextAlign = ContentAlignment.MiddleLeft;
_trafficChart.Font = _wideChartFont;
var chartTop = _wideUpload.Bottom + S(3);
_trafficChart.Bounds = new Rectangle(S(10), chartTop, trendWidth - S(20), _speedTrendCard.Height - chartTop - S(7));
_trafficChart.Bounds = new Rectangle(S(9), chartTop, trendWidth - S(18), _speedTrendCard.Height - chartTop - S(6));
var totalsHeight = _dailyCard.Height;
var titleWidth = Math.Min(S(155), _dailyCard.Width / 4);
_dailyIcon.Bounds = new Rectangle(S(12), (totalsHeight - S(28)) / 2, S(28), S(28));
_dailyHeading.Bounds = new Rectangle(S(47), 0, Math.Max(1, titleWidth - S(48)), totalsHeight);
var titleWidth = S(140);
var iconSize = S(18);
_dailyIcon.Bounds = new Rectangle(pad, (totalsHeight - iconSize) / 2, iconSize, iconSize);
_dailyHeading.Bounds = new Rectangle(_dailyIcon.Right + S(8), 0, titleWidth - _dailyIcon.Right - S(8), totalsHeight);
_dailyHeading.TextAlign = ContentAlignment.MiddleLeft;
var metricWidth = (_dailyCard.Width - titleWidth - S(9)) / 2;
_usageMetric.Bounds = new Rectangle(titleWidth, S(3), metricWidth, totalsHeight - S(9));
_sessionMetric.Bounds = new Rectangle(_usageMetric.Right, S(3), metricWidth, totalsHeight - S(9));
var metricWidth = Math.Min(S(178), (_dailyCard.Width - titleWidth - pad) / 2);
_usageMetric.Bounds = new Rectangle(titleWidth, S(1), metricWidth, totalsHeight - S(3));
_sessionMetric.Bounds = new Rectangle(_usageMetric.Right, S(1), metricWidth, totalsHeight - S(3));
var footerHeight = _footer.Height;
_wideFooterClock.Bounds = new Rectangle(S(11), (footerHeight - S(22)) / 2, S(22), S(22));
_expiryLabel.Bounds = new Rectangle(S(40), 0, S(126), footerHeight);
_wideFooterShield.Bounds = new Rectangle(S(171), (footerHeight - S(22)) / 2, S(22), S(22));
_wideFooterState.Bounds = new Rectangle(S(200), 0, Math.Max(1, _footer.Width - S(452)), footerHeight);
_footerHint.Bounds = new Rectangle(_footer.Width - S(243), 0, S(229), footerHeight);
_footerHint.Visible = true;
_planLabel.Visible = _footerPoem.Visible = false;
_wideSidebarPlan.Text = _planLabel.Text;
_expiryLabel.Bounds = new Rectangle(pad, 0, S(110), footerHeight);
_planLabel.Bounds = new Rectangle(_expiryLabel.Right + S(8), 0, _footer.Width - S(390), footerHeight);
_footerHint.Bounds = new Rectangle(_footer.Width - S(229) - pad, 0, S(229), footerHeight);
_footerHint.Visible = _planLabel.Visible = true;
_footerPoem.Visible = false;
}
private void RefreshConnectionAppearance()
@@ -265,8 +205,7 @@ internal sealed partial class MainForm
_ => Color.FromArgb(13, 99, 195),
} : accent;
_statusDot.Featured = _statusCard.WideBanner;
_wideFooterShield.ForeColor = accent;
_statusDot.Glyph = _wideFooterShield.Glyph = tone switch
_statusDot.Glyph = tone switch
{
BannerTone.Connected => DashboardIcon.Shield,
BannerTone.Error or BannerTone.Attention => DashboardIcon.ShieldAlert,
@@ -276,7 +215,6 @@ internal sealed partial class MainForm
_wideSummaryState.Text = _selectionUiConnected
? (_currentNodeUsesTailnet ? "● Tailscale 入口" : "● 公网入口")
: "● " + title;
_wideFooterState.Text = tone == BannerTone.Connected ? "网络连接 · 已连接" : "网络连接 · " + title;
_footerCompanySite.Text = tone switch
{
BannerTone.Connected => "网络 · 已连接",
@@ -288,76 +226,3 @@ internal sealed partial class MainForm
_footerCompanySite.ForeColor = accent;
}
}
internal sealed class TrendSummaryPanel : CardPanel
{
protected override void OnPaintBackground(PaintEventArgs e)
{
base.OnPaintBackground(e);
if (Width < 20 || Height < 48) return;
var g = e.Graphics;
var state = g.Save();
var scale = DeviceDpi / 96f;
var inset = Math.Max(1, (int)Math.Round(scale * 2));
using var clip = UiGeometry.RoundedRectangle(new Rectangle(inset, inset, Width - 2 * inset - 1, Height - 2 * inset - 2),
Math.Min((int)Math.Round(12 * scale), (Height - 2 * inset - 2) / 2));
g.SetClip(clip, CombineMode.Intersect);
var y = Height * .84f;
using var wave = new GraphicsPath();
wave.AddBezier(0, y, Width * .35f, Height * .43f, Width * .52f, Height * 1.25f, Width, Height * .66f);
wave.AddLine(Width, Height, 0, Height);
wave.CloseFigure();
using var fill = new LinearGradientBrush(ClientRectangle, Color.FromArgb(36, 117, 194, 244), Color.FromArgb(80, 114, 192, 246), 90);
using var line = new Pen(Color.FromArgb(96, 66, 152, 217), Math.Max(1f, .7f * scale));
g.SmoothingMode = SmoothingMode.AntiAlias;
g.FillPath(fill, wave);
g.DrawBezier(line, 0, y, Width * .35f, Height * .43f, Width * .52f, Height * 1.25f, Width, Height * .66f);
g.Restore(state);
}
}
internal sealed class DashboardFeature : Control
{
private readonly DashboardIcon _icon;
private readonly string _title, _detail;
private readonly bool _divider;
internal DashboardFeature(DashboardIcon icon, string title, string detail, bool divider = false)
{
_icon = icon;
_title = title;
_detail = detail;
_divider = divider;
SetStyle(ControlStyles.SupportsTransparentBackColor | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw, true);
BackColor = Color.Transparent;
AccessibleName = title;
AccessibleDescription = detail;
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
var g = e.Graphics;
var scale = DeviceDpi / 96f;
int S(float value) => (int)Math.Round(value * scale);
var side = Math.Min(S(36), Height - S(6));
var icon = new Rectangle(S(5), (Height - side) / 2, side, side);
g.SmoothingMode = SmoothingMode.AntiAlias;
using var bubble = new SolidBrush(Color.FromArgb(92, 174, 217, 251));
g.FillEllipse(bubble, icon);
DashboardDrawing.Icon(g, _icon, Rectangle.Inflate(icon, -S(7), -S(7)), Brand.DeepBlue);
using var title = Brand.Font(10.5f, FontStyle.Bold);
using var detail = Brand.Font(8.5f);
var x = icon.Right + S(10);
var width = Width - x - S(4);
var middle = Height / 2;
if (_divider && Height >= S(38))
{
using var divider = new Pen(Color.FromArgb(108, 167, 198, 223), Math.Max(1f, .65f * scale));
g.DrawLine(divider, S(6), 0, Width - S(7), 0);
}
var flags = TextFormatFlags.SingleLine | TextFormatFlags.EndEllipsis | TextFormatFlags.VerticalCenter;
TextRenderer.DrawText(g, _title, title, new Rectangle(x, middle - S(16), width, S(18)), Brand.Navy, flags);
TextRenderer.DrawText(g, _detail, detail, new Rectangle(x, middle + S(2), width, S(16)), Brand.Muted, flags);
}
}