From a91024bba3c9c463556e642a1235387fec47b040 Mon Sep 17 00:00:00 2001 From: R3x <10961076+Tyron18@users.noreply.github.com> Date: Thu, 29 Nov 2018 10:13:52 +0200 Subject: [PATCH 1/3] Add methods for aligning view edges to the center of other views. --- .../AdvancedFluentLayoutExtensions.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Cirrious.FluentLayout/AdvancedFluentLayoutExtensions.cs b/Cirrious.FluentLayout/AdvancedFluentLayoutExtensions.cs index 1022d80..3b3969c 100644 --- a/Cirrious.FluentLayout/AdvancedFluentLayoutExtensions.cs +++ b/Cirrious.FluentLayout/AdvancedFluentLayoutExtensions.cs @@ -110,7 +110,19 @@ public static FluentLayout ToTopMargin(this UIView view, UIView previous) => view.Top().EqualTo().TopMarginOf(previous); public static FluentLayout ToBottomMargin(this UIView view, UIView previous) => - view.Bottom().EqualTo().BottomMarginOf(previous); + view.Bottom().EqualTo().BottomMarginOf(previous); + + public static FluentLayout ToLeftOfCenterOf(this UIView view, UIView previous, nfloat? margin = null) => + view.Right().EqualTo().CenterXOf(previous).Minus(margin.GetValueOrDefault(0)); + + public static FluentLayout ToRightOfCenterOf(this UIView view, UIView previous, nfloat? margin = null) => + view.Left().EqualTo().CenterXOf(previous).Minus(margin.GetValueOrDefault(0)); + + public static FluentLayout AboveCenterOf(this UIView view, UIView previous, nfloat? margin = null) => + view.Bottom().EqualTo().CenterYOf(previous).Minus(margin.GetValueOrDefault(0)); + + public static FluentLayout BelowCenterOf(this UIView view, UIView previous, nfloat? margin = null) => + view.Top().EqualTo().CenterYOf(previous).Minus(margin.GetValueOrDefault(0)); public static IEnumerable FullWidthOf(this UIView view, UIView parent, nfloat? margin = null) { From b082bbfd1b53acaef407a8a1cabd0d77fbef4fe5 Mon Sep 17 00:00:00 2001 From: R3x <10961076+Tyron18@users.noreply.github.com> Date: Thu, 29 Nov 2018 10:23:17 +0200 Subject: [PATCH 2/3] Fix margin for ToRightOfCenterOf and BelowCenterOf --- Cirrious.FluentLayout/AdvancedFluentLayoutExtensions.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cirrious.FluentLayout/AdvancedFluentLayoutExtensions.cs b/Cirrious.FluentLayout/AdvancedFluentLayoutExtensions.cs index 3b3969c..5981529 100644 --- a/Cirrious.FluentLayout/AdvancedFluentLayoutExtensions.cs +++ b/Cirrious.FluentLayout/AdvancedFluentLayoutExtensions.cs @@ -116,13 +116,13 @@ public static FluentLayout ToLeftOfCenterOf(this UIView view, UIView previous, n view.Right().EqualTo().CenterXOf(previous).Minus(margin.GetValueOrDefault(0)); public static FluentLayout ToRightOfCenterOf(this UIView view, UIView previous, nfloat? margin = null) => - view.Left().EqualTo().CenterXOf(previous).Minus(margin.GetValueOrDefault(0)); + view.Left().EqualTo().CenterXOf(previous).Plus(margin.GetValueOrDefault(0)); public static FluentLayout AboveCenterOf(this UIView view, UIView previous, nfloat? margin = null) => view.Bottom().EqualTo().CenterYOf(previous).Minus(margin.GetValueOrDefault(0)); public static FluentLayout BelowCenterOf(this UIView view, UIView previous, nfloat? margin = null) => - view.Top().EqualTo().CenterYOf(previous).Minus(margin.GetValueOrDefault(0)); + view.Top().EqualTo().CenterYOf(previous).Plus(margin.GetValueOrDefault(0)); public static IEnumerable FullWidthOf(this UIView view, UIView parent, nfloat? margin = null) { From 503783e3c26c482f5641cddea01d78d30cd5c8c3 Mon Sep 17 00:00:00 2001 From: Tyron De Andrade Date: Fri, 30 Nov 2018 09:17:04 +0200 Subject: [PATCH 3/3] example for center constraints --- QuickLayout.Core/QuickLayout.Core.csproj | 1 + QuickLayout.Core/ViewModels/FirstViewModel.cs | 2 + .../ToCenterConstraintsViewModel.cs | 8 +++ QuickLayout.Touch/QuickLayout.Touch.csproj | 21 +++++-- QuickLayout.Touch/Views/FirstView.cs | 7 ++- .../Views/ToCenterConstraintsView.cs | 55 +++++++++++++++++++ 6 files changed, 88 insertions(+), 6 deletions(-) create mode 100644 QuickLayout.Core/ViewModels/ToCenterConstraintsViewModel.cs create mode 100644 QuickLayout.Touch/Views/ToCenterConstraintsView.cs diff --git a/QuickLayout.Core/QuickLayout.Core.csproj b/QuickLayout.Core/QuickLayout.Core.csproj index 3de6c21..8ef635e 100644 --- a/QuickLayout.Core/QuickLayout.Core.csproj +++ b/QuickLayout.Core/QuickLayout.Core.csproj @@ -45,6 +45,7 @@ + diff --git a/QuickLayout.Core/ViewModels/FirstViewModel.cs b/QuickLayout.Core/ViewModels/FirstViewModel.cs index 59d38af..47998aa 100644 --- a/QuickLayout.Core/ViewModels/FirstViewModel.cs +++ b/QuickLayout.Core/ViewModels/FirstViewModel.cs @@ -26,5 +26,7 @@ public class FirstViewModel public void GoRightToLeft() => ShowViewModel(); public void GoViewWithSafeArea() => ShowViewModel(); + + public void GoCenterConstraints() => ShowViewModel(); } } \ No newline at end of file diff --git a/QuickLayout.Core/ViewModels/ToCenterConstraintsViewModel.cs b/QuickLayout.Core/ViewModels/ToCenterConstraintsViewModel.cs new file mode 100644 index 0000000..79b5df9 --- /dev/null +++ b/QuickLayout.Core/ViewModels/ToCenterConstraintsViewModel.cs @@ -0,0 +1,8 @@ +using MvvmCross.Core.ViewModels; + +namespace QuickLayout.Core.ViewModels +{ + public class ToCenterConstraintsViewModel : MvxViewModel + { + } +} diff --git a/QuickLayout.Touch/QuickLayout.Touch.csproj b/QuickLayout.Touch/QuickLayout.Touch.csproj index 9dd442f..fda8ceb 100644 --- a/QuickLayout.Touch/QuickLayout.Touch.csproj +++ b/QuickLayout.Touch/QuickLayout.Touch.csproj @@ -90,6 +90,7 @@ + @@ -159,11 +160,21 @@ - - - - - + + false + + + false + + + false + + + false + + + false + \ No newline at end of file diff --git a/QuickLayout.Touch/Views/FirstView.cs b/QuickLayout.Touch/Views/FirstView.cs index c8ff226..fe7175e 100644 --- a/QuickLayout.Touch/Views/FirstView.cs +++ b/QuickLayout.Touch/Views/FirstView.cs @@ -11,7 +11,7 @@ namespace QuickLayout.Touch.Views [Register("FirstView")] public class FirstView : MvxViewController { - private UIButton _viewForm, _viewFormGrid, _viewDetails, _viewSearch, _viewTip, _viewUpdateConstaints, _viewAdvancedVerticalStack, _fullSize, _directionFormView, _rightToLeft, _viewSafeArea; + private UIButton _viewForm, _viewFormGrid, _viewDetails, _viewSearch, _viewTip, _viewUpdateConstaints, _viewAdvancedVerticalStack, _fullSize, _directionFormView, _rightToLeft, _viewSafeArea, _viewCenterConstraints; public override void ViewDidLoad() { @@ -66,6 +66,10 @@ public override void ViewDidLoad() _viewSafeArea.SetTitle("View with Safe Area", UIControlState.Normal); Add(_viewSafeArea); + _viewCenterConstraints = new UIButton(UIButtonType.RoundedRect); + _viewCenterConstraints.SetTitle("View Contraining to centers", UIControlState.Normal); + Add(_viewCenterConstraints); + View.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints(); var set = this.CreateBindingSet(); @@ -80,6 +84,7 @@ public override void ViewDidLoad() set.Bind(_directionFormView).To("GoDirectionForm"); set.Bind(_rightToLeft).To("GoRightToLeft"); set.Bind(_viewSafeArea).To("GoViewWithSafeArea"); + set.Bind(_viewCenterConstraints).To("GoCenterConstraints"); set.Apply(); var constraints = View.VerticalStackPanelConstraints( diff --git a/QuickLayout.Touch/Views/ToCenterConstraintsView.cs b/QuickLayout.Touch/Views/ToCenterConstraintsView.cs new file mode 100644 index 0000000..c98bd14 --- /dev/null +++ b/QuickLayout.Touch/Views/ToCenterConstraintsView.cs @@ -0,0 +1,55 @@ +using Cirrious.FluentLayouts.Touch; +using Foundation; +using MvvmCross.iOS.Views; +using QuickLayout.Core.ViewModels; +using UIKit; + +namespace QuickLayout.Touch.Views +{ + [Register("ToCenterConstraintsView")] + public class ToCenterConstraintsView : MvxViewController + { + public override void ViewDidLoad() + { + + UIView firstContainer = new UIView + { + TranslatesAutoresizingMaskIntoConstraints = false, + BackgroundColor = UIColor.Blue + }, + + secondContainer = new UIView + { + TranslatesAutoresizingMaskIntoConstraints = false, + BackgroundColor = UIColor.Red + }, + + thirdContainer = new UIView + { + TranslatesAutoresizingMaskIntoConstraints = false, + BackgroundColor = UIColor.Yellow, + Alpha = .5f + }; + + View.AddSubviews(firstContainer, secondContainer, thirdContainer); + + View.AddConstraints(new FluentLayout[] + { + firstContainer.AtTopOf(View), + firstContainer.AtLeftOf(View), + firstContainer.AboveCenterOf(View, 10f), + firstContainer.ToLeftOfCenterOf(View, 10f), + + secondContainer.AtBottomOf(View), + secondContainer.AtRightOf(View), + secondContainer.ToRightOfCenterOf(View, 10f), + secondContainer.BelowCenterOf(View, 10f), + + thirdContainer.ToRightOfCenterOf(firstContainer), + thirdContainer.ToLeftOfCenterOf(secondContainer), + thirdContainer.AboveCenterOf(secondContainer), + thirdContainer.BelowCenterOf(firstContainer) + }); + } + } +} \ No newline at end of file