Skip to content

Commit

Permalink
add tab gesture for control in example to show bounds of control
Browse files Browse the repository at this point in the history
  • Loading branch information
xtuzy committed Apr 6, 2024
1 parent 1f298ce commit 9c97527
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
15 changes: 11 additions & 4 deletions SharpConstraintLayout.Maui.Example/Pages/MainPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ void GroupTest(ConstraintLayout page)
set.ApplyTo(layout);

}
SecondButton.Clicked -= Button_Clicked_ShowPopup;
SecondButton.Clicked += (sender, e) =>
{
if (group.ConstrainVisibility == ConstraintSet.Gone)
Expand Down Expand Up @@ -72,6 +73,7 @@ void FlowPerformanceTest(ConstraintLayout rootpage)
page.AddElement(SecondButton);

FirstButton.Text = "Add Button";
FirstButton.Clicked -= Button_Clicked_ShowPopup;
FirstButton.Clicked += (sender, e) =>
{
var newbutton = new Button();
Expand Down Expand Up @@ -102,6 +104,7 @@ void FlowPerformanceTest(ConstraintLayout rootpage)
}

SecondButton.Text = "Add Char";
SecondButton.Clicked -= Button_Clicked_ShowPopup;
SecondButton.Clicked += (sender, e) =>
{
buttonList[0].Text = buttonList[0].Text + "A";//not use entry to add char, because entry will measure twice
Expand Down Expand Up @@ -412,6 +415,7 @@ private void VisibilityTest(ConstraintLayout page)

int index = 2;

FirstButton.Clicked -= Button_Clicked_ShowPopup;
FirstButton.Clicked += (sender, e) =>
{
if (index == 1)
Expand Down Expand Up @@ -501,6 +505,9 @@ private void GuidelineTest(ConstraintLayout page)
{
Background = new SolidColorBrush(Colors.Black)
};
var tab = new TapGestureRecognizer();
tab.Tapped += Button_Clicked_ShowPopup;
layout.GestureRecognizers.Add(tab);

var guide = new Guideline();

Expand Down Expand Up @@ -530,20 +537,20 @@ private void BaseAlignTest(ConstraintLayout page)
(Button FirstButton, Button SecondButton, ContentView ThirdCanvas, Label FouthTextBlock, Entry FifthTextBox, Editor SixthRichTextBlock) = CreateControls();

FirstButton.Text = "CenterTo Width=100";
SecondButton.Text = "RightToRight & TopToBottom";
SecondButton.Text = "RightToRight(-100) & TopToBottom";
FouthTextBlock.Text = "CenterXTo & BottomToTop(100)";
FifthTextBox.Text = "CenterXTo & TopToBottom";
SixthRichTextBlock.Text = "CenterXTo & TopToBottom";
var layout = page;

layout.AddElement(FirstButton, SecondButton, ThirdCanvas, FouthTextBlock, FifthTextBox, SixthRichTextBlock);
layout.AddElement(ThirdCanvas, FirstButton, SecondButton, FouthTextBlock, FifthTextBox, SixthRichTextBlock);

var layoutSet = new FluentConstraintSet();
layoutSet.Clone(layout);
layoutSet
.Select(FirstButton).CenterTo()
.Select(FirstButton).CenterTo().Width(100)
.Select(ThirdCanvas).Width(SizeBehavier.MatchConstraint).Height(SizeBehavier.MatchConstraint)
.Select(SecondButton).RightToRight(FirstButton).TopToBottom(FirstButton)
.Select(SecondButton).RightToRight(FirstButton, -100).TopToBottom(FirstButton)
.Select(ThirdCanvas).LeftToRight(FirstButton).RightToRight().EdgesYTo()
.Select(FouthTextBlock).CenterXTo().BottomToTop(FirstButton, 100).Width(SizeBehavier.MatchConstraint)
.Select(FifthTextBox).CenterXTo().TopToBottom(SecondButton).Width(SizeBehavier.MatchConstraint)
Expand Down
16 changes: 15 additions & 1 deletion SharpConstraintLayout.Maui.Example/Pages/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,22 @@ protected override Size ArrangeOverride(Rect bounds)
//WidthRequest = 100
//Background = new SolidColorBrush(Colors.Red)
};
FirstButton.Clicked += Button_Clicked_ShowPopup;

var SecondButton = new Button()
{
Text = "SecondBotton",
//Background = new SolidColorBrush(Colors.Black)
};
SecondButton.Clicked += Button_Clicked_ShowPopup;

var ThirdCanvas = new ContentView()
{
Background = new SolidColorBrush(Colors.LightGreen)
};
var tab = new TapGestureRecognizer();
tab.Tapped += Button_Clicked_ShowPopup;
ThirdCanvas.GestureRecognizers.Add(tab);

var FouthTextBlock = new Label()
{
Expand All @@ -136,6 +141,7 @@ protected override Size ArrangeOverride(Rect bounds)
VerticalTextAlignment = TextAlignment.Center,
BackgroundColor = Colors.Black
};
FouthTextBlock.GestureRecognizers.Add(tab);

var FifthTextBox = new Entry()
{
Expand All @@ -146,17 +152,25 @@ protected override Size ArrangeOverride(Rect bounds)
{
//(FifthTextBox.Parent as ConstraintLayout)?.RequestReLayout();
};
FifthTextBox.Completed += Button_Clicked_ShowPopup;

//https://stackoverflow.com/questions/35710355/uwpc-adding-text-to-richtextblock
var SixthRichTextBlock = new Editor()
{
Text = "SixthEditor",
AutoSize = EditorAutoSizeOption.TextChanges
};
SixthRichTextBlock.Completed += Button_Clicked_ShowPopup;

return (FirstButton, SecondButton, ThirdCanvas, FouthTextBlock, FifthTextBox, SixthRichTextBlock);
}

private async void Button_Clicked_ShowPopup(object sender, EventArgs e)
{
var view = (sender as VisualElement);
await DisplayAlert(sender.GetType().Name+" Information", $"[{view.Bounds.Left.ToString("0.0")}, {view.Bounds.Top.ToString("0.0")}, {view.Bounds.Right.ToString("0.0")}, {view.Bounds.Bottom.ToString("0.0")}][{view.Bounds.Width.ToString("0.0")}, {view.Bounds.Height.ToString("0.0")}]", "OK");
}

ConstraintLayout CreateConstraintLayout(ILogger log = null)
{
var content = new ConstraintLayout(log)
Expand All @@ -169,7 +183,7 @@ ConstraintLayout CreateConstraintLayout(ILogger log = null)
Background = new SolidColorBrush(Colors.HotPink),
};
gridLayout.RemoveAt(gridLayout.Count - 1);
gridLayout.Add(content);
gridLayout.Add(content);
return content;
}

Expand Down

0 comments on commit 9c97527

Please sign in to comment.