From f7bdee389d254510cc8a318c33107d9e436676ea Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Fri, 14 Aug 2020 23:25:07 +0800 Subject: [PATCH] remove flags --- src/Avalonia.Controls/Grid.cs | 182 ++++------------------------------ 1 file changed, 21 insertions(+), 161 deletions(-) diff --git a/src/Avalonia.Controls/Grid.cs b/src/Avalonia.Controls/Grid.cs index 58b4c6465c..41c03adc9b 100644 --- a/src/Avalonia.Controls/Grid.cs +++ b/src/Avalonia.Controls/Grid.cs @@ -53,10 +53,9 @@ namespace Avalonia.Controls private static readonly IComparer s_minRatioComparer = new MinRatioComparer(); private static readonly IComparer s_maxRatioComparer = new MaxRatioComparer(); private static readonly IComparer s_starWeightComparer = new StarWeightComparer(); - - private Flags _flags; // Grid validity / property caches dirtiness flags + private GridLinesRenderer _gridLinesRenderer; // Keeps track of definition indices. - + private int[] _definitionIndices; private double[] _roundingErrors; // Stores unrounded values and rounding errors during layout rounding. @@ -228,9 +227,6 @@ namespace Avalonia.Controls try { - ListenToNotifications = true; - MeasureOverrideInProgress = true; - if (RowOrColumnDefChanged) { if (ColIsEmpty) @@ -536,7 +532,7 @@ namespace Avalonia.Controls } finally { - MeasureOverrideInProgress = false; + } return (gridDesiredSize); @@ -550,8 +546,6 @@ namespace Avalonia.Controls { try { - ArrangeOverrideInProgress = true; - if (IsTrivial) { var children = this.Children; @@ -608,7 +602,6 @@ namespace Avalonia.Controls finally { SetValid(); - ArrangeOverrideInProgress = false; } return (arrangeSize); } @@ -675,35 +668,6 @@ namespace Avalonia.Controls return (value); } - /// - /// Convenience accessor to MeasureOverrideInProgress bit flag. - /// - internal bool MeasureOverrideInProgress - { - get { return (CheckFlagsAnd(Flags.MeasureOverrideInProgress)); } - set { SetFlags(value, Flags.MeasureOverrideInProgress); } - } - - /// - /// Convenience accessor to ArrangeOverrideInProgress bit flag. - /// - internal bool ArrangeOverrideInProgress - { - get { return (CheckFlagsAnd(Flags.ArrangeOverrideInProgress)); } - set { SetFlags(value, Flags.ArrangeOverrideInProgress); } - } - - // internal bool RowOrColumnDefinitionsDirty - // { - // get - // { - // if (ColumnDefinitions is null || RowDefinitions is null) - // return true; - // if (ColumnDefinitions.IsDirty || RowDefinitions.IsDirty) - // return true; - // return false; - // } - // } /// /// Lays out cells according to rows and columns, and creates lookup grids. @@ -2301,53 +2265,20 @@ namespace Avalonia.Controls return (_gridLinesRenderer); } - /// - /// SetFlags is used to set or unset one or multiple - /// flags on the object. - /// - private void SetFlags(bool value, Flags flags) - { - _flags = value ? (_flags | flags) : (_flags & (~flags)); - } - - /// - /// CheckFlagsAnd returns true if all the flags in the - /// given bitmask are set on the object. - /// - private bool CheckFlagsAnd(Flags flags) - { - return ((_flags & flags) == flags); - } - - /// - /// CheckFlagsOr returns true if at least one flag in the - /// given bitmask is set. - /// - /// - /// If no bits are set in the given bitmask, the method returns - /// true. - /// - private bool CheckFlagsOr(Flags flags) - { - return (flags == 0 || (_flags & flags) != 0); - } - private static void OnCellAttachedPropertyChanged(AvaloniaObject d, AvaloniaPropertyChangedEventArgs e) { - Visual child = d as Visual; + var child = d as Visual; if (child != null) { - Grid grid = child.GetVisualParent(); - if (grid != null) - { - grid.Invalidate(); - } + var grid = child.GetVisualParent(); + if (grid != null & !grid.IsTrivial) + grid.InvalidateMeasure(); } } /// - /// Reflects the changes on the ColumnDefinition StyledProperty to the target grid. + /// Update internal flags when ColumnDefinition changes /// private static void ColumnDefinitionsPropertyChanged(Grid target, AvaloniaPropertyChangedEventArgs e) { @@ -2364,7 +2295,7 @@ namespace Avalonia.Controls } /// - /// Reflects the changes on the RowDefinition StyledProperty to the target grid. + /// Update internal flags when RowDefinitions changes. /// private static void RowDefinitionsPropertyChanged(Grid target, AvaloniaPropertyChangedEventArgs e) { @@ -2497,67 +2428,34 @@ namespace Avalonia.Controls } /// - /// Convenience accessor to ValidCellsStructure bit flag. + /// This field is true if the cells needs to be recalculated /// - private bool CellsStructureDirty - { - get { return (!CheckFlagsAnd(Flags.ValidCellsStructure)); } - set { SetFlags(!value, Flags.ValidCellsStructure); } - } + private bool CellsStructureDirty; /// - /// Convenience accessor to ListenToNotifications bit flag. + /// This field is true if calculating to content in U direction. /// - private bool ListenToNotifications - { - get { return (CheckFlagsAnd(Flags.ListenToNotifications)); } - set { SetFlags(value, Flags.ListenToNotifications); } - } + private bool SizeToContentU; /// - /// Convenience accessor to SizeToContentU bit flag. + /// This field is true if calculating to content in V direction. /// - private bool SizeToContentU - { - get { return (CheckFlagsAnd(Flags.SizeToContentU)); } - set { SetFlags(value, Flags.SizeToContentU); } - } + private bool SizeToContentV; /// - /// Convenience accessor to SizeToContentV bit flag. + /// This field is true if at least one cell belongs to a Star column. /// - private bool SizeToContentV - { - get { return (CheckFlagsAnd(Flags.SizeToContentV)); } - set { SetFlags(value, Flags.SizeToContentV); } - } + private bool HasStarCellsU; /// - /// Convenience accessor to HasStarCellsU bit flag. + // This field is true if at least one cell belongs to a Star row. /// - private bool HasStarCellsU - { - get { return (CheckFlagsAnd(Flags.HasStarCellsU)); } - set { SetFlags(value, Flags.HasStarCellsU); } - } + private bool HasStarCellsV; /// - /// Convenience accessor to HasStarCellsV bit flag. + // This field is true if at least one cell of group 3 belongs to an Auto row. /// - private bool HasStarCellsV - { - get { return (CheckFlagsAnd(Flags.HasStarCellsV)); } - set { SetFlags(value, Flags.HasStarCellsV); } - } - - /// - /// Convenience accessor to HasGroup3CellsInAutoRows bit flag. - /// - private bool HasGroup3CellsInAutoRows - { - get { return (CheckFlagsAnd(Flags.HasGroup3CellsInAutoRows)); } - set { SetFlags(value, Flags.HasGroup3CellsInAutoRows); } - } + private bool HasGroup3CellsInAutoRows; /// /// Returns *-weight, adjusted for scale computed during Phase 1 @@ -2577,44 +2475,6 @@ namespace Avalonia.Controls } } - - - - - /// - /// Grid validity / property caches dirtiness flags - /// - [System.Flags] - private enum Flags - { - // - // the foolowing flags let grid tracking dirtiness in more granular manner: - // * Valid???Structure flags indicate that elements were added or removed. - // * Valid???Layout flags indicate that layout time portion of the information - // stored on the objects should be updated. - // - ValidDefinitionsUStructure = 0x00000001, - ValidDefinitionsVStructure = 0x00000002, - ValidCellsStructure = 0x00000004, - - // - // boolean properties state - // - ShowGridLinesPropertyValue = 0x00000100, // show grid lines ? - - // - // boolean flags - // - ListenToNotifications = 0x00001000, // "0" when all notifications are ignored - SizeToContentU = 0x00002000, // "1" if calculating to content in U direction - SizeToContentV = 0x00004000, // "1" if calculating to content in V direction - HasStarCellsU = 0x00008000, // "1" if at least one cell belongs to a Star column - HasStarCellsV = 0x00010000, // "1" if at least one cell belongs to a Star row - HasGroup3CellsInAutoRows = 0x00020000, // "1" if at least one cell of group 3 belongs to an Auto row - MeasureOverrideInProgress = 0x00040000, // "1" while in the context of Grid.MeasureOverride - ArrangeOverrideInProgress = 0x00080000, // "1" while in the context of Grid.ArrangeOverride - } - /// /// Defines the property. ///