Skip to content

Commit

Permalink
Upgrade Avalonia to 11.2.1 (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlm authored Dec 2, 2024
1 parent bfae13f commit 64bbfce
Show file tree
Hide file tree
Showing 21 changed files with 215 additions and 60 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
<NoWarn>AVA3001</NoWarn>
</PropertyGroup>
<PropertyGroup>
<AvaloniaVersion>11.0.9</AvaloniaVersion>
<AvaloniaVersion>11.2.1</AvaloniaVersion>
</PropertyGroup>
</Project>
4 changes: 1 addition & 3 deletions src/Consolonia.Core/Consolonia.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.ReactiveUI" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.FreeDesktop" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.Skia" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.Desktop" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.Controls.DataGrid" Version="$(AvaloniaVersion)" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.3.2" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.8" />
Expand Down
36 changes: 23 additions & 13 deletions src/Consolonia.Core/Controls/MessageBox.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,7 @@ public MessageBox()

InitializeComponent();

AttachedToVisualTree += (_, _) =>
{
// we don't hook this up until the dialog is shown as the visible state is driven off of the DataContext
// which is set at ShowDialogAsync() time.
if (OkButton.IsVisible)
OkButton.AttachedToVisualTree += (_, _) => OkButton.Focus();
else if (YesButton.IsVisible)
YesButton.AttachedToVisualTree += (_, _) => YesButton.Focus();
else if (CancelButton.IsVisible)
CancelButton.AttachedToVisualTree += (_, _) => CancelButton.Focus();
else if (NoButton.IsVisible)
NoButton.AttachedToVisualTree += (_, _) => NoButton.Focus();
};
AttachedToVisualTree += OnShowDialog;
}

public Mode Mode
Expand Down Expand Up @@ -88,6 +76,28 @@ public object No
set => SetAndRaise(NoProperty, ref _no, value);
}

private void OnShowDialog(object sender, VisualTreeAttachmentEventArgs e)
{
// we don't hook this up until the dialog is shown as the visible state is driven off of the DataContext
// which is set at ShowDialogAsync() time.
AttachedToVisualTree -= OnShowDialog;
if (OkButton.IsVisible)
OkButton.AttachedToVisualTree += ButtonAttached;
else if (YesButton.IsVisible)
YesButton.AttachedToVisualTree += ButtonAttached;
else if (CancelButton.IsVisible)
CancelButton.AttachedToVisualTree += ButtonAttached;
else if (NoButton.IsVisible)
NoButton.AttachedToVisualTree += ButtonAttached;
}

private void ButtonAttached(object sender, VisualTreeAttachmentEventArgs e)
{
var button = (Button)sender;
button.AttachedToVisualTree -= ButtonAttached;
button.Focus();
}

public async Task<MessageBoxResult> ShowDialogAsync(Control parent, string text, string title = null)
{
DataContext = new MessageBoxViewModel(Mode, Ok, Cancel, Yes, No, text, title ?? Title);
Expand Down
12 changes: 9 additions & 3 deletions src/Consolonia.Core/Drawing/ConsoleBrush.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,16 @@ public static ConsoleBrush FromPosition(IBrush brush, int x, int y, int width, i
// Calculate the distance from the center
double dx = x - centerX;
double dy = y - centerY;
double distance = Math.Sqrt(dx * dx + dy * dy);

// Normalize the distance based on the brush radius
double normalizedDistance = distance / (Math.Min(width, height) * radialBrush.Radius);
// Calculate the distance based on separate X and Y radii
double distanceX = dx / (width * radialBrush.RadiusX.Scalar);
double distanceY = dy / (height * radialBrush.RadiusY.Scalar);
double distance = Math.Sqrt(distanceX * distanceX + distanceY * distanceY);

// Normalize the distance
double normalizedDistance = distance /
Math.Sqrt(radialBrush.RadiusX.Scalar * radialBrush.RadiusX.Scalar +
radialBrush.RadiusY.Scalar * radialBrush.RadiusY.Scalar);

// Clamp the normalized distance to [0, 1]
normalizedDistance = Math.Min(Math.Max(normalizedDistance, 0), 1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Avalonia;
using Avalonia.Platform;

namespace Consolonia.Core.Drawing
Expand All @@ -20,6 +21,13 @@ public IRenderTarget CreateRenderTarget(IEnumerable<object> surfaces)
return new RenderTarget(surfaces);
}

public IDrawingContextLayerImpl CreateOffscreenRenderTarget(PixelSize pixelSize, double scaling)
{
throw new NotImplementedException();
}

public bool IsLost => false;

public IReadOnlyDictionary<Type, object> PublicFeatures { get; } = new Dictionary<Type, object>();
}
}
7 changes: 7 additions & 0 deletions src/Consolonia.Core/Drawing/ConsoloniaRenderInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,17 @@ public bool IsSupportedBitmapPixelFormat(PixelFormat format)
throw new NotImplementedException();
}

public IPlatformRenderInterfaceRegion CreateRegion()
{
throw new NotImplementedException();
}

public bool SupportsIndividualRoundRects => false;

public AlphaFormat DefaultAlphaFormat => throw new NotImplementedException();

public PixelFormat DefaultPixelFormat => throw new NotImplementedException();

public bool SupportsRegions => false;
}
}
24 changes: 21 additions & 3 deletions src/Consolonia.Core/Drawing/DrawingContextImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public void DrawGlyphRun(IBrush foreground, IGlyphRunImpl glyphRun)
DrawStringInternal(foreground, text, glyphRun.GlyphTypeface);
}

public IDrawingContextLayerImpl CreateLayer(Size size)
public IDrawingContextLayerImpl CreateLayer(PixelSize size)
{
return new RenderTarget(_consoleWindow);
}
Expand All @@ -234,6 +234,11 @@ public void PushClip(RoundedRect clip)
PushClip(clip.Rect);
}

public void PushClip(IPlatformRenderInterfaceRegion region)
{
throw new NotImplementedException();
}

public void PopClip()
{
_clipStack.Pop();
Expand Down Expand Up @@ -286,14 +291,27 @@ public object GetFeature(Type t)
throw new NotImplementedException();
}

public RenderOptions RenderOptions { get; set; }

public Matrix Transform
{
get => _transform;
set => _transform = value * _postTransform;
}

public void DrawRegion(IBrush brush, IPen pen, IPlatformRenderInterfaceRegion region)
{
throw new NotImplementedException();
}

public void PushLayer(Rect bounds)
{
throw new NotImplementedException();
}

public void PopLayer()
{
throw new NotImplementedException();
}

/// <summary>
/// Draw a straight horizontal line or vertical line
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions src/Consolonia.Core/Drawing/Line.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ public bool TryGetSegment(double startDistance, double stopDistance, bool startO
public IGeometryImpl SourceGeometry { get; }
public Matrix Transform { get; }

public IGeometryImpl GetWidenedGeometry(IPen pen)
{
throw new NotImplementedException();
}

public static Line CreateMyLine(Point p1, Point p2)
{
(double x, double y) = p2 - p1;
Expand Down
5 changes: 5 additions & 0 deletions src/Consolonia.Core/Drawing/Rectangle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public bool TryGetSegment(double startDistance, double stopDistance, bool startO
throw new NotImplementedException();
}

public IGeometryImpl GetWidenedGeometry(IPen pen)
{
throw new NotImplementedException();
}

public Rect Bounds => _rect;
public double ContourLength => (_rect.Width + _rect.Height) * 2;
public IGeometryImpl SourceGeometry { get; }
Expand Down
13 changes: 5 additions & 8 deletions src/Consolonia.Core/Drawing/RenderTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,15 @@ void IDrawingContextLayerImpl.Blit(IDrawingContextImpl context)

bool IDrawingContextLayerImpl.CanBlit => true;

public IDrawingContextImpl CreateDrawingContext()
public bool IsCorrupted => false;

public IDrawingContextImpl CreateDrawingContext(bool useScaledDrawing)
{
if (useScaledDrawing)
throw new NotImplementedException("Consolonia doesn't support useScaledDrawing");
return new DrawingContextImpl(_consoleWindow);
}

public bool IsCorrupted => false;


private void OnResized(Size size, WindowResizeReason reason)
{
Expand Down Expand Up @@ -147,11 +149,6 @@ private void RenderToDevice()
}
}

public IDrawingContextImpl CreateDrawingContext(bool useScaledDrawing)
{
return new DrawingContextImpl(_consoleWindow);
}

private struct FlushingBuffer
{
//todo: move class out
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.VisualTree;
using Consolonia.Core.InternalHelpers;
Expand All @@ -15,9 +16,9 @@ public class ArrowsAndKeyboardNavigationHandler : IKeyboardNavigationHandler
//todo: check XTFocus https://github.com/jinek/Consolonia/issues/105#issuecomment-2089015880
private IInputRoot _owner;

public ArrowsAndKeyboardNavigationHandler(IKeyboardNavigationHandler keyboardNavigationHandler)
public ArrowsAndKeyboardNavigationHandler()
{
_keyboardNavigationHandler = keyboardNavigationHandler;
_keyboardNavigationHandler = new KeyboardNavigationHandler();
}

public void SetOwner(IInputRoot owner)
Expand Down Expand Up @@ -124,8 +125,26 @@ private void OnKeyDown(object sender, KeyEventArgs e)
{
if (e.Handled) return;

if (e.Source is MenuItem) return;

if (e.Key == Key.Escape)
{
// if there is a overlay popup, close it
OverlayPopupHost overlay = sender as OverlayPopupHost ??
((Visual)sender).FindDescendantOfType<OverlayPopupHost>();
if (overlay != null)
{
// it will have a popup as the parent.
var popup = overlay.Parent as Popup;
if (popup != null)
popup.Close();
e.Handled = true;
return;
}
}

//see FocusManager.GetFocusManager
IInputElement current = TopLevel.GetTopLevel((Visual)sender)!.FocusManager!.GetFocusedElement();
IInputElement current = TopLevel.GetTopLevel((Visual)sender)?.FocusManager?.GetFocusedElement();

if (e.KeyModifiers != KeyModifiers.None)
return;
Expand Down
Loading

0 comments on commit 64bbfce

Please sign in to comment.