Focus next/previous input element with Tab
This commit is contained in:
@@ -301,13 +301,15 @@ public sealed class Grid<T> : ChildContainerView<Grid<T>, T>, IVisibilityChangeH
|
||||
var x = positionExtension?.Column ?? 0;
|
||||
var y = positionExtension?.Row ?? 0;
|
||||
|
||||
if (x > columns)
|
||||
Debug.Assert(x < columns, "Child requests column outside of grid");
|
||||
if (x >= columns)
|
||||
{
|
||||
Logger?.LogWarning("Child {Child} is out of bounds, x: {X}, y: {Y}", view, x, y);
|
||||
x = 0;
|
||||
}
|
||||
|
||||
if (y > rows)
|
||||
Debug.Assert(y < rows, "Child requests row outside of grid");
|
||||
if (y >= rows)
|
||||
{
|
||||
Logger?.LogWarning("Child {Child} is out of bounds, x: {X}, y: {Y}", view, x, y);
|
||||
y = 0;
|
||||
@@ -339,15 +341,27 @@ public sealed class Grid<T> : ChildContainerView<Grid<T>, T>, IVisibilityChangeH
|
||||
Span<int> allWidth = stackalloc int[columns * rows];
|
||||
Span<int> allHeight = stackalloc int[columns * rows];
|
||||
|
||||
//Store the largest width and height for a cell
|
||||
foreach (var child in Children)
|
||||
{
|
||||
var childSize = child.GetRequestedSize();
|
||||
var (x, y) = GetViewColumnAndRow(child, columns, rows);
|
||||
|
||||
allWidth.SetToMatrix(childSize.Width, x, y, columns);
|
||||
allHeight.SetToMatrix(childSize.Height, x, y, columns);
|
||||
var currentWidth = allWidth.GetFromMatrix(x, y, columns);
|
||||
var currentHeight = allHeight.GetFromMatrix(x, y, columns);
|
||||
|
||||
if (currentWidth < childSize.Width)
|
||||
{
|
||||
allWidth.SetToMatrix(childSize.Width, x, y, columns);
|
||||
}
|
||||
|
||||
if (currentHeight < childSize.Height)
|
||||
{
|
||||
allHeight.SetToMatrix(childSize.Height, x, y, columns);
|
||||
}
|
||||
}
|
||||
|
||||
//Calculate the width and height for each column and row
|
||||
Span<int> columnWidths = stackalloc int[columns];
|
||||
Span<int> rowHeights = stackalloc int[rows];
|
||||
|
||||
@@ -407,6 +421,7 @@ public sealed class Grid<T> : ChildContainerView<Grid<T>, T>, IVisibilityChangeH
|
||||
usedHeight += rowHeights[i];
|
||||
}
|
||||
|
||||
//Calculate the width and height for each column and row with star value if size of the current grid is given
|
||||
if (size.IsSome)
|
||||
{
|
||||
var widthLeft = size.Value.Width - usedWidth;
|
||||
|
||||
@@ -31,6 +31,7 @@ public interface IView : INotifyPropertyChanged, IDisposableCollection
|
||||
RenderMethod RenderMethod { get; set; }
|
||||
IView? VisualParent { get; set; }
|
||||
ReadOnlyObservableCollection<IView> VisualChildren { get; }
|
||||
bool IsFocusBoundary { get; set; }
|
||||
event Action<IView> Disposed;
|
||||
|
||||
Size GetRequestedSize();
|
||||
|
||||
@@ -38,15 +38,21 @@ public sealed partial class ItemsControl<TDataContext, TItem>
|
||||
|
||||
if (_itemsSource is ObservableCollection<TItem> observableDeclarative)
|
||||
{
|
||||
var consumer = new OcConsumer();
|
||||
_children = observableDeclarative
|
||||
.Selecting(i => CreateItem(i))
|
||||
.OfTypeComputing<IView<TItem>>();
|
||||
.OfTypeComputing<IView<TItem>>()
|
||||
.For(consumer);
|
||||
_itemsDisposables.Add(consumer);
|
||||
}
|
||||
else if (_itemsSource is ReadOnlyObservableCollection<TItem> readOnlyObservableDeclarative)
|
||||
{
|
||||
var consumer = new OcConsumer();
|
||||
_children = readOnlyObservableDeclarative
|
||||
.Selecting(i => CreateItem(i))
|
||||
.OfTypeComputing<IView<TItem>>();
|
||||
.OfTypeComputing<IView<TItem>>()
|
||||
.For(consumer);
|
||||
_itemsDisposables.Add(consumer);
|
||||
}
|
||||
else if (_itemsSource is ICollection<TItem> collection)
|
||||
_children = collection.Select(CreateItem).OfType<IView<TItem>>().ToList();
|
||||
|
||||
@@ -34,6 +34,7 @@ public abstract partial class View<TConcrete, T> : IView<T> where TConcrete : Vi
|
||||
[Notify] private IApplicationContext? _applicationContext;
|
||||
[Notify] private bool _attached;
|
||||
[Notify] private IView? _visualParent;
|
||||
[Notify] private bool _isFocusBoundary;
|
||||
|
||||
protected List<Action<TConcrete, GeneralKeyEventArgs>> KeyHandlers { get; } = new();
|
||||
protected ObservableCollection<IView> VisualChildren { get; } = new();
|
||||
|
||||
Reference in New Issue
Block a user