From 09e3e086adf4af4e355d73ee92a428a35a5ea654 Mon Sep 17 00:00:00 2001 From: Tom Laird-McConnell Date: Fri, 13 Dec 2024 10:38:15 -0800 Subject: [PATCH 1/2] cleanup cloning as per review (#202) * cleanup cloning as per review --- .../Drawing/StreamGeometryImpl.cs | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/Consolonia.Core/Drawing/StreamGeometryImpl.cs b/src/Consolonia.Core/Drawing/StreamGeometryImpl.cs index 1ea540a6..e2279c9f 100644 --- a/src/Consolonia.Core/Drawing/StreamGeometryImpl.cs +++ b/src/Consolonia.Core/Drawing/StreamGeometryImpl.cs @@ -12,7 +12,6 @@ internal class StreamGeometryImpl : IStreamGeometryImpl { private readonly List _fills; private readonly List _strokes; - private Rect _bounds; public StreamGeometryImpl() { @@ -25,23 +24,25 @@ public StreamGeometryImpl() public IReadOnlyList Fills => _fills; // private SKPath _path; - public Rect Bounds => _bounds; + public Rect Bounds { get; private set; } public double ContourLength => _strokes.Sum(l => l.ContourLength); public IStreamGeometryImpl Clone() { - var clone = new StreamGeometryImpl(); - foreach (Line line in _strokes) clone._strokes.Add(line); - foreach (Rectangle rect in _fills) clone._fills.Add(rect); - clone._bounds = _bounds; - return clone; + var cloneGeometry = new StreamGeometryImpl(); + foreach (Line cloneLine in _strokes.Select(l => new Line(l.PStart, l.PEnd, this, l.Transform))) + cloneGeometry._strokes.Add(cloneLine); + foreach (Rectangle cloneRect in _fills.Select(r => new Rectangle(r.Rect, r, r.Transform))) + cloneGeometry._fills.Add(cloneRect); + cloneGeometry.Bounds = Bounds; + return cloneGeometry; } public bool FillContains(Point point) { - return _bounds.Contains(point); + return _fills.Any(rect => rect.FillContains(point)); } public Rect GetRenderBounds(IPen pen) @@ -177,11 +178,8 @@ public void LineTo(Point point) public void EndFigure(bool isClosed) { Rect bound = _geometryImpl._strokes.Aggregate(new Rect(), (rect, line) => rect.Union(line.Bounds)); - _geometryImpl._bounds = bound; - if (_isFilled) - { - // _geometryImpl._fills.Add(new Rectangle(bound)); - } + _geometryImpl.Bounds = bound; + if (_isFilled) _geometryImpl._fills.Add(new Rectangle(bound)); } /// From 2b741da279b57219cd9e2e4c639ddc17c79be6c3 Mon Sep 17 00:00:00 2001 From: Tom Laird-McConnell Date: Fri, 13 Dec 2024 10:46:46 -0800 Subject: [PATCH 2/2] Add ability to inspect XAML markup for gallery pages (#204) * Added ability to see Xaml for gallery page --- .../View/ControlsListView.axaml | 19 ++++++---- .../View/ControlsListView.axaml.cs | 23 +++++++++--- .../View/XamlDialogWindow.axaml | 15 ++++++++ .../View/XamlDialogWindow.axaml.cs | 35 +++++++++++++++++++ .../Consolonia.Gallery.Tests/ListBoxTests.cs | 2 +- 5 files changed, 82 insertions(+), 12 deletions(-) create mode 100644 src/Consolonia.Gallery/View/XamlDialogWindow.axaml create mode 100644 src/Consolonia.Gallery/View/XamlDialogWindow.axaml.cs diff --git a/src/Consolonia.Gallery/View/ControlsListView.axaml b/src/Consolonia.Gallery/View/ControlsListView.axaml index 60181320..5b4b2822 100644 --- a/src/Consolonia.Gallery/View/ControlsListView.axaml +++ b/src/Consolonia.Gallery/View/ControlsListView.axaml @@ -11,7 +11,7 @@ - @@ -19,21 +19,26 @@ Binding="{Binding Name}" /> - + - + + + + + + + \ No newline at end of file diff --git a/src/Consolonia.Gallery/View/ControlsListView.axaml.cs b/src/Consolonia.Gallery/View/ControlsListView.axaml.cs index 46073cfb..cbecca06 100644 --- a/src/Consolonia.Gallery/View/ControlsListView.axaml.cs +++ b/src/Consolonia.Gallery/View/ControlsListView.axaml.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using Avalonia; using Avalonia.Controls; @@ -33,7 +34,7 @@ public ControlsListView() #if DEBUG this.AttachDevTools(); #endif - this.Grid.ItemsSource = _items = GalleryItem.Enumerated.ToArray(); + this.GalleryGrid.ItemsSource = _items = GalleryItem.Enumerated.ToArray(); var lifetime = Application.Current!.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime; if (lifetime != null) @@ -52,7 +53,7 @@ private void TrySetupSelected() { if (_commandLineArgs.Length is not 1 and not 2) { - this.Grid.SelectedIndex = 0; + this.GalleryGrid.SelectedIndex = 0; return; } @@ -72,8 +73,8 @@ private void TrySetupSelected() $"Several gallery items found with provided name {itemToSelectName}"); } - this.Grid.SelectedItem = itemToSelect; - this.Grid.Focus(); + this.GalleryGrid.SelectedItem = itemToSelect; + this.GalleryGrid.Focus(); } @@ -88,6 +89,20 @@ private void Exit_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e) this.Close(); } + private async void OnShowXaml(object sender, Avalonia.Interactivity.RoutedEventArgs e) + { + var lifetime = (IClassicDesktopStyleApplicationLifetime)Application.Current.ApplicationLifetime; + + var selectedItem = GalleryGrid.SelectedItem as GalleryItem; + var path = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, "..", "..", "..", "Gallery", "GalleryViews", $"{selectedItem.Type.Name}.axaml")); + var dialog = new XamlDialogWindow() + { + DataContext = File.ReadAllText(path) + }; + + await dialog.ShowDialogAsync(lifetime.MainWindow); + } + private void ComboBox_SelectionChanged(object sender, Avalonia.Controls.SelectionChangedEventArgs e) { if (ThemeCombo?.SelectedItem is not ComboBoxItem selectedItem || diff --git a/src/Consolonia.Gallery/View/XamlDialogWindow.axaml b/src/Consolonia.Gallery/View/XamlDialogWindow.axaml new file mode 100644 index 00000000..3b96bde5 --- /dev/null +++ b/src/Consolonia.Gallery/View/XamlDialogWindow.axaml @@ -0,0 +1,15 @@ + + + + + \ No newline at end of file diff --git a/src/Consolonia.Gallery/View/XamlDialogWindow.axaml.cs b/src/Consolonia.Gallery/View/XamlDialogWindow.axaml.cs new file mode 100644 index 00000000..7d4cf23f --- /dev/null +++ b/src/Consolonia.Gallery/View/XamlDialogWindow.axaml.cs @@ -0,0 +1,35 @@ +using System.Linq; +using Avalonia; +using Avalonia.Input; +using Consolonia.Core.Controls; + +namespace Consolonia.Gallery.View +{ + public partial class XamlDialogWindow : DialogWindow + { + public XamlDialogWindow() + { + InitializeComponent(); + + AttachedToVisualTree += DialogWindowAttachedToVisualTree; + } + + private void DialogWindowAttachedToVisualTree(object sender, Avalonia.VisualTreeAttachmentEventArgs e) + { + AttachedToVisualTree -= DialogWindowAttachedToVisualTree; + + var child = this.LogicalChildren.FirstOrDefault(); + if (child is InputElement input) + input.AttachedToVisualTree += OnChildAttachedToVisualTree; + } + + private void OnChildAttachedToVisualTree(object sender, VisualTreeAttachmentEventArgs e) + { + if (sender is InputElement input) + { + input.AttachedToVisualTree -= OnChildAttachedToVisualTree; + input.Focus(); + } + } + } +} \ No newline at end of file diff --git a/src/Tests/Consolonia.Gallery.Tests/ListBoxTests.cs b/src/Tests/Consolonia.Gallery.Tests/ListBoxTests.cs index 3b99f9f4..5e650db0 100644 --- a/src/Tests/Consolonia.Gallery.Tests/ListBoxTests.cs +++ b/src/Tests/Consolonia.Gallery.Tests/ListBoxTests.cs @@ -16,7 +16,7 @@ public async Task PerformSingleTest() await UITest.KeyInput(Key.Tab, RawInputModifiers.Shift); await UITest.KeyInput(Key.Tab, RawInputModifiers.Shift); await UITest.KeyInput(Key.PageDown); - await UITest.AssertHasText("Item 53"); + await UITest.AssertHasText("Item 49"); } } } \ No newline at end of file