Merge branch 'main' into main
This commit is contained in:
Коммит
f5de59f4d5
|
@ -20,12 +20,12 @@ namespace Microcharts
|
|||
///
|
||||
/// A bar chart.
|
||||
/// </summary>
|
||||
public class BarChartImplementation<T> : PointChartImplementation<T> where T : IBarChart
|
||||
public class BarChartImplementation : PointChartImplementation
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:Microcharts.BarChart"/> class.
|
||||
/// </summary>
|
||||
public BarChartImplementation(T control) : base(control)
|
||||
public BarChartImplementation(IBarChart control) : base(control)
|
||||
{
|
||||
PointSize = 0;
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace Microcharts
|
|||
/// <summary>
|
||||
/// A chart.
|
||||
/// </summary>
|
||||
public abstract class ChartImplementation<T> : StandardControlImplementation<T>, INotifyPropertyChanged where T : IChart
|
||||
public abstract class ChartImplementation : StandardControlImplementation, INotifyPropertyChanged
|
||||
{
|
||||
private float animationProgress;
|
||||
private double margin = 20, labelTextSize = 16;
|
||||
|
@ -42,11 +42,15 @@ namespace Microcharts
|
|||
private Task invalidationPlanification;
|
||||
private CancellationTokenSource animationCancellation;
|
||||
|
||||
protected IChart Control { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:Microcharts.Chart"/> class.
|
||||
/// </summary>
|
||||
public ChartImplementation(T control) : base(control)
|
||||
public ChartImplementation(IChart control) : base((IStandardControlEnvironmentPeer)control)
|
||||
{
|
||||
Control = control;
|
||||
|
||||
PropertyChanged += OnPropertyChanged;
|
||||
|
||||
// Animation doesn't currently work, so disable it by default
|
||||
|
@ -419,10 +423,10 @@ namespace Microcharts
|
|||
/// <param name="target">The target instance.</param>
|
||||
/// <param name="onInvalidate">Callback when chart is invalidated.</param>
|
||||
/// <typeparam name="TTarget">The target subsriber type.</typeparam>
|
||||
public InvalidatedWeakEventHandler<T, TTarget> ObserveInvalidate<TTarget>(TTarget target, Action<TTarget> onInvalidate)
|
||||
public InvalidatedWeakEventHandler<TTarget> ObserveInvalidate<TTarget>(TTarget target, Action<TTarget> onInvalidate)
|
||||
where TTarget : class
|
||||
{
|
||||
var weakHandler = new InvalidatedWeakEventHandler<T, TTarget>(this, target, onInvalidate);
|
||||
var weakHandler = new InvalidatedWeakEventHandler<TTarget>(this, target, onInvalidate);
|
||||
weakHandler.Subsribe();
|
||||
return weakHandler;
|
||||
}
|
||||
|
|
|
@ -24,12 +24,12 @@ namespace Microcharts
|
|||
///
|
||||
/// Point chart.
|
||||
/// </summary>
|
||||
public class PointChartImplementation<T> : ChartImplementation<T> where T : IPointChart
|
||||
public class PointChartImplementation : ChartImplementation
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:Microcharts.PointChart"/> class.
|
||||
/// </summary>
|
||||
public PointChartImplementation(T control) : base(control)
|
||||
public PointChartImplementation(IPointChart control) : base(control)
|
||||
{
|
||||
LabelOrientation = Orientation.Horizontal; // Orientation.Default;
|
||||
ValueLabelOrientation = Orientation.Default;
|
||||
|
|
|
@ -21,11 +21,11 @@ namespace Microcharts
|
|||
///
|
||||
/// A radar chart.
|
||||
/// </summary>
|
||||
public class RadarChartImplementation<T> : ChartImplementation<T> where T : IRadarChart
|
||||
public class RadarChartImplementation : ChartImplementation
|
||||
{
|
||||
private const float Epsilon = 0.01f;
|
||||
|
||||
public RadarChartImplementation(T control) : base(control)
|
||||
public RadarChartImplementation(IRadarChart control) : base(control)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -11,11 +11,11 @@ namespace Microcharts
|
|||
/// in memory instead of the actual subscriber.
|
||||
/// This could be considered as an acceptable solution in most cases.
|
||||
/// </summary>
|
||||
public class InvalidatedWeakEventHandler<TControlSource, TTarget> : IDisposable where TControlSource : IChart where TTarget : class
|
||||
public class InvalidatedWeakEventHandler<TTarget> : IDisposable where TTarget : class
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private readonly WeakReference<ChartImplementation<TControlSource>> sourceReference;
|
||||
private readonly WeakReference<ChartImplementation> sourceReference;
|
||||
|
||||
private readonly WeakReference<TTarget> targetReference;
|
||||
|
||||
|
@ -33,9 +33,9 @@ namespace Microcharts
|
|||
/// <param name="source">The source.</param>
|
||||
/// <param name="target">The target.</param>
|
||||
/// <param name="targetMethod">The target method.</param>
|
||||
public InvalidatedWeakEventHandler(ChartImplementation<TControlSource> source, TTarget target, Action<TTarget> targetMethod)
|
||||
public InvalidatedWeakEventHandler(ChartImplementation source, TTarget target, Action<TTarget> targetMethod)
|
||||
{
|
||||
this.sourceReference = new WeakReference<ChartImplementation<TControlSource>>(source);
|
||||
this.sourceReference = new WeakReference<ChartImplementation>(source);
|
||||
this.targetReference = new WeakReference<TTarget>(target);
|
||||
this.targetMethod = targetMethod;
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ namespace Microcharts
|
|||
/// Gets a value indicating whether this <see cref="T:Microcharts.InvalidateWeakEventHandler`1"/> is alive.
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if is alive; otherwise, <c>false</c>.</value>
|
||||
public bool IsAlive => this.sourceReference.TryGetTarget(out ChartImplementation<TControlSource> s) && this.targetReference.TryGetTarget(out TTarget t);
|
||||
public bool IsAlive => this.sourceReference.TryGetTarget(out ChartImplementation s) && this.targetReference.TryGetTarget(out TTarget t);
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -59,7 +59,7 @@ namespace Microcharts
|
|||
/// </summary>
|
||||
public void Subsribe()
|
||||
{
|
||||
if (!this.isSubscribed && this.sourceReference.TryGetTarget(out ChartImplementation<TControlSource> source))
|
||||
if (!this.isSubscribed && this.sourceReference.TryGetTarget(out ChartImplementation source))
|
||||
{
|
||||
source.Invalidated += this.OnEvent;
|
||||
this.isSubscribed = true;
|
||||
|
@ -73,7 +73,7 @@ namespace Microcharts
|
|||
{
|
||||
if (this.isSubscribed)
|
||||
{
|
||||
if (this.sourceReference.TryGetTarget(out ChartImplementation<TControlSource> source))
|
||||
if (this.sourceReference.TryGetTarget(out ChartImplementation source))
|
||||
{
|
||||
source.Invalidated -= this.OnEvent;
|
||||
}
|
||||
|
|
|
@ -12,16 +12,20 @@ namespace SimpleControls
|
|||
IBrush? Fill { get; set; }
|
||||
}
|
||||
|
||||
public class RadialGaugeImplementation<T> : StandardControlImplementation<T> where T : IRadialGauge
|
||||
public class RadialGaugeImplementation : StandardControlImplementation
|
||||
{
|
||||
public RadialGaugeImplementation(T control) : base(control)
|
||||
{ }
|
||||
private readonly IRadialGauge control;
|
||||
|
||||
public RadialGaugeImplementation(IRadialGauge control) : base((IStandardControlEnvironmentPeer)control)
|
||||
{
|
||||
this.control = control;
|
||||
}
|
||||
|
||||
public override IUIElement? Build()
|
||||
{
|
||||
var blueBrush = SolidColorBrush().Color(Colors.Blue);
|
||||
|
||||
return Rectangle() .Width(50) .Height(50) .Stroke(blueBrush) .Fill(Control.Fill);
|
||||
return Rectangle() .Width(50) .Height(50) .Stroke(blueBrush) .Fill(this.control.Fill);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace SimpleControls.Wpf
|
|||
|
||||
public BarChart()
|
||||
{
|
||||
InitImplementation(new BarChartImplementation<IBarChart>(this));
|
||||
InitImplementation(new BarChartImplementation(this));
|
||||
}
|
||||
|
||||
public IEnumerable<ChartEntry> Entries
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace SimpleControls.Wpf
|
|||
|
||||
public PointChart()
|
||||
{
|
||||
InitImplementation(new PointChartImplementation<IPointChart>(this));
|
||||
InitImplementation(new PointChartImplementation(this));
|
||||
}
|
||||
|
||||
public IEnumerable<ChartEntry> Entries
|
||||
|
|
|
@ -54,7 +54,7 @@ internal sealed class StandardUIControlAttribute : System.Attribute
|
|||
return;
|
||||
}
|
||||
|
||||
if (!SourceGenerator.TryGetTypeNamesFromInterface(interfaceFullTypeName, out string interfaceTypeName, out string interfaceNamespace, out string controlTypeName))
|
||||
if (!SourceGenerator.TryGetTypeNamesFromInterface(interfaceFullTypeName, out string interfaceNamespace, out string controlTypeName))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -68,11 +68,11 @@ using Microsoft.StandardUI.Wpf;
|
|||
|
||||
namespace SimpleControls.Wpf
|
||||
{{
|
||||
public class {controlTypeName} : StandardControl, {interfaceTypeName}
|
||||
public class {controlTypeName} : StandardControl, {interfaceFullTypeName}
|
||||
{{
|
||||
public {controlTypeName}()
|
||||
{{
|
||||
InitImplementation(new {interfaceNamespace}.{controlTypeName}Implementation<{interfaceTypeName}>(this));
|
||||
InitImplementation(new {interfaceNamespace}.{controlTypeName}Implementation(this));
|
||||
}}");
|
||||
|
||||
SourceGenerator.GenerateProperties(interfaceSymbol, controlTypeName, sourceCode);
|
||||
|
@ -165,24 +165,21 @@ namespace SimpleControls.Wpf
|
|||
/// Given the full name (with namespace) of an interface type, extracts various other related strings.
|
||||
/// </summary>
|
||||
/// <param name="interfaceFullTypeName">The full name (with namespace) of an interface type. For example, Contoso.Controls.IControl</param>
|
||||
/// <param name="interfaceTypeName">The interface's type name. For example, IControl</param>
|
||||
/// <param name="interfaceNamespace">The interface's namespace. For example, Contoso.Controls</param>
|
||||
/// <param name="controlTypeName">The default name of the class implementing the interface (by convention). For example, Control</param>
|
||||
/// <returns>True if the output strings were successfully determined, otherwise false.</returns>
|
||||
private static bool TryGetTypeNamesFromInterface(string interfaceFullTypeName, out string interfaceTypeName, out string interfaceNamespace, out string controlTypeName)
|
||||
private static bool TryGetTypeNamesFromInterface(string interfaceFullTypeName, out string interfaceNamespace, out string controlTypeName)
|
||||
{
|
||||
int lastDotIndex = interfaceFullTypeName.LastIndexOf('.');
|
||||
if (lastDotIndex < 3)
|
||||
{
|
||||
interfaceTypeName = null;
|
||||
interfaceNamespace = null;
|
||||
controlTypeName = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
interfaceTypeName = interfaceFullTypeName.Substring(lastDotIndex + 1);
|
||||
controlTypeName = interfaceFullTypeName.Substring(lastDotIndex + 2);
|
||||
interfaceNamespace = interfaceFullTypeName.Substring(0, lastDotIndex);
|
||||
controlTypeName = interfaceTypeName.Substring(1);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -95,14 +95,4 @@ namespace Microsoft.StandardUI.Controls
|
|||
return finalSize;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class StandardControlImplementation<T> : StandardControlImplementation where T : IControl
|
||||
{
|
||||
public T Control { get; }
|
||||
|
||||
public StandardControlImplementation(T control) : base((IStandardControlEnvironmentPeer)control)
|
||||
{
|
||||
Control = control;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче