Skip to content

Commit

Permalink
chore: add Stretch
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelMendesRosa committed Aug 18, 2023
1 parent 420b14a commit 2620370
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public ShadowContainerSamplePage()
var shadowsItemsControl = SamplePageLayout.GetSampleChild<ItemsControl>(Design.Agnostic, "ShadowsItemsControl");
shadowsItemsControl.ItemsSource = _shadows;
shadowContainer.UpdateLayout();
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,10 @@ private void OnShadowSizeChanged()
if (_currentContent is FrameworkElement fm)
{
marginElement = fm.Margin;
_shadowHost?.InvalidateMeasure();
_shadowHost?.InvalidateArrange();
this.GetDispatcherCompat().Schedule(() => UpdateCanvasSize(fm.ActualWidth, fm.ActualHeight, Shadows, marginElement));
}
UpdateCanvasSize(_currentContent.ActualWidth, _currentContent.ActualHeight, Shadows, marginElement);
InvalidateFromShadowPropertyChange();
}
}

Expand Down
55 changes: 18 additions & 37 deletions src/Uno.Toolkit.Skia.WinUI/Controls/Shadows/ShadowContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ protected override void OnApplyTemplate()
#else
var skiaCanvas = new SKXamlCanvas();
skiaCanvas.PaintSurface += OnSurfacePainted;
//skiaCanvas.Loaded += OnSurfacePainted;
#endif

#if __IOS__ || __MACCATALYST__
Expand All @@ -101,18 +100,6 @@ protected override void OnApplyTemplate()
base.OnApplyTemplate();
}

//protected override Size MeasureOverride(Size availableSize)
//{
// var desiredSize = base.MeasureOverride(availableSize);

// if (Content is FrameworkElement c)
// {
// UpdateCanvasSize(desiredSize.Width, desiredSize.Height, Shadows, c.Margin);
// }

// return desiredSize;
//}

/// <inheritdoc/>
protected override void OnContentChanged(object oldContent, object newContent)
{
Expand All @@ -122,15 +109,13 @@ protected override void OnContentChanged(object oldContent, object newContent)
{
_panel?.Children.Remove(oldElement);
oldElement.SizeChanged -= OnContentSizeChanged;
//oldElement.LayoutUpdated -= _currentContent_LayoutUpdated;
}

if (newContent is FrameworkElement newElement)
{
_currentContent = newElement;
_currentContent.SizeChanged += OnContentSizeChanged;
_currentOriginalMargin = newElement.Margin;
//_currentContent.LayoutUpdated += _currentContent_LayoutUpdated;

if (TryGetCornerRadius(newElement, out var cornerRadius))
{
Expand All @@ -154,7 +139,6 @@ protected override void OnContentChanged(object oldContent, object newContent)
);
}
}


_cornerRadius = cornerRadius;
}
Expand Down Expand Up @@ -207,12 +191,12 @@ private void OnContentSizeChanged(object sender, SizeChangedEventArgs args)
if (args.OriginalSource is FrameworkElement fm)
{
marginElement = fm.Margin;
UpdateCanvasSize(args.NewSize.Width, args.NewSize.Height, Shadows, marginElement);

_shadowHost?.InvalidateMeasure();
_shadowHost?.InvalidateArrange();
this.GetDispatcherCompat().Schedule(() => UpdateCanvasSize(fm.ActualWidth, fm.ActualHeight, Shadows, marginElement));
}
UpdateCanvasSize(args.NewSize.Width, args.NewSize.Height, Shadows, marginElement);
//#if __ANDROID__ || __IOS__
// _shadowHost?.Invalidate();
// InvalidateFromShadowPropertyChange();
//#endif
}
}

Expand Down Expand Up @@ -240,32 +224,29 @@ private void UpdateCanvasSize(double childWidth, double childHeight, ShadowColle
double newHostSpreadHeight = maxBlurRadius + absoluteMaxOffsetY + maxSpread;

_currentContent.Margin = new Thickness(_currentContent.HorizontalAlignment == HorizontalAlignment.Left ? 0 : newHostSpread,
newHostSpreadHeight,
_currentContent.HorizontalAlignment == HorizontalAlignment.Right ? 0 : newHostSpread,
newHostSpreadHeight);
newHostSpreadHeight,
_currentContent.HorizontalAlignment == HorizontalAlignment.Right ? 0 : newHostSpread,
newHostSpreadHeight);

_shadowHost.HorizontalAlignment = _currentContent.HorizontalAlignment == HorizontalAlignment.Stretch ? HorizontalAlignment.Center : _currentContent.HorizontalAlignment;
_shadowHost.VerticalAlignment = _currentContent.VerticalAlignment == VerticalAlignment.Stretch ? VerticalAlignment.Center : _currentContent.VerticalAlignment;
_shadowHost.Height = childHeight + newHostSpreadHeight * 2 +
(_currentContent.VerticalAlignment == VerticalAlignment.Top ? childMargin.Top : 0) +
(_currentContent.VerticalAlignment == VerticalAlignment.Bottom ? childMargin.Bottom : 0); ;
(_currentContent.VerticalAlignment == VerticalAlignment.Top ? childMargin.Top : 0) +
(_currentContent.VerticalAlignment == VerticalAlignment.Bottom ? childMargin.Bottom : 0); ;
_shadowHost.Width = childWidth + newHostSpread * 2 +
(_currentContent.HorizontalAlignment == HorizontalAlignment.Left ? childMargin.Left : 0) +
(_currentContent.HorizontalAlignment == HorizontalAlignment.Right ? childMargin.Right : 0);
(_currentContent.HorizontalAlignment == HorizontalAlignment.Left ? childMargin.Left : 0) +
(_currentContent.HorizontalAlignment == HorizontalAlignment.Right ? childMargin.Right : 0);
_shadowHost.Margin = new Thickness(-1 * (newHostSpread),
-1 * (newHostSpreadHeight),
-1 * (newHostSpread),
-1 * (newHostSpreadHeight));

_panel.BorderBrush = new SolidColorBrush(Colors.Red);
_panel.BorderThickness = new Thickness(1, 1, 1, 1);
-1 * (newHostSpreadHeight),
-1 * (newHostSpread),
-1 * (newHostSpreadHeight));

if (_currentOriginalMargin is Thickness { } margin)
{
_panel.Padding = new Thickness(margin.Left,
margin.Top,
margin.Right,
margin.Bottom);
margin.Top,
margin.Right,
margin.Bottom);
}
}
}

0 comments on commit 2620370

Please sign in to comment.