Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Avalonia 0.10.0-preview4 #7

Merged
merged 3 commits into from
Apr 5, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Adapters/AvaloniaAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected override RBrush CreateLinearGradientBrush(RRect rect, RColor color1, R
{
StartPoint = new RelativePoint(x, y, RelativeUnit.Relative),
EndPoint = new RelativePoint(1 - x, 1 - y, RelativeUnit.Relative),
GradientStops = new[]
GradientStops = new GradientStops()
{
new GradientStop(startColor, 0),
new GradientStop(endColor, 1)
Expand Down
2 changes: 1 addition & 1 deletion Adapters/ControlAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public override RPoint MouseLocation
{
get
{
var pos = (_control.GetVisualRoot() as IInputRoot)?.MouseDevice?.Position ?? default(Point);
var pos = (_control.GetVisualRoot() as IInputRoot)?.MouseDevice?.Position ?? default(PixelPoint);
return Util.Convert(pos);
}
}
Expand Down
15 changes: 8 additions & 7 deletions Adapters/GraphicsAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public override void ReturnPreviousSmoothingMode(Object prevMode)
public override RSize MeasureString(string str, RFont font)
{
var text = GetText(str, font);
var measure = text.Measure();
var measure = text.Bounds;
return new RSize(measure.Width, measure.Height);

}
Expand All @@ -120,14 +120,15 @@ FormattedText GetText(string str, RFont font)
return new FormattedText
{
Text = str,
Typeface = new Typeface(f.Name, font.Size, f.FontStyle, f.Weight),
Typeface = new Typeface(f.Name, /*font.Size, */f.FontStyle, f.Weight),
Splitwirez marked this conversation as resolved.
Show resolved Hide resolved
FontSize = font.Size
};
}

public override void MeasureString(string str, RFont font, double maxWidth, out int charFit, out double charFitWidth)
{
var text = GetText(str, font);
var fullLength = text.Measure().Width;
var fullLength = text.Bounds.Width;
if (fullLength < maxWidth)
{
charFitWidth = fullLength;
Expand All @@ -140,7 +141,7 @@ public override void MeasureString(string str, RFont font, double maxWidth, out
BinarySearch(len =>
{
text = GetText(str.Substring(0, len), font);
var size = text.Measure().Width;
var size = text.Bounds.Width;
lastMeasure = size;
lastLen = len;
if (size <= maxWidth)
Expand All @@ -151,7 +152,7 @@ public override void MeasureString(string str, RFont font, double maxWidth, out
if (lastMeasure > maxWidth)
{
lastLen--;
lastMeasure = GetText(str.Substring(0, lastLen), font).Measure().Width;
lastMeasure = GetText(str.Substring(0, lastLen), font).Bounds.Width;
}
charFit = lastLen;
charFitWidth = lastMeasure;
Expand Down Expand Up @@ -253,12 +254,12 @@ public override void DrawRectangle(RBrush brush, double x, double y, double widt

public override void DrawImage(RImage image, RRect destRect, RRect srcRect)
{
_g.DrawImage(((ImageAdapter) image).Image, 1, Util.Convert(srcRect), Util.Convert(destRect));
_g.DrawImage(((ImageAdapter) image).Image, /*1, */Util.Convert(srcRect), Util.Convert(destRect));
}

public override void DrawImage(RImage image, RRect destRect)
{
_g.DrawImage(((ImageAdapter) image).Image, 1, new Rect(0, 0, image.Width, image.Height),
_g.DrawImage(((ImageAdapter) image).Image, /*1, */new Rect(0, 0, image.Width, image.Height),
Util.Convert(destRect));
}

Expand Down
4 changes: 2 additions & 2 deletions Adapters/ImageAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public ImageAdapter(Bitmap image)
/// </summary>
public Bitmap Image => _image;

public override double Width => _image.PixelWidth;
public override double Width => _image.PixelSize.Width;

public override double Height => _image.PixelHeight;
public override double Height => _image.PixelSize.Height;

public override void Dispose()
{
Expand Down
8 changes: 4 additions & 4 deletions Adapters/PenAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ public override RDashStyle DashStyle
private static readonly Dictionary<RDashStyle, DashStyle> DashStyles = new Dictionary<RDashStyle, DashStyle>
{
{RDashStyle.Solid,null },
{RDashStyle.Dash, global::Avalonia.Media.DashStyle.Dash },
{RDashStyle.DashDot, global::Avalonia.Media.DashStyle.DashDot },
{RDashStyle.DashDotDot, global::Avalonia.Media.DashStyle.DashDotDot },
{RDashStyle.Dot, global::Avalonia.Media.DashStyle.Dot }
{RDashStyle.Dash, null/*global::Avalonia.Media.DashStyle.Dash*/ },
{RDashStyle.DashDot, null/*global::Avalonia.Media.DashStyle.DashDot*/ },
{RDashStyle.DashDotDot, null/*global::Avalonia.Media.DashStyle.DashDotDot*/ },
{RDashStyle.Dot, null/*global::Avalonia.Media.DashStyle.Dot*/ }
};

/// <summary>
Expand Down
5 changes: 3 additions & 2 deletions Avalonia.HtmlRenderer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
<Compile Include="Utilities\Util.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.6.1" />
<PackageReference Include="Avalonia" Version="0.10.0-preview4" />
<PackageReference Include="System.Reactive.Core" Version="4.4.1" />
</ItemGroup>
</Project>
</Project>
23 changes: 14 additions & 9 deletions HtmlControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,17 @@ public class HtmlControl : Control
protected Point _lastScrollOffset;

public static readonly AvaloniaProperty AvoidImagesLateLoadingProperty =
PropertyHelper.Register<HtmlControl, bool>(nameof(AvoidImagesLateLoading), false, OnAvaloniaProperty_valueChanged);
AvaloniaProperty.Register<HtmlControl, bool>(nameof(AvoidImagesLateLoading), defaultValue: false);
public static readonly AvaloniaProperty IsSelectionEnabledProperty =
PropertyHelper.Register<HtmlControl, bool>(nameof(IsSelectionEnabled), true, OnAvaloniaProperty_valueChanged);
AvaloniaProperty.Register<HtmlControl, bool>(nameof(IsSelectionEnabled), defaultValue: true);
public static readonly AvaloniaProperty IsContextMenuEnabledProperty =
PropertyHelper.Register<HtmlControl, bool>(nameof(IsContextMenuEnabled), true, OnAvaloniaProperty_valueChanged);
AvaloniaProperty.Register<HtmlControl, bool>(nameof(IsContextMenuEnabled), defaultValue: true);

public static readonly AvaloniaProperty BaseStylesheetProperty =
PropertyHelper.Register<HtmlControl, string>(nameof(BaseStylesheet), null, OnAvaloniaProperty_valueChanged);
AvaloniaProperty.Register<HtmlControl, string>(nameof(BaseStylesheet), defaultValue: null);

public static readonly AvaloniaProperty TextProperty =
PropertyHelper.Register<HtmlControl, string>(nameof(Text), null, OnAvaloniaProperty_valueChanged);
AvaloniaProperty.Register<HtmlControl, string>(nameof(Text), defaultValue: null);

public static readonly StyledProperty<IBrush> BackgroundProperty =
Border.BackgroundProperty.AddOwner<HtmlControl>();
Expand Down Expand Up @@ -117,12 +117,18 @@ static HtmlControl()
{
FocusableProperty.OverrideDefaultValue(typeof(HtmlControl), true);
AffectsRender(TextProperty);

AvoidImagesLateLoadingProperty.Changed.AddClassHandler<HtmlControl>(OnAvaloniaProperty_valueChanged);
IsSelectionEnabledProperty.Changed.AddClassHandler<HtmlControl>(OnAvaloniaProperty_valueChanged);
IsContextMenuEnabledProperty.Changed.AddClassHandler<HtmlControl>(OnAvaloniaProperty_valueChanged);
BaseStylesheetProperty.Changed.AddClassHandler<HtmlControl>(OnAvaloniaProperty_valueChanged);
TextProperty.Changed.AddClassHandler<HtmlControl>(OnAvaloniaProperty_valueChanged);
}

/// <summary>
/// Creates a new HtmlPanel and sets a basic css for it's styling.
/// </summary>
protected HtmlControl()
public HtmlControl()
{
_htmlContainer = new HtmlContainer();
_htmlContainer.LoadComplete += OnLoadComplete;
Expand Down Expand Up @@ -521,8 +527,7 @@ protected virtual void InvokeMouseMove()
/// <summary>
/// Handle when dependency property value changes to update the underline HtmlContainer with the new value.
/// </summary>
private static void OnAvaloniaProperty_valueChanged(AvaloniaObject AvaloniaObject,
AvaloniaPropertyChangedEventArgs e)
private static void OnAvaloniaProperty_valueChanged(IAvaloniaObject AvaloniaObject, AvaloniaPropertyChangedEventArgs e)
{
var control = AvaloniaObject as HtmlControl;
if (control != null)
Expand Down Expand Up @@ -612,4 +617,4 @@ private void OnRefresh(object sender, HtmlRefreshEventArgs e)
Dispatcher.UIThread.InvokeAsync(() => OnRefresh(e)).Wait();
}
}
}
}
4 changes: 2 additions & 2 deletions HtmlLabel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected override Size MeasureOverride(Size constraint)
/// <summary>
/// Handle when dependency property value changes to update the underline HtmlContainer with the new value.
/// </summary>
private static void OnAvaloniaProperty_valueChanged(AvaloniaObject AvaloniaObject, AvaloniaPropertyChangedEventArgs e)
private static Action<IAvaloniaObject, AvaloniaPropertyChangedEventArgs> OnAvaloniaProperty_valueChanged = new Action<IAvaloniaObject, AvaloniaPropertyChangedEventArgs>((AvaloniaObject, e) =>
{
var control = AvaloniaObject as HtmlLabel;
if (control != null)
Expand All @@ -106,7 +106,7 @@ private static void OnAvaloniaProperty_valueChanged(AvaloniaObject AvaloniaObjec
}
}
}
}
});

#endregion
}
Expand Down
24 changes: 23 additions & 1 deletion PropertyHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Avalonia.HtmlRenderer
static class PropertyHelper
{

public static AvaloniaProperty Register<TOwner, T>(string name, T def, Action<AvaloniaObject, AvaloniaPropertyChangedEventArgs> changed) where TOwner : AvaloniaObject
/*public static AvaloniaProperty Register<TOwner, T>(string name, T def, Action<AvaloniaObject, AvaloniaPropertyChangedEventArgs> changed) where TOwner : AvaloniaObject
{
var pp = AvaloniaProperty.Register<TOwner, T>(name, def);
Action<AvaloniaPropertyChangedEventArgs> cb = args =>
Expand All @@ -20,5 +20,27 @@ static class PropertyHelper
pp.Changed.Subscribe(cb);
return pp;
}



*/public static AvaloniaProperty Register<TOwner, T>(string name, T def, Action<IAvaloniaObject, AvaloniaPropertyChangedEventArgs> changed) where TOwner : IAvaloniaObject
{
var pp = AvaloniaProperty.Register<TOwner, T>(name, def);

/*IObserver<AvaloniaPropertyChangedEventArgs> cb = new Observer<AvaloniaPropertyChangedEventArgs>.Create((args) =>
{
changed(args.Sender, args);
});*/

pp.Changed.Subscribe(args =>
{
changed.Invoke(args.Sender, args);
/*if ((args != null) && (args.Sender != null) && (changed != null))
changed(args.Sender, args);*/
});

//pp.Changed.Subscribe(changed);
return pp;
}
}
}
8 changes: 8 additions & 0 deletions Utilities/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ public static RPoint Convert(Point p)
return new RPoint(p.X, p.Y);
}

/// <summary>
/// Convert from Avalonia PixelPoint to core point.
/// </summary>
public static RPoint Convert(PixelPoint p)
{
return new RPoint(p.X, p.Y);
}

/// <summary>
/// Convert from WPF point to core point.
/// </summary>
Expand Down