Skip to content

Commit

Permalink
[Maui.Example] add fit grid test
Browse files Browse the repository at this point in the history
  • Loading branch information
xtuzy committed Apr 22, 2023
1 parent f2d46a3 commit a816e75
Showing 1 changed file with 49 additions and 11 deletions.
60 changes: 49 additions & 11 deletions SharpConstraintLayout.Maui.Example/Pages/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using SharpConstraintLayout.Maui.Example.Pages;
using SharpConstraintLayout.Maui.Example.Tool;
using SharpConstraintLayout.Maui.Example.ViewModels;
using SharpConstraintLayout.Maui.Native.Example.Tool;
using SharpConstraintLayout.Maui.Widget;
using static SharpConstraintLayout.Maui.Widget.FluentConstraintSet;

Expand All @@ -26,7 +27,27 @@ public MainPage()
System.Diagnostics.Debug.WriteLine("MainPage: Width=" + (sender as Page).Bounds.Width);
App.WindowWidth = (int)(sender as Page).Bounds.Width;
};


FitGridTest();

#if WINDOWS || __ANDROID__ || __IOS__
if (fr == null)
{
fr = new BlogFrameRate.FrameRateCalculator();
fr.FrameRateUpdated += (value) =>
{
this.Dispatcher.Dispatch(() => fpsLabel.Text = value.Frames.ToString());
};
fr.Start();
}
#endif
}

/// <summary>
/// ConstraintLayout use int in internal, so need double to int, here we test it if will get error.
/// </summary>
void FitGridTest()
{
var myHorizontalStackLayout = new MyHorizontalStackLayout();
var myConstraintLayout = new ConstraintLayout(new Log());
compareWithGridLayout.Add(myHorizontalStackLayout);
Expand All @@ -36,23 +57,40 @@ public MainPage()
myHorizontalStackLayout.Add(new Entry() { Text = "In MyHorizontalStackLayout", VerticalOptions = LayoutOptions.Center });
var entry = new Entry() { Text = "In ConstraintLayout" };
myConstraintLayout.Add(entry);
using(var set = new FluentConstraintSet())
using (var set = new FluentConstraintSet())
{
set.Clone(myConstraintLayout);
set.Select(entry).CenterYTo();
set.ApplyTo(myConstraintLayout);
}
#if WINDOWS || __ANDROID__ || __IOS__
if (fr == null)

var testMessage = "HorizontalStackLayout should have same height with ConstraintLayout";
var addRowTask = new Task(() =>
{
fr = new BlogFrameRate.FrameRateCalculator();
fr.FrameRateUpdated += (value) =>
UIThread.Invoke(() =>
{
this.Dispatcher.Dispatch(() => fpsLabel.Text = value.Frames.ToString());
};
fr.Start();
}
#endif
compareWithGridLayout.AddRowDefinition(new RowDefinition() { Height = GridLength.Star });
}, myConstraintLayout);
Task.Run(async () =>
{
await Task.Delay(3000);//wait UI change or show
UIThread.Invoke(() =>
{
SimpleTest.AreEqual(myHorizontalStackLayout.GetSize().Height, myConstraintLayout.GetSize().Height, nameof(FitGridTest));
}, myConstraintLayout);
});
});
Task.Run(async () =>
{
await Task.Delay(3000);//wait UI change or show
UIThread.Invoke(() =>
{
SimpleTest.AreEqual(myHorizontalStackLayout.GetSize().Height, myConstraintLayout.GetSize().Height, nameof(FitGridTest));
}, myConstraintLayout);
}).ContinueWith((t) =>
{
addRowTask.Start();
});
}

/// <summary>
Expand Down

0 comments on commit a816e75

Please sign in to comment.