Skip to content

Commit

Permalink
Merge pull request #318 from aldelaro5/avalonia11-preview6
Browse files Browse the repository at this point in the history
Upgrade to Avalonia 11.0.0-preview6
  • Loading branch information
danipen authored Mar 30, 2023
2 parents d9469b6 + a4e751a commit b036472
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<LangVersion>latest</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AvaloniaVersion>11.0.999-cibuild0031007-beta</AvaloniaVersion>
<AvaloniaVersion>11.0.0-preview6</AvaloniaVersion>
<TextMateSharpVersion>1.0.50</TextMateSharpVersion>
<NewtonsoftJsonVersion>13.0.1</NewtonsoftJsonVersion>
<VersionSuffix>beta</VersionSuffix>
Expand Down
4 changes: 2 additions & 2 deletions src/AvaloniaEdit.Demo/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public MainWindow()
_textEditor.ShowLineNumbers = true;
_textEditor.ContextMenu = new ContextMenu
{
Items = new List<MenuItem>
ItemsSource = new List<MenuItem>
{
new MenuItem { Header = "Copy", InputGesture = new KeyGesture(Key.C, KeyModifiers.Control) },
new MenuItem { Header = "Paste", InputGesture = new KeyGesture(Key.V, KeyModifiers.Control) },
Expand Down Expand Up @@ -84,7 +84,7 @@ public MainWindow()
Language csharpLanguage = _registryOptions.GetLanguageByExtension(".cs");

_syntaxModeCombo = this.FindControl<ComboBox>("syntaxModeCombo");
_syntaxModeCombo.Items = _registryOptions.GetAvailableLanguages();
_syntaxModeCombo.ItemsSource = _registryOptions.GetAvailableLanguages();
_syntaxModeCombo.SelectedItem = csharpLanguage;
_syntaxModeCombo.SelectionChanged += SyntaxModeCombo_SelectionChanged;

Expand Down
4 changes: 2 additions & 2 deletions src/AvaloniaEdit/CodeCompletion/CompletionList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
_listBox = e.NameScope.Find("PART_ListBox") as CompletionListBox;
if (_listBox != null)
{
_listBox.Items = _completionData;
_listBox.ItemsSource = _completionData;
}
}

Expand Down Expand Up @@ -294,7 +294,7 @@ where quality > 0

_currentList = listBoxItems;
//_listBox.Items = null; Makes no sense? Tooltip disappeared because of this
_listBox.Items = listBoxItems;
_listBox.ItemsSource = listBoxItems;
SelectIndexCentered(bestIndex);
}

Expand Down
2 changes: 1 addition & 1 deletion src/AvaloniaEdit/CodeCompletion/CompletionWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public CompletionWindow(TextArea textArea) : base(textArea)
{
IsLightDismissEnabled = true,
PlacementTarget = this,
PlacementMode = PlacementMode.Right,
Placement = PlacementMode.Right,
Child = _toolTipContent,
};

Expand Down
2 changes: 1 addition & 1 deletion src/AvaloniaEdit/CodeCompletion/CompletionWindowBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public CompletionWindowBase(TextArea textArea) : base()
StartOffset = EndOffset = TextArea.Caret.Offset;

PlacementTarget = TextArea.TextView;
PlacementMode = PlacementMode.AnchorAndGravity;
Placement = PlacementMode.AnchorAndGravity;
PlacementAnchor = Avalonia.Controls.Primitives.PopupPositioning.PopupAnchor.TopLeft;
PlacementGravity = Avalonia.Controls.Primitives.PopupPositioning.PopupGravity.BottomRight;

Expand Down
4 changes: 2 additions & 2 deletions src/AvaloniaEdit/Editing/Caret.cs
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ public Rect CalculateCaretRectangle()
var visualLine = _textView.GetOrConstructVisualLine(_textView.Document.GetLineByNumber(_position.Line));
return _textArea.OverstrikeMode ? CalcCaretOverstrikeRectangle(visualLine) : CalcCaretRectangle(visualLine);
}
return Rect.Empty;
return default;
}

/// <summary>
Expand All @@ -465,7 +465,7 @@ public void BringCaretToView()
public void BringCaretToView(double border)
{
var caretRectangle = CalculateCaretRectangle();
if (!caretRectangle.IsEmpty)
if (caretRectangle != default)
{
caretRectangle = caretRectangle.Inflate(border);
_textView.MakeVisible(caretRectangle);
Expand Down
2 changes: 1 addition & 1 deletion src/AvaloniaEdit/Editing/TextArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,7 @@ public Rect CursorRectangle
{
if(_textArea == null)
{
return Rect.Empty;
return default;
}

var transform = _textArea.TextView.TransformToVisual(_textArea);
Expand Down
6 changes: 3 additions & 3 deletions src/AvaloniaEdit/Rendering/BackgroundGeometryBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ private static IEnumerable<Rect> ProcessTextLines(TextView textView, VisualLine
int segmentStartVcInLine = Math.Max(segmentStartVc, visualStartCol);
int segmentEndVcInLine = Math.Min(segmentEndVc, visualEndCol);
y -= scrollOffset.Y;
Rect lastRect = Rect.Empty;
Rect lastRect = default;
if (segmentStartVcInLine == segmentEndVcInLine) {
// GetTextBounds crashes for length=0, so we'll handle this case with GetDistanceFromCharacterHit
// We need to return a rectangle to ensure empty lines are still visible
Expand All @@ -229,7 +229,7 @@ private static IEnumerable<Rect> ProcessTextLines(TextView textView, VisualLine
foreach (var b in line.GetTextBounds(segmentStartVcInLine, segmentEndVcInLine - segmentStartVcInLine)) {
double left = b.Rectangle.Left - scrollOffset.X;
double right = b.Rectangle.Right - scrollOffset.X;
if (!lastRect.IsEmpty)
if (lastRect != default)
yield return lastRect;
// left>right is possible in RTL languages
lastRect = new Rect(Math.Min(left, right), y, Math.Abs(right - left), line.Height);
Expand Down Expand Up @@ -261,7 +261,7 @@ private static IEnumerable<Rect> ProcessTextLines(TextView textView, VisualLine
right = visualLine.GetTextLineVisualXPosition(lastTextLine, segmentEndVc);
}
Rect extendSelection = new Rect(Math.Min(left, right), y, Math.Abs(right - left), line.Height);
if (!lastRect.IsEmpty) {
if (lastRect != default) {
if (extendSelection.Intersects(lastRect)) {
lastRect.Union(extendSelection);
yield return lastRect;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public TabGlyphRun(TabTextElement element, TextRunProperties properties)

public override double Baseline => _element.Text.Baseline;

public override Size Size => Size.Empty;
public override Size Size => default;

public override void Draw(DrawingContext drawingContext, Point origin)
{
Expand Down
2 changes: 1 addition & 1 deletion src/AvaloniaEdit/Rendering/TextView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1952,7 +1952,7 @@ private static ImmutablePen CreateFrozenPen(IBrush brush)

bool ILogicalScrollable.BringIntoView(Control target, Rect rectangle)
{
if (rectangle.IsEmpty || target == null || target == this || !this.IsVisualAncestorOf(target))
if (rectangle == default || target == null || target == this || !this.IsVisualAncestorOf(target))
{
return false;
}
Expand Down
15 changes: 12 additions & 3 deletions test/AvaloniaEdit.Tests/AvaloniaMocks/MockFontManagerImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

using System.Collections.Generic;
using System.Globalization;
using System.IO;

#nullable enable

Expand All @@ -24,7 +25,7 @@ public string GetDefaultFontFamilyName()
return _defaultFamilyName;
}

public IEnumerable<string> GetInstalledFontFamilyNames(bool checkForUpdates = false)
public string[] GetInstalledFontFamilyNames(bool checkForUpdates = false)
{
return new[] { _defaultFamilyName };
}
Expand All @@ -37,9 +38,17 @@ public bool TryMatchCharacter(int codepoint, FontStyle fontStyle, FontWeight fon
return true;
}

public IGlyphTypeface CreateGlyphTypeface(Typeface typeface)
public bool TryCreateGlyphTypeface(string familyName, FontStyle style, FontWeight weight,
FontStretch stretch, out IGlyphTypeface glyphTypeface)
{
return new MockGlyphTypeface();
glyphTypeface = new MockGlyphTypeface();
return true;
}

public bool TryCreateGlyphTypeface(Stream stream, out IGlyphTypeface glyphTypeface)
{
glyphTypeface = new MockGlyphTypeface();
return true;
}
}
}
4 changes: 2 additions & 2 deletions test/AvaloniaEdit.Tests/AvaloniaMocks/MockGlyphRun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public MockGlyphRun(IReadOnlyList<GlyphInfo> glyphInfos)
width += glyphInfos[i].GlyphAdvance;
}

Size = new Size(width, 10);
Bounds = new Rect(new Size(width, 10));
}

public Size Size { get; }
public Rect Bounds { get; }

public Point BaselineOrigin => new Point(0, 8);

Expand Down
5 changes: 5 additions & 0 deletions test/AvaloniaEdit.Tests/AvaloniaMocks/MockGlyphTypeface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class MockGlyphTypeface : IGlyphTypeface
IsFixedPitch = true
};

public FontStretch Stretch { get; }
public int GlyphCount => 1337;

public FontSimulations FontSimulations => throw new NotImplementedException();
Expand Down Expand Up @@ -62,6 +63,10 @@ public bool TryGetTable(uint tag, out byte[] table)
return false;
}

public string FamilyName => "";
public FontWeight Weight => FontWeight.Normal;
public FontStyle Style => FontStyle.Normal;

public bool TryGetGlyphMetrics(ushort glyph, out GlyphMetrics metrics)
{
metrics = new GlyphMetrics
Expand Down

1 comment on commit b036472

@SKProCH
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this was published as a new version for nuget?

Please sign in to comment.