Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Grid row/column definitions styleable #4397

Closed
wants to merge 31 commits into from
Closed
Changes from 2 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
ea9a272
make row/col definitions styleable
jmacato Jul 29, 2020
ba3cc0f
make the magic happen
jmacato Jul 29, 2020
a7f5cd5
add null check
jmacato Jul 29, 2020
ee3e5ce
nit fixes
jmacato Jul 29, 2020
0a3c39c
whatever happened there
jmacato Jul 29, 2020
f8df56f
rename
jmacato Jul 29, 2020
a7524ec
Merge branch 'master' into styleable-grid-rowcoldefs
jmacato Jul 29, 2020
db6d99c
nit
jmacato Jul 29, 2020
c0a0469
simplify
jmacato Jul 29, 2020
af197fa
handle non-matching row/col changes
jmacato Jul 29, 2020
d68323c
handle row/col change in definition count
jmacato Jul 29, 2020
7ea79cc
Fix test
jmacato Jul 29, 2020
6eaea94
nits
jmacato Jul 29, 2020
047dea3
Merge branch 'master' into styleable-grid-rowcoldefs
jmacato Jul 30, 2020
50f27f7
Merge branch 'master' into styleable-grid-rowcoldefs
jmacato Aug 6, 2020
5753ff5
add unit test
jmacato Aug 6, 2020
9d14e0b
ugly fix
jmacato Aug 7, 2020
4af4000
revert
jmacato Aug 7, 2020
c144f5f
add more test
jmacato Aug 7, 2020
9bc1ee0
almost passed the tests
jmacato Aug 7, 2020
69d7e88
make stuff work finally gof
jmacato Aug 8, 2020
a346964
make the damn Grid work for once
jmacato Aug 14, 2020
cfd6b1f
Merge branch 'master' into styleable-grid-rowcoldefs
jmacato Aug 14, 2020
5a017af
fix stuff
jmacato Aug 14, 2020
940a691
add checks
jmacato Aug 14, 2020
b262926
remove commented out code
jmacato Aug 14, 2020
949349b
cleanup and move fields up
jmacato Aug 14, 2020
0a89e32
test for ci
jmacato Aug 14, 2020
703e7ef
temporarily remove tests for ci
jmacato Aug 14, 2020
f7bdee3
remove flags
jmacato Aug 14, 2020
67b4805
Merge branch 'master' into styleable-grid-rowcoldefs
jmacato Nov 24, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 67 additions & 26 deletions src/Avalonia.Controls/Grid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,53 @@ public class Grid : Panel
{
static Grid()
{
ShowGridLinesProperty.Changed.AddClassHandler<Grid>(OnShowGridLinesPropertyChanged);
ShowGridLinesProperty.Changed.AddClassHandler((Action<Grid, AvaloniaPropertyChangedEventArgs>)OnShowGridLinesPropertyChanged);

IsSharedSizeScopeProperty.Changed.AddClassHandler<Control>(DefinitionBase.OnIsSharedSizeScopePropertyChanged);
ColumnProperty.Changed.AddClassHandler<Control>(OnCellAttachedPropertyChanged);
ColumnSpanProperty.Changed.AddClassHandler<Control>(OnCellAttachedPropertyChanged);
RowProperty.Changed.AddClassHandler<Control>(OnCellAttachedPropertyChanged);
RowSpanProperty.Changed.AddClassHandler<Control>(OnCellAttachedPropertyChanged);
IsSharedSizeScopeProperty.Changed.AddClassHandler((Action<Control, AvaloniaPropertyChangedEventArgs>)DefinitionBase.OnIsSharedSizeScopePropertyChanged);
ColumnProperty.Changed.AddClassHandler((Action<Control, AvaloniaPropertyChangedEventArgs>)OnCellAttachedPropertyChanged);
ColumnSpanProperty.Changed.AddClassHandler((Action<Control, AvaloniaPropertyChangedEventArgs>)OnCellAttachedPropertyChanged);
RowProperty.Changed.AddClassHandler((Action<Control, AvaloniaPropertyChangedEventArgs>)OnCellAttachedPropertyChanged);
RowSpanProperty.Changed.AddClassHandler((Action<Control, AvaloniaPropertyChangedEventArgs>)OnCellAttachedPropertyChanged);

AffectsParentMeasure<Grid>(ColumnProperty, ColumnSpanProperty, RowProperty, RowSpanProperty);
AffectsParentMeasure<Grid>(ColumnProperty, ColumnSpanProperty, RowProperty, RowSpanProperty, ColumnDefinitionsProperty, RowDefinitionsProperty);
AffectsMeasure<Grid>(ColumnDefinitionsProperty, RowDefinitionsProperty);

RowDefinitionsProperty.Changed.AddClassHandler<Grid>(RowDefinitionsPropertyChanged);
ColumnDefinitionsProperty.Changed.AddClassHandler<Grid>(ColumnDefinitionsPropertyChanged);
}

private static void ColumnDefinitionsPropertyChanged(Grid arg1, AvaloniaPropertyChangedEventArgs arg2)
{
var val = arg2.NewValue as ColumnDefinitions;
ColumnDefinitionsPropertyChangedCore(arg1, val);
}

private static void ColumnDefinitionsPropertyChangedCore(Grid arg1, ColumnDefinitions arg2)
{
if (arg1._data is null)
arg1._data = new ExtendedData();

arg1._data!.ColumnDefinitions = arg2;
arg1._data!.ColumnDefinitions.IsDirty = true;
arg1._data!.ColumnDefinitions.Parent = arg1;
}

private static void RowDefinitionsPropertyChanged(Grid arg1, AvaloniaPropertyChangedEventArgs arg2)
{
var val = arg2.NewValue as RowDefinitions;
RowDefinitionsPropertyChangedCore(arg1, val);
}

private static void RowDefinitionsPropertyChangedCore(Grid arg1, RowDefinitions arg2)
{
if (arg1._data is null)
arg1._data = new ExtendedData();

arg1._data!.RowDefinitions = arg2;
jmacato marked this conversation as resolved.
Show resolved Hide resolved
arg1._data!.RowDefinitions.IsDirty = true;
arg1._data!.RowDefinitions.Parent = arg1;
}
///

/// <summary>
/// Default constructor.
Expand Down Expand Up @@ -160,45 +197,49 @@ public bool ShowGridLines
set { SetValue(ShowGridLinesProperty, value); }
}

/// <summary>
/// Returns a ColumnDefinitions of column definitions.
/// </summary>
public static readonly StyledProperty<ColumnDefinitions> ColumnDefinitionsProperty =
AvaloniaProperty.Register<Grid, ColumnDefinitions>(nameof(ColumnDefinitions));

public ColumnDefinitions ColumnDefinitions
{
get
{
if (_data == null) { _data = new ExtendedData(); }
if (_data.ColumnDefinitions == null) { _data.ColumnDefinitions = new ColumnDefinitions() { Parent = this }; }
if (_data.ColumnDefinitions == null)
{
_data.ColumnDefinitions = new ColumnDefinitions() { Parent = this };
SetValue(ColumnDefinitionsProperty, _data.ColumnDefinitions);
}

return (_data.ColumnDefinitions);
return GetValue(ColumnDefinitionsProperty);
}
set
{
if (_data == null) { _data = new ExtendedData(); }
_data.ColumnDefinitions = value;
_data.ColumnDefinitions.Parent = this;
InvalidateMeasure();
ColumnDefinitionsPropertyChangedCore(this, value);
SetValue(ColumnDefinitionsProperty, _data.ColumnDefinitions);
}
}

/// <summary>
/// Returns a RowDefinitions of row definitions.
/// </summary>
public static readonly StyledProperty<RowDefinitions> RowDefinitionsProperty =
AvaloniaProperty.Register<Grid, RowDefinitions>(nameof(RowDefinitions));

public RowDefinitions RowDefinitions
{
get
{
if (_data == null) { _data = new ExtendedData(); }
if (_data.RowDefinitions == null) { _data.RowDefinitions = new RowDefinitions() { Parent = this }; }
if (_data.RowDefinitions == null)
{
_data.RowDefinitions = new RowDefinitions() { Parent = this };
SetValue(RowDefinitionsProperty, _data.RowDefinitions);
}

return (_data.RowDefinitions);
return GetValue(RowDefinitionsProperty);
}
set
{
if (_data == null) { _data = new ExtendedData(); }
_data.RowDefinitions = value;
_data.RowDefinitions.Parent = this;
InvalidateMeasure();
RowDefinitionsPropertyChangedCore(this, value);
SetValue(RowDefinitionsProperty, _data.RowDefinitions);
}
}

Expand Down Expand Up @@ -2314,7 +2355,7 @@ private void SetValid()
}
}
}

/// <summary>
/// Synchronized ShowGridLines property with the state of the grid's visual collection
/// by adding / removing GridLinesRenderer visual.
Expand Down