Skip to content

Commit

Permalink
Merge branch 'tomlm/accessText' of https://github.com/jinek/Consolonia
Browse files Browse the repository at this point in the history
…into tomlm/accessText
  • Loading branch information
tomlm committed Dec 14, 2024
2 parents b7b4443 + e616d81 commit 64fb797
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 25 deletions.
24 changes: 11 additions & 13 deletions src/Consolonia.Core/Drawing/StreamGeometryImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ internal class StreamGeometryImpl : IStreamGeometryImpl
{
private readonly List<Rectangle> _fills;
private readonly List<Line> _strokes;
private Rect _bounds;

public StreamGeometryImpl()
{
Expand All @@ -25,23 +24,25 @@ public StreamGeometryImpl()
public IReadOnlyList<Rectangle> 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)
Expand Down Expand Up @@ -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));
}

/// <inheritdoc />
Expand Down
19 changes: 12 additions & 7 deletions src/Consolonia.Gallery/View/ControlsListView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,34 @@
</Window.Resources>
<DockPanel>
<Grid RowDefinitions="* Auto" DockPanel.Dock="Left">
<DataGrid x:Name="Grid" Grid.Row="0"
<DataGrid x:Name="GalleryGrid" Grid.Row="0"
SelectedIndex="0"
SelectionMode="Single">
<DataGrid.Columns>
<DataGridTextColumn Header="Name"
Binding="{Binding Name}" />
</DataGrid.Columns>
</DataGrid>
<Grid Grid.Row="1" RowDefinitions="Auto Auto" ColumnDefinitions="Auto *">
<Grid Grid.Row="1" RowDefinitions="Auto Auto" ColumnDefinitions="Auto *" Margin="0 0 0 1">
<Label Content="Theme" />
<ComboBox Grid.Column="1" x:Name="ThemeCombo" SelectionChanged="ComboBox_SelectionChanged" IsTabStop="false" HorizontalContentAlignment="Stretch">
<ComboBox Grid.Column="1" x:Name="ThemeCombo" SelectionChanged="ComboBox_SelectionChanged" IsTabStop="false" HorizontalContentAlignment="Stretch" >
<ComboBoxItem Content="Material" IsSelected="True" />
<ComboBoxItem Content="Fluent"/>
<ComboBoxItem Content="TurboVision"/>
<ComboBoxItem Content="TurboVisionDark"/>
<ComboBoxItem Content="TurboVisionBlack"/>
</ComboBox>
<Button Grid.Row="1" Grid.ColumnSpan="2" Click="Exit_Click" IsTabStop="False">Exit</Button>
</Grid>

</Grid>
<Border Child="{Binding ElementName=Grid,Path=SelectedItem, Converter={StaticResource GalleryItemConverter}}"
BorderThickness="1"
BorderBrush="{DynamicResource ThemeBorderBrush}" />
<Grid RowDefinitions="* Auto">
<Border Child="{Binding ElementName=GalleryGrid,Path=SelectedItem, Converter={StaticResource GalleryItemConverter}}"
BorderThickness="1"
BorderBrush="{DynamicResource ThemeBorderBrush}" />
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Row="1">
<Button Click="OnShowXaml" IsTabStop="False" HorizontalAlignment="Right">Show XAML</Button>
<Button Click="Exit_Click" IsTabStop="False">Exit</Button>
</StackPanel>
</Grid>
</DockPanel>
</Window>
23 changes: 19 additions & 4 deletions src/Consolonia.Gallery/View/ControlsListView.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Avalonia;
using Avalonia.Controls;
Expand Down Expand Up @@ -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)
Expand All @@ -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;
}

Expand All @@ -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();
}


Expand All @@ -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 ||
Expand Down
15 changes: 15 additions & 0 deletions src/Consolonia.Gallery/View/XamlDialogWindow.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<controls:DialogWindow xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:controls="clr-namespace:Consolonia.Core.Controls;assembly=Consolonia.Core"
HorizontalAlignment="Center"
VerticalAlignment="Center"
x:Class="Consolonia.Gallery.View.XamlDialogWindow">
<ScrollViewer HorizontalScrollBarVisibility="Visible"
VerticalScrollBarVisibility="Visible"
Focusable="True">
<SelectableTextBlock Name="Xaml" Text="{Binding}" />
</ScrollViewer>
</controls:DialogWindow>
35 changes: 35 additions & 0 deletions src/Consolonia.Gallery/View/XamlDialogWindow.axaml.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
}
2 changes: 1 addition & 1 deletion src/Tests/Consolonia.Gallery.Tests/ListBoxTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}

0 comments on commit 64fb797

Please sign in to comment.