Portable Tool for an Ideal Windows Setup
C# activatorbloatware-removalcsharpdebloatdebloaterdisable-servicesmonitoring-systemportableprivacy-toolsregistry-tweakssystem-tuningsystem-utilitytelemetrytweakerwindows-10windows-11windows-debloatwindows-defenderwindows-optimizationwindows-tweaks
fix handle Infinity width dynamically in flowpanel & ref
Greedeksda375943b408
diff --git a/.Source/GTweak/Assets/UserControls/FlowPanel.cs b/.Source/GTweak/Assets/UserControls/FlowPanel.csindex 4d5dada2..d203a24d 100644--- a/.Source/GTweak/Assets/UserControls/FlowPanel.cs+++ b/.Source/GTweak/Assets/UserControls/FlowPanel.cs@@ -15,12 +15,7 @@ namespace GTweak.Assets.UserControlsinternal double Height;}- public enum FlowOrientation- {- Unset = 0,- Vertical = 1,- Horizontal = 2- }+ public enum FlowOrientation { Unset, Vertical, Horizontal }public static readonly DependencyProperty HorizontalSpacingProperty = DependencyProperty.Register(nameof(HorizontalSpacing), typeof(double), typeof(FlowPanel),new FrameworkPropertyMetadata(20.0, FrameworkPropertyMetadataOptions.AffectsArrange | FrameworkPropertyMetadataOptions.AffectsMeasure));@@ -44,7 +39,7 @@ namespace GTweak.Assets.UserControlsnew FrameworkPropertyMetadata(320.0, FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsArrange));public static readonly DependencyProperty ResponsiveModeProperty = DependencyProperty.Register(nameof(ResponsiveMode), typeof(bool), typeof(FlowPanel),- new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsArrange | FrameworkPropertyMetadataOptions.AffectsMeasure));+ new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsArrange | FrameworkPropertyMetadataOptions.AffectsMeasure));public double HorizontalSpacing{@@ -159,72 +154,59 @@ namespace GTweak.Assets.UserControls}}- private double GetResponsiveAlignmentOffset(double outerWidth, double contentWidth)- {- double extra = Math.Max(0, outerWidth - contentWidth);-- return ContentAlignment switch- {- HorizontalAlignment.Center => extra / 2.0,- HorizontalAlignment.Right => extra,- _ => 0- };- }-protected override Size MeasureOverride(Size availableSize){try{UpdateVisibleCache();- if (_visibleCache.Count == 0)+ int count = _visibleCache.Count;+ if (count == 0){return new Size(0, 0);}- double aw = double.IsInfinity(availableSize.Width) ? 1200 : availableSize.Width;- double ah = availableSize.Height;-Size constraint = EqualizeItemSize ? new Size(ItemWidth, double.PositiveInfinity) : new Size(availableSize.Width, double.PositiveInfinity);- for (int i = 0; i < _visibleCache.Count; i++)- {- _visibleCache[i]?.Measure(constraint);- }+ double totalItemWidth = 0;+ double totalItemHeight = 0;+ double maxItemHeight = 0;+ double maxItemWidth = 0;- if (ResponsiveMode)+ for (int i = 0; i < count; i++){- double totalItemWidth = 0;- double totalItemHeight = 0;- double maxItemHeight = 0;- double maxItemWidth = 0;- int count = _visibleCache.Count;+ UIElement child = _visibleCache[i];+ child?.Measure(constraint);- for (int i = 0; i < count; i++)- {- double cw = GetChildWidth(_visibleCache[i]);- double ch = GetChildHeight(_visibleCache[i]);+ double cw = GetChildWidth(child);+ double ch = GetChildHeight(child);- totalItemWidth += cw;- totalItemHeight += ch;+ totalItemWidth += cw;+ totalItemHeight += ch;- if (cw > maxItemWidth)- {- maxItemWidth = cw;- }+ if (cw > maxItemWidth)+ {+ maxItemWidth = cw;+ }- if (ch > maxItemHeight)- {- maxItemHeight = ch;- }+ if (ch > maxItemHeight)+ {+ maxItemHeight = ch;}+ }- double horizontalRequired = totalItemWidth + (count > 1 ? (count - 1) * HorizontalSpacing : 0);- double verticalRequired = totalItemHeight + (count > 1 ? (count - 1) * VerticalSpacing : 0);+ double horizontalRequired = totalItemWidth + (count > 1 ? (count - 1) * HorizontalSpacing : 0);+ double verticalRequired = totalItemHeight + (count > 1 ? (count - 1) * VerticalSpacing : 0);+ double aw = double.IsInfinity(availableSize.Width) ? horizontalRequired : availableSize.Width;+ double ah = availableSize.Height;++ if (ResponsiveMode)+ {if (horizontalRequired <= aw){- return new Size(aw, maxItemHeight);+ double returnWidth = double.IsInfinity(availableSize.Width) ? horizontalRequired : aw;+ return new Size(returnWidth, maxItemHeight);}return new Size(maxItemWidth, verticalRequired);@@ -236,11 +218,14 @@ namespace GTweak.Assets.UserControls_cachedLayout = null;}- _cachedMeasureWidth = aw;_cachedLayout = CreateOptimalColumns(aw, ah, _visibleCache);double neededHeight = CalculateLayoutHeight(_cachedLayout);- return new Size(aw, neededHeight);+ double neededWidth = double.IsInfinity(availableSize.Width) ? CalculateTotalWidth(_cachedLayout) : aw;++ _cachedMeasureWidth = neededWidth;++ return new Size(neededWidth, neededHeight);}catch (Exception ex){@@ -249,6 +234,18 @@ namespace GTweak.Assets.UserControls}}+ private double GetResponsiveAlignmentOffset(double outerWidth, double contentWidth)+ {+ double extra = Math.Max(0, outerWidth - contentWidth);++ return ContentAlignment switch+ {+ HorizontalAlignment.Center => extra / 2.0,+ HorizontalAlignment.Right => extra,+ _ => 0+ };+ }+private void ArrangeResponsive(Size finalSize){int count = _visibleCache.Count;@@ -529,6 +526,8 @@ namespace GTweak.Assets.UserControlsreturn CreateWrappedRows(availableWidth, visibleChildren);case FlowOrientation.Vertical:return CreateWrappedColumns(availableHeight, visibleChildren);+ default:+ break;}double basisWidth;diff --git a/.Source/GTweak/View/ToolsetView.xaml b/.Source/GTweak/View/ToolsetView.xamlindex 080e2ae1..9838b97b 100644--- a/.Source/GTweak/View/ToolsetView.xaml+++ b/.Source/GTweak/View/ToolsetView.xaml@@ -3,10 +3,11 @@xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"+ xmlns:uc="clr-namespace:GTweak.Assets.UserControls"xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"xmlns:local="clr-namespace:GTweak.View"mc:Ignorable="d" d:Width="1014" Style="{StaticResource LaunchPage}"><Grid>-+</Grid></UserControl>