Skip to content

Commit

Permalink
Revert "fix: Avoid nested UI classes in runtime tests"
Browse files Browse the repository at this point in the history
This reverts commit e40221a.
  • Loading branch information
Youssef1313 committed Nov 7, 2023
1 parent b5b4478 commit a5362ab
Show file tree
Hide file tree
Showing 8 changed files with 262 additions and 263 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1353,145 +1353,145 @@ private static VirtualizingLayout GetMonitoringLayout(Size desiredSize, List<Rec
ArrangeLayoutFunc = (finalSize, context) => finalSize
};
}
}

internal partial class TestScrollingSurface : ContentControl, IRepeaterScrollingSurface
{
private bool _isHorizontallyScrollable;
private bool _isVerticallyScrollable;
private ConfigurationChangedEventHandler _configurationChangedTokenTable;

public bool InMeasure { get; set; }
public bool InArrange { get; set; }
public bool InPostArrange { get; private set; }
private partial class TestScrollingSurface : ContentControl, IRepeaterScrollingSurface
{
private bool _isHorizontallyScrollable;
private bool _isVerticallyScrollable;
private ConfigurationChangedEventHandler _configurationChangedTokenTable;

public Action ConfigurationChangedAddFunc { get; set; }
public Action ConfigurationChangedRemoveFunc { get; set; }
public bool InMeasure { get; set; }
public bool InArrange { get; set; }
public bool InPostArrange { get; private set; }

public Action<UIElement> RegisterAnchorCandidateFunc { get; set; }
public Action<UIElement> UnregisterAnchorCandidateFunc { get; set; }
public Func<UIElement, Rect> GetRelativeViewportFunc { get; set; }
public Action ConfigurationChangedAddFunc { get; set; }
public Action ConfigurationChangedRemoveFunc { get; set; }

public UIElement AnchorElement { get; set; }
public Action<UIElement> RegisterAnchorCandidateFunc { get; set; }
public Action<UIElement> UnregisterAnchorCandidateFunc { get; set; }
public Func<UIElement, Rect> GetRelativeViewportFunc { get; set; }

public bool IsHorizontallyScrollable
{
get { return _isHorizontallyScrollable; }
set
{
_isHorizontallyScrollable = value;
RaiseConfigurationChanged();
InvalidateMeasure();
}
}
public UIElement AnchorElement { get; set; }

public bool IsVerticallyScrollable
{
get { return _isVerticallyScrollable; }
set
public bool IsHorizontallyScrollable
{
_isVerticallyScrollable = value;
RaiseConfigurationChanged();
InvalidateMeasure();
get { return _isHorizontallyScrollable; }
set
{
_isHorizontallyScrollable = value;
RaiseConfigurationChanged();
InvalidateMeasure();
}
}
}

public event ConfigurationChangedEventHandler ConfigurationChanged
{
add
public bool IsVerticallyScrollable
{
if (ConfigurationChangedAddFunc != null)
get { return _isVerticallyScrollable; }
set
{
ConfigurationChangedAddFunc();
_isVerticallyScrollable = value;
RaiseConfigurationChanged();
InvalidateMeasure();
}

_configurationChangedTokenTable += value;
}
remove

public event ConfigurationChangedEventHandler ConfigurationChanged
{
if (ConfigurationChangedRemoveFunc != null)
add
{
ConfigurationChangedRemoveFunc();
if (ConfigurationChangedAddFunc != null)
{
ConfigurationChangedAddFunc();
}

_configurationChangedTokenTable += value;
}
remove
{
if (ConfigurationChangedRemoveFunc != null)
{
ConfigurationChangedRemoveFunc();
}

_configurationChangedTokenTable -= value;
_configurationChangedTokenTable -= value;
}
}
}
public event PostArrangeEventHandler PostArrange;
public event PostArrangeEventHandler PostArrange;
#pragma warning disable CS0067
// Warning CS0067: The event 'ViewportTests.TestScrollingSurface.ViewportChanged' is never used.
public event ViewportChangedEventHandler ViewportChanged;
// Warning CS0067: The event 'ViewportTests.TestScrollingSurface.ViewportChanged' is never used.
public event ViewportChangedEventHandler ViewportChanged;
#pragma warning restore CS0067

public void RegisterAnchorCandidate(UIElement element)
{
RegisterAnchorCandidateFunc(element);
}
public void RegisterAnchorCandidate(UIElement element)
{
RegisterAnchorCandidateFunc(element);
}

public void UnregisterAnchorCandidate(UIElement element)
{
UnregisterAnchorCandidateFunc(element);
}
public void UnregisterAnchorCandidate(UIElement element)
{
UnregisterAnchorCandidateFunc(element);
}

public Rect GetRelativeViewport(UIElement child)
{
return GetRelativeViewportFunc(child);
}
public Rect GetRelativeViewport(UIElement child)
{
return GetRelativeViewportFunc(child);
}

protected override Size MeasureOverride(Size availableSize)
{
InMeasure = true;
var result = base.MeasureOverride(availableSize);
InMeasure = false;
return result;
}
protected override Size MeasureOverride(Size availableSize)
{
InMeasure = true;
var result = base.MeasureOverride(availableSize);
InMeasure = false;
return result;
}

protected override Size ArrangeOverride(Size finalSize)
{
InArrange = true;
protected override Size ArrangeOverride(Size finalSize)
{
InArrange = true;

var result = base.ArrangeOverride(finalSize);
var result = base.ArrangeOverride(finalSize);

InArrange = false;
InPostArrange = true;
InArrange = false;
InPostArrange = true;

if (PostArrange != null)
{
PostArrange(this);
}
if (PostArrange != null)
{
PostArrange(this);
}

InPostArrange = false;
InPostArrange = false;

return result;
}
return result;
}

private void RaiseConfigurationChanged()
{
_configurationChangedTokenTable?.Invoke(this);
private void RaiseConfigurationChanged()
{
_configurationChangedTokenTable?.Invoke(this);
}
}
}

internal partial class TestStackLayout : StackLayout
{
public UIElement SuggestedAnchor { get; private set; }

protected internal override Size MeasureOverride(VirtualizingLayoutContext context, Size availableSize)
private partial class TestStackLayout : StackLayout
{
var anchorIndex = context.RecommendedAnchorIndex;
SuggestedAnchor = anchorIndex < 0 ? null : context.GetOrCreateElementAt(anchorIndex);
return base.MeasureOverride(context, availableSize);
}
}
public UIElement SuggestedAnchor { get; private set; }

internal partial class TestGridLayout : UniformGridLayout
{
public UIElement SuggestedAnchor { get; private set; }
protected internal override Size MeasureOverride(VirtualizingLayoutContext context, Size availableSize)
{
var anchorIndex = context.RecommendedAnchorIndex;
SuggestedAnchor = anchorIndex < 0 ? null : context.GetOrCreateElementAt(anchorIndex);
return base.MeasureOverride(context, availableSize);
}
}

protected internal override Size MeasureOverride(VirtualizingLayoutContext context, Size availableSize)
private partial class TestGridLayout : UniformGridLayout
{
var anchorIndex = context.RecommendedAnchorIndex;
SuggestedAnchor = anchorIndex < 0 ? null : context.GetOrCreateElementAt(anchorIndex);
return base.MeasureOverride(context, availableSize);
public UIElement SuggestedAnchor { get; private set; }

protected internal override Size MeasureOverride(VirtualizingLayoutContext context, Size availableSize)
{
var anchorIndex = context.RecommendedAnchorIndex;
SuggestedAnchor = anchorIndex < 0 ? null : context.GetOrCreateElementAt(anchorIndex);
return base.MeasureOverride(context, availableSize);
}
}
}
}
94 changes: 47 additions & 47 deletions src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,53 @@ namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml
[TestClass]
public partial class Given_Control
{
private partial class CustomControl : Control
{
public Size AvailableSizePassedToMeasureOverride { get; private set; }
protected override Size MeasureOverride(Size availableSize)
{
AvailableSizePassedToMeasureOverride = availableSize;
return new(2000, 2000);
}
}

#if HAS_UNO
private partial class OnApplyTemplateCounterControl : Control
{
public OnApplyTemplateCounterControl() : base()
{
Loading += (_, _) => OnControlLoading();
}

private ControlTemplate _template;
public int OnApplyTemplateCalls { get; private set; }

protected override void OnApplyTemplate()
{
// OnApplyTemplate should be called when the Template changes, so we only care
// about (unnecessary) calls that happen when the Template doesn't change
if (_template != Template)
{
_template = Template;
OnApplyTemplateCalls = 0;
}

OnApplyTemplateCalls++;
}

private void OnControlLoading() => Style = new Style
{
Setters =
{
new Setter(TemplateProperty, new ControlTemplate(() => new Grid())
{
TargetType = typeof(OnApplyTemplateCounterControl),
})
}
};
}
#endif

[TestMethod]
[RunsOnUIThread]
public async Task When_Limited_By_Available_Size_Before_Margin_Application()
Expand Down Expand Up @@ -238,51 +285,4 @@ public async Task When_Padding_Set_In_SizeChanged()
Assert.AreEqual(0, ((UIElement)VisualTreeHelper.GetChild(SUT, 0)).ActualOffset.Y);
}
}

#if HAS_UNO
public partial class OnApplyTemplateCounterControl : Control
{
public OnApplyTemplateCounterControl() : base()
{
Loading += (_, _) => OnControlLoading();
}

private ControlTemplate _template;
public int OnApplyTemplateCalls { get; private set; }

protected override void OnApplyTemplate()
{
// OnApplyTemplate should be called when the Template changes, so we only care
// about (unnecessary) calls that happen when the Template doesn't change
if (_template != Template)
{
_template = Template;
OnApplyTemplateCalls = 0;
}

OnApplyTemplateCalls++;
}

private void OnControlLoading() => Style = new Style
{
Setters =
{
new Setter(TemplateProperty, new ControlTemplate(() => new Grid())
{
TargetType = typeof(OnApplyTemplateCounterControl),
})
}
};
}
#endif

public partial class CustomControl : Control
{
public Size AvailableSizePassedToMeasureOverride { get; private set; }
protected override Size MeasureOverride(Size availableSize)
{
AvailableSizePassedToMeasureOverride = availableSize;
return new(2000, 2000);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,16 @@ public Task When_Grid_Measure_And_Invalidate() =>
});
#endif

public partial class MyGrid : Grid
{
public Size AvailableSizeUsedForMeasure { get; private set; }
protected override Size MeasureOverride(Size availableSize)
{
AvailableSizeUsedForMeasure = availableSize;
return base.MeasureOverride(availableSize);
}
}

[TestMethod]
[RunsOnUIThread]
#if __MACOS__
Expand Down Expand Up @@ -765,16 +775,6 @@ public async Task When_Add_Element_While_Parent_Loaded_Then_Load_Raised()
#endif
}

public partial class MyGrid : Grid
{
public Size AvailableSizeUsedForMeasure { get; private set; }
protected override Size MeasureOverride(Size availableSize)
{
AvailableSizeUsedForMeasure = availableSize;
return base.MeasureOverride(availableSize);
}
}

public partial class MyControl01 : FrameworkElement
{
public List<Size> MeasureOverrides { get; } = new List<Size>();
Expand Down
Loading

0 comments on commit a5362ab

Please sign in to comment.