2026-03-09 12:27:33 +08:00
|
|
|
using Avalonia.Controls;
|
|
|
|
|
|
|
|
|
|
namespace LanMountainDesktop.PluginSdk;
|
|
|
|
|
|
|
|
|
|
public sealed class PluginDesktopComponentRegistration
|
|
|
|
|
{
|
|
|
|
|
public PluginDesktopComponentRegistration(
|
2026-03-12 09:22:03 +08:00
|
|
|
Func<IServiceProvider, PluginDesktopComponentContext, Control> controlFactory,
|
2026-03-20 22:37:37 +08:00
|
|
|
PluginDesktopComponentOptions options)
|
2026-03-09 12:27:33 +08:00
|
|
|
{
|
|
|
|
|
ArgumentNullException.ThrowIfNull(controlFactory);
|
2026-03-20 22:37:37 +08:00
|
|
|
ArgumentNullException.ThrowIfNull(options);
|
|
|
|
|
ArgumentException.ThrowIfNullOrWhiteSpace(options.ComponentId);
|
|
|
|
|
ArgumentException.ThrowIfNullOrWhiteSpace(options.DisplayName);
|
|
|
|
|
ArgumentException.ThrowIfNullOrWhiteSpace(options.IconKey);
|
|
|
|
|
ArgumentException.ThrowIfNullOrWhiteSpace(options.Category);
|
|
|
|
|
|
|
|
|
|
ComponentId = options.ComponentId.Trim();
|
|
|
|
|
DisplayName = options.DisplayName.Trim();
|
|
|
|
|
DisplayNameLocalizationKey = string.IsNullOrWhiteSpace(options.DisplayNameLocalizationKey)
|
2026-03-09 12:27:33 +08:00
|
|
|
? null
|
2026-03-20 22:37:37 +08:00
|
|
|
: options.DisplayNameLocalizationKey.Trim();
|
2026-06-07 00:40:48 +08:00
|
|
|
Description = string.IsNullOrWhiteSpace(options.Description)
|
|
|
|
|
? null
|
|
|
|
|
: options.Description.Trim();
|
|
|
|
|
DescriptionLocalizationKey = string.IsNullOrWhiteSpace(options.DescriptionLocalizationKey)
|
|
|
|
|
? null
|
|
|
|
|
: options.DescriptionLocalizationKey.Trim();
|
2026-03-09 12:27:33 +08:00
|
|
|
ControlFactory = controlFactory;
|
2026-03-20 22:37:37 +08:00
|
|
|
IconKey = options.IconKey.Trim();
|
|
|
|
|
Category = options.Category.Trim();
|
|
|
|
|
MinWidthCells = Math.Max(1, options.MinWidthCells);
|
|
|
|
|
MinHeightCells = Math.Max(1, options.MinHeightCells);
|
|
|
|
|
AllowDesktopPlacement = options.AllowDesktopPlacement;
|
|
|
|
|
AllowStatusBarPlacement = options.AllowStatusBarPlacement;
|
|
|
|
|
ResizeMode = options.ResizeMode;
|
|
|
|
|
CornerRadiusPreset = options.CornerRadiusPreset;
|
|
|
|
|
CornerRadiusResolver = options.CornerRadiusResolver;
|
2026-03-09 12:27:33 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-12 09:22:03 +08:00
|
|
|
public PluginDesktopComponentRegistration(
|
|
|
|
|
Func<PluginDesktopComponentContext, Control> controlFactory,
|
2026-03-20 22:37:37 +08:00
|
|
|
PluginDesktopComponentOptions options)
|
|
|
|
|
: this((_, context) => controlFactory(context), options)
|
2026-03-12 09:22:03 +08:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-09 12:27:33 +08:00
|
|
|
public string ComponentId { get; }
|
|
|
|
|
|
|
|
|
|
public string DisplayName { get; }
|
|
|
|
|
|
|
|
|
|
public string? DisplayNameLocalizationKey { get; }
|
|
|
|
|
|
2026-06-07 00:40:48 +08:00
|
|
|
public string? Description { get; }
|
|
|
|
|
|
|
|
|
|
public string? DescriptionLocalizationKey { get; }
|
|
|
|
|
|
2026-03-12 09:22:03 +08:00
|
|
|
public Func<IServiceProvider, PluginDesktopComponentContext, Control> ControlFactory { get; }
|
2026-03-09 12:27:33 +08:00
|
|
|
|
|
|
|
|
public string IconKey { get; }
|
|
|
|
|
|
|
|
|
|
public string Category { get; }
|
|
|
|
|
|
|
|
|
|
public int MinWidthCells { get; }
|
|
|
|
|
|
|
|
|
|
public int MinHeightCells { get; }
|
|
|
|
|
|
|
|
|
|
public bool AllowDesktopPlacement { get; }
|
|
|
|
|
|
|
|
|
|
public bool AllowStatusBarPlacement { get; }
|
|
|
|
|
|
|
|
|
|
public PluginDesktopComponentResizeMode ResizeMode { get; }
|
|
|
|
|
|
2026-03-20 22:37:37 +08:00
|
|
|
public PluginCornerRadiusPreset CornerRadiusPreset { get; }
|
|
|
|
|
|
|
|
|
|
public Func<IPluginAppearanceContext, double, double>? CornerRadiusResolver { get; }
|
|
|
|
|
|
|
|
|
|
public double ResolveCornerRadius(IPluginAppearanceContext appearance, double cellSize)
|
|
|
|
|
{
|
|
|
|
|
ArgumentNullException.ThrowIfNull(appearance);
|
|
|
|
|
|
|
|
|
|
var resolved = CornerRadiusResolver is not null
|
|
|
|
|
? CornerRadiusResolver(appearance, Math.Max(1d, cellSize))
|
|
|
|
|
: CornerRadiusPreset == PluginCornerRadiusPreset.Default
|
2026-04-12 13:52:52 +08:00
|
|
|
? appearance.ResolveCornerRadius(PluginCornerRadiusPreset.Component)
|
2026-03-20 22:37:37 +08:00
|
|
|
: appearance.ResolveCornerRadius(CornerRadiusPreset);
|
|
|
|
|
|
|
|
|
|
return double.IsFinite(resolved)
|
|
|
|
|
? Math.Max(0d, resolved)
|
2026-04-12 13:52:52 +08:00
|
|
|
: appearance.ResolveCornerRadius(PluginCornerRadiusPreset.Component);
|
2026-03-20 22:37:37 +08:00
|
|
|
}
|
2026-03-09 12:27:33 +08:00
|
|
|
}
|