Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Cirrious.FluentLayout/AdvancedFluentLayoutExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ public static FluentLayout AtRightOf(this UIView view, UIView parentView, nfloat
public static FluentLayout AtBottomOf(this UIView view, UIView parentView, nfloat? margin = null) =>
view.Bottom().EqualTo().BottomOf(parentView).Minus(margin.GetValueOrDefault(DefaultMargin));

public static FluentLayout AtLeadingOf(this UIView view, UIView parentView, nfloat? margin = null) =>
view.Leading().EqualTo().LeadingOf(parentView).Plus(margin.GetValueOrDefault(DefaultMargin));

public static FluentLayout AtTrailingOf(this UIView view, UIView parentView, nfloat? margin = null) =>
view.Trailing().EqualTo().TrailingOf(parentView).Minus(margin.GetValueOrDefault(DefaultMargin));

public static FluentLayout Below(this UIView view, UIView previous, nfloat? margin = null) =>
view.Top().EqualTo().BottomOf(previous).Plus(margin.GetValueOrDefault(DefaultMargin));

Expand All @@ -50,6 +56,10 @@ public static FluentLayout Above(this UIView view, UIView previous, nfloat? marg

public static FluentLayout WithSameBottom(this UIView view, UIView previous) => view.Bottom().EqualTo().BottomOf(previous);

public static FluentLayout WithSameLeading(this UIView view, UIView previous) => view.Leading().EqualTo().LeadingOf(previous);

public static FluentLayout WithSameTrailing(this UIView view, UIView previous) => view.Trailing().EqualTo().TrailingOf(previous);

public static FluentLayout WithRelativeWidth(this UIView view, UIView previous, nfloat? scale = null) =>
view.Width().EqualTo().WidthOf(previous).WithMultiplier(scale.GetValueOrDefault(DefaultScale));

Expand All @@ -64,6 +74,12 @@ public static FluentLayout ToRightOf(this UIView view, UIView previous, nfloat?
public static FluentLayout ToLeftOf(this UIView view, UIView previous, nfloat? margin = null) =>
view.Right().EqualTo().LeftOf(previous).Minus(margin.GetValueOrDefault(DefaultMargin));

public static FluentLayout ToTrailingOf(this UIView view, UIView previous, nfloat? margin = null) =>
view.Leading().EqualTo().TrailingOf(previous).Plus(margin.GetValueOrDefault(DefaultMargin));

public static FluentLayout ToLeadingOf(this UIView view, UIView previous, nfloat? margin = null) =>
view.Trailing().EqualTo().LeadingOf(previous).Minus(margin.GetValueOrDefault(DefaultMargin));

public static FluentLayout ToLeftMargin(this UIView view, UIView previous) =>
view.Leading().EqualTo().LeadingMarginOf(previous);

Expand Down
1 change: 1 addition & 0 deletions QuickLayout.Core/QuickLayout.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<Compile Include="ViewModels\UpdateConstraintsViewModel.cs" />
<Compile Include="ViewModels\AdvancedVerticalStackViewModel.cs" />
<Compile Include="ViewModels\DirectionFormViewModel.cs" />
<Compile Include="ViewModels\RightToLeftViewModel.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
2 changes: 2 additions & 0 deletions QuickLayout.Core/ViewModels/FirstViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ public class FirstViewModel
public void GoFullSize() => ShowViewModel<FullSizeViewModel>();

public void GoDirectionForm() => ShowViewModel<DirectionFormViewModel>();

public void GoRightToLeft() => ShowViewModel<RightToLeftViewModel>();
}
}
7 changes: 7 additions & 0 deletions QuickLayout.Core/ViewModels/RightToLeftViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace QuickLayout.Core.ViewModels
{
public class RightToLeftViewModel
: BaseDetailsViewModel
{
}
}
2 changes: 2 additions & 0 deletions QuickLayout.Touch/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@
<string>1</string>
<key>NSMainNibFile</key>
<string></string>
<key>CFBundleName</key>
<string>QuickLayout</string>
</dict>
</plist>
1 change: 1 addition & 0 deletions QuickLayout.Touch/QuickLayout.Touch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
<Compile Include="Views\DirectionFormView.cs" />
<None Include="packages.config" />
<Compile Include="Bootstrap\MethodBindingPluginBootstrap.cs" />
<Compile Include="Views\RightToLeftView.cs" />
</ItemGroup>
<ItemGroup>
<BundleResource Include="Resources\Default.png" />
Expand Down
9 changes: 7 additions & 2 deletions QuickLayout.Touch/Views/FirstView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
private UIButton _viewForm, _viewFormGrid, _viewDetails, _viewSearch, _viewTip, _viewUpdateConstaints, _viewAdvancedVerticalStack, _fullSize, _directionFormView, _rightToLeft;

public override void ViewDidLoad()
{
Expand Down Expand Up @@ -56,7 +56,11 @@ public override void ViewDidLoad()

_directionFormView = new UIButton(UIButtonType.RoundedRect);
_directionFormView.SetTitle("Directions", UIControlState.Normal);
Add(_directionFormView);
Add(_directionFormView);

_rightToLeft = new UIButton(UIButtonType.RoundedRect);
_rightToLeft.SetTitle("Right-To-Left Support", UIControlState.Normal);
Add(_rightToLeft);

View.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();

Expand All @@ -70,6 +74,7 @@ public override void ViewDidLoad()
set.Bind(_viewAdvancedVerticalStack).To("GoAdvancedVerticalStack");
set.Bind(_fullSize).To("GoFullSize");
set.Bind(_directionFormView).To("GoDirectionForm");
set.Bind(_rightToLeft).To("GoRightToLeft");
set.Apply();

var constraints = View.VerticalStackPanelConstraints(
Expand Down
152 changes: 152 additions & 0 deletions QuickLayout.Touch/Views/RightToLeftView.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
using Cirrious.FluentLayouts.Touch;
using MvvmCross.Binding.BindingContext;
using MvvmCross.iOS.Views;
using Foundation;
using ObjCRuntime;
using UIKit;

using QuickLayout.Core.ViewModels;
using System.Runtime.InteropServices;
using System;

namespace QuickLayout.Touch.Views
{
[Register("RightToLeftView")]
public class RightToLeftView : MvxViewController
{
public RightToLeftView()
{
SetRTL(false);
}

public override void ViewDidLoad()
{
View.BackgroundColor = UIColor.White;
base.ViewDidLoad();

// ios7 layout
if (RespondsToSelector(new Selector("edgesForExtendedLayout")))
EdgesForExtendedLayout = UIRectEdge.None;

var fNameLabel = new UILabel {Text = "First"};
Add(fNameLabel);

var sNameLabel = new UILabel {Text = "Last"};
Add(sNameLabel);

var numberLabel = new UILabel {Text = "#"};
Add(numberLabel);

var streetLabel = new UILabel {Text = "Street"};
Add(streetLabel);

var townLabel = new UILabel {Text = "Town"};
Add(townLabel);

var zipLabel = new UILabel {Text = "Zip"};
Add(zipLabel);

var fNameField = new UITextField() { BackgroundColor = UIColor.LightGray, BorderStyle = UITextBorderStyle.RoundedRect };
Add(fNameField);

var sNameField = new UITextField() { BackgroundColor = UIColor.LightGray, BorderStyle = UITextBorderStyle.RoundedRect };
Add(sNameField);

var numberField = new UITextField() { BackgroundColor = UIColor.LightGray, BorderStyle = UITextBorderStyle.RoundedRect };
Add(numberField);

var streetField = new UITextField() { BackgroundColor = UIColor.LightGray, BorderStyle = UITextBorderStyle.RoundedRect };
Add(streetField);

var townField = new UITextField() { BackgroundColor = UIColor.LightGray, BorderStyle = UITextBorderStyle.RoundedRect };
Add(townField);

var zipField = new UITextField() { BackgroundColor = UIColor.LightGray, BorderStyle = UITextBorderStyle.RoundedRect };
Add(zipField);

var debug = new UILabel() { BackgroundColor = UIColor.White, Lines = 0 };
Add(debug);

var set = this.CreateBindingSet<RightToLeftView, RightToLeftViewModel>();
set.Bind(fNameField).To(vm => vm.FirstName);
set.Bind(sNameField).To(vm => vm.LastName);
set.Bind(numberField).To(vm => vm.Number);
set.Bind(streetField).To(vm => vm.Street);
set.Bind(townField).To(vm => vm.Town);
set.Bind(zipField).To(vm => vm.Zip);
set.Bind(debug).To("FirstName + ' ' + LastName + ', ' + Number + ' ' + Street + ' ' + Town + ' ' + Zip");
set.Apply();

View.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();

var hMargin = 10;
var vMargin = 10;


View.AddConstraints(

fNameLabel.AtTopOf(View, vMargin),
fNameLabel.AtLeadingOf(View, hMargin),
fNameLabel.ToLeadingOf(sNameLabel, hMargin),

sNameLabel.WithSameTop(fNameLabel),
sNameLabel.AtTrailingOf(View, hMargin),
sNameLabel.WithSameWidth(fNameLabel),

fNameField.WithSameWidth(fNameLabel),
fNameField.WithSameLeading(fNameLabel),
fNameField.Below(fNameLabel, vMargin),

sNameField.WithSameLeading(sNameLabel),
sNameField.WithSameWidth(sNameLabel),
sNameField.WithSameTop(fNameField),

numberLabel.WithSameLeading(fNameLabel),
numberLabel.ToLeadingOf(streetLabel, hMargin),
numberLabel.Below(fNameField, vMargin),
numberLabel.WithRelativeWidth(streetLabel, 0.3f),

streetLabel.WithSameTop(numberLabel),
streetLabel.AtTrailingOf(View, hMargin),

numberField.WithSameLeading(numberLabel),
numberField.WithSameWidth(numberLabel),
numberField.Below(numberLabel, vMargin),

streetField.WithSameLeading(streetLabel),
streetField.WithSameWidth(streetLabel),
streetField.WithSameTop(numberField),

townLabel.WithSameLeading(fNameLabel),
townLabel.WithSameTrailing(streetLabel),
townLabel.Below(numberField, vMargin),

townField.WithSameLeading(townLabel),
townField.WithSameWidth(townLabel),
townField.Below(townLabel, vMargin),

zipLabel.WithSameLeading(fNameLabel),
zipLabel.WithSameWidth(townLabel),
zipLabel.Below(townField, vMargin),

zipField.WithSameLeading(townLabel),
zipField.WithSameWidth(zipLabel),
zipField.Below(zipLabel, vMargin),

debug.WithSameLeading(townLabel),
debug.WithSameWidth(zipLabel),
debug.AtBottomOf(View, vMargin)

);
}

[DllImport(Constants.ObjectiveCLibrary, EntryPoint = "objc_msgSend")]
internal extern static IntPtr IntPtr_objc_msgSend(IntPtr receiver, IntPtr selector, UISemanticContentAttribute arg1);

private static void SetRTL(bool isRTL)
{
Selector selector = new Selector("setSemanticContentAttribute:");
IntPtr_objc_msgSend(UIView.Appearance.Handle, selector.Handle, isRTL ? UISemanticContentAttribute.ForceRightToLeft : UISemanticContentAttribute.ForceLeftToRight);
}
}
}