Replace tabs with spaces to fit coding standard
This commit is contained in:
@@ -7,8 +7,8 @@ using CoreGraphics;
|
|||||||
|
|
||||||
namespace Facebook.Yoga.Mac
|
namespace Facebook.Yoga.Mac
|
||||||
{
|
{
|
||||||
// Xamarin.Mac binding projects allow you to include native libraries inside C# DLLs for easy consumption
|
// Xamarin.Mac binding projects allow you to include native libraries inside C# DLLs for easy consumption
|
||||||
// later. However, the binding project build files currently assume you are binding some objective-c API
|
// later. However, the binding project build files currently assume you are binding some objective-c API
|
||||||
// and that you need an ApiDefinition.cs for that. yoga is all C APIs, so just include this "blank" file so
|
// and that you need an ApiDefinition.cs for that. yoga is all C APIs, so just include this "blank" file so
|
||||||
// the dylib gets packaged
|
// the dylib gets packaged
|
||||||
}
|
}
|
||||||
|
@@ -1,11 +1,11 @@
|
|||||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<CompileDependsOn>CopyInNativeLib;$(CompileDependsOn)</CompileDependsOn>
|
<CompileDependsOn>CopyInNativeLib;$(CompileDependsOn)</CompileDependsOn>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<!-- The # and , in this path does not play nice with the binding project logic, so make a copy -->
|
<!-- The # and , in this path does not play nice with the binding project logic, so make a copy -->
|
||||||
<Target Name="CopyInNativeLib" Inputs="..\..\buck-out\gen\csharp\yoganet#default,shared\libyoga.dylib" Outputs="$(ProjectDir)libyoga.dylib">
|
<Target Name="CopyInNativeLib" Inputs="..\..\buck-out\gen\csharp\yoganet#default,shared\libyoga.dylib" Outputs="$(ProjectDir)libyoga.dylib">
|
||||||
<Copy SourceFiles="..\..\buck-out\gen\csharp\yoganet#default,shared\libyoga.dylib" DestinationFiles="$(ProjectDir)/libyoga.dylib" />
|
<Copy SourceFiles="..\..\buck-out\gen\csharp\yoganet#default,shared\libyoga.dylib" DestinationFiles="$(ProjectDir)/libyoga.dylib" />
|
||||||
</Target>
|
</Target>
|
||||||
</Project>
|
</Project>
|
||||||
|
@@ -3,20 +3,20 @@ using Foundation;
|
|||||||
|
|
||||||
namespace Facebook.Yoga.Mac.Test
|
namespace Facebook.Yoga.Mac.Test
|
||||||
{
|
{
|
||||||
[Register("AppDelegate")]
|
[Register("AppDelegate")]
|
||||||
public class AppDelegate : NSApplicationDelegate
|
public class AppDelegate : NSApplicationDelegate
|
||||||
{
|
{
|
||||||
public AppDelegate()
|
public AppDelegate()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void DidFinishLaunching(NSNotification notification)
|
public override void DidFinishLaunching(NSNotification notification)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void WillTerminate(NSNotification notification)
|
public override void WillTerminate(NSNotification notification)
|
||||||
{
|
{
|
||||||
// Insert code here to tear down your application
|
// Insert code here to tear down your application
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
namespace Facebook.Yoga.Mac.Test
|
namespace Facebook.Yoga.Mac.Test
|
||||||
{
|
{
|
||||||
static class MainClass
|
static class MainClass
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
NSApplication.Init();
|
NSApplication.Init();
|
||||||
NSApplication.Main(args);
|
NSApplication.Main(args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -7,123 +7,123 @@ using CoreGraphics;
|
|||||||
|
|
||||||
namespace Facebook.Yoga.Mac.Test
|
namespace Facebook.Yoga.Mac.Test
|
||||||
{
|
{
|
||||||
public static class NSViewYogaExtensions
|
public static class NSViewYogaExtensions
|
||||||
{
|
{
|
||||||
public static void ApplyYogaLayout (this NSView view, YogaNode n, bool root = true)
|
public static void ApplyYogaLayout (this NSView view, YogaNode n, bool root = true)
|
||||||
{
|
{
|
||||||
#if DEBUG_LAYOUT
|
#if DEBUG_LAYOUT
|
||||||
Console.WriteLine ($"ApplyYogaLayout {view.ToolTip}, {n.LayoutX}, {n.LayoutY}, {n.LayoutWidth}, {n.LayoutHeight}");
|
Console.WriteLine ($"ApplyYogaLayout {view.ToolTip}, {n.LayoutX}, {n.LayoutY}, {n.LayoutWidth}, {n.LayoutHeight}");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// A bit of gross special casing
|
// A bit of gross special casing
|
||||||
// This really should mostly go away if/when the UIView+Yoga.m magic gets ported to AppKit
|
// This really should mostly go away if/when the UIView+Yoga.m magic gets ported to AppKit
|
||||||
if (root)
|
if (root)
|
||||||
view.Frame = new CGRect (n.LayoutX, n.LayoutY, n.LayoutWidth, n.LayoutHeight);
|
view.Frame = new CGRect (n.LayoutX, n.LayoutY, n.LayoutWidth, n.LayoutHeight);
|
||||||
#if DEBUG_LAYOUT
|
#if DEBUG_LAYOUT
|
||||||
Console.WriteLine ($"Setting {view.ToolTip} frame to {view.Frame}");
|
Console.WriteLine ($"Setting {view.ToolTip} frame to {view.Frame}");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// This assumes your YogaNode and NSView children were inserted in same order
|
// This assumes your YogaNode and NSView children were inserted in same order
|
||||||
for (int i = 0; i < n.Count; ++i) {
|
for (int i = 0; i < n.Count; ++i) {
|
||||||
YogaNode childNode = n[i];
|
YogaNode childNode = n[i];
|
||||||
// Cocoa coord space is from bottom left not top left
|
// Cocoa coord space is from bottom left not top left
|
||||||
view.Subviews[i].Frame = new CGRect (childNode.LayoutX, n.LayoutHeight - childNode.LayoutY - childNode.LayoutHeight, childNode.LayoutWidth, childNode.LayoutHeight);
|
view.Subviews[i].Frame = new CGRect (childNode.LayoutX, n.LayoutHeight - childNode.LayoutY - childNode.LayoutHeight, childNode.LayoutWidth, childNode.LayoutHeight);
|
||||||
#if DEBUG_LAYOUT
|
#if DEBUG_LAYOUT
|
||||||
Console.WriteLine ($"Setting {view.Subviews[i].ToolTip} frame to {view.Subviews[i].Frame}");
|
Console.WriteLine ($"Setting {view.Subviews[i].ToolTip} frame to {view.Subviews[i].Frame}");
|
||||||
#endif
|
#endif
|
||||||
if (childNode.Count > 0){
|
if (childNode.Count > 0){
|
||||||
#if DEBUG_LAYOUT
|
#if DEBUG_LAYOUT
|
||||||
Console.WriteLine ($"Calling ApplyYogaLayout recursively on {view.Subviews[i].ToolTip}");
|
Console.WriteLine ($"Calling ApplyYogaLayout recursively on {view.Subviews[i].ToolTip}");
|
||||||
#endif
|
#endif
|
||||||
ApplyYogaLayout (view.Subviews[i], childNode, false);
|
ApplyYogaLayout (view.Subviews[i], childNode, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public partial class ViewController : NSViewController
|
public partial class ViewController : NSViewController
|
||||||
{
|
{
|
||||||
public ViewController(IntPtr handle) : base(handle)
|
public ViewController(IntPtr handle) : base(handle)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ViewDidLoad()
|
public override void ViewDidLoad()
|
||||||
{
|
{
|
||||||
base.ViewDidLoad ();
|
base.ViewDidLoad ();
|
||||||
|
|
||||||
NSImage image = NSImage.ImageNamed (NSImageName.TrashFull);
|
NSImage image = NSImage.ImageNamed (NSImageName.TrashFull);
|
||||||
|
|
||||||
NSView root = CreateViewHierarchy (image);
|
NSView root = CreateViewHierarchy (image);
|
||||||
var rootNode = CalculateLayout (View.Frame, image.Size);
|
var rootNode = CalculateLayout (View.Frame, image.Size);
|
||||||
|
|
||||||
root.ApplyYogaLayout (rootNode);
|
root.ApplyYogaLayout (rootNode);
|
||||||
|
|
||||||
View.AddSubview (root);
|
View.AddSubview (root);
|
||||||
}
|
}
|
||||||
|
|
||||||
static NSView CreateViewHierarchy (NSImage image)
|
static NSView CreateViewHierarchy (NSImage image)
|
||||||
{
|
{
|
||||||
var root = new NSView () {
|
var root = new NSView () {
|
||||||
WantsLayer = true,
|
WantsLayer = true,
|
||||||
ToolTip = "Root"
|
ToolTip = "Root"
|
||||||
};
|
};
|
||||||
root.Layer.BackgroundColor = NSColor.Red.CGColor;
|
root.Layer.BackgroundColor = NSColor.Red.CGColor;
|
||||||
|
|
||||||
NSView child1 = new NSView () {
|
NSView child1 = new NSView () {
|
||||||
WantsLayer = true,
|
WantsLayer = true,
|
||||||
ToolTip = "Child 1"
|
ToolTip = "Child 1"
|
||||||
};
|
};
|
||||||
child1.Layer.BackgroundColor = NSColor.Blue.CGColor;
|
child1.Layer.BackgroundColor = NSColor.Blue.CGColor;
|
||||||
|
|
||||||
NSView child2 = new NSView () {
|
NSView child2 = new NSView () {
|
||||||
WantsLayer = true,
|
WantsLayer = true,
|
||||||
ToolTip = "Child 2"
|
ToolTip = "Child 2"
|
||||||
};
|
};
|
||||||
child2.Layer.BackgroundColor = NSColor.Green.CGColor;
|
child2.Layer.BackgroundColor = NSColor.Green.CGColor;
|
||||||
|
|
||||||
NSView child3 = new NSView () {
|
NSView child3 = new NSView () {
|
||||||
WantsLayer = true,
|
WantsLayer = true,
|
||||||
ToolTip = "Child 3"
|
ToolTip = "Child 3"
|
||||||
};
|
};
|
||||||
child3.Layer.BackgroundColor = NSColor.Yellow.CGColor;
|
child3.Layer.BackgroundColor = NSColor.Yellow.CGColor;
|
||||||
|
|
||||||
root.AddSubview (child1);
|
root.AddSubview (child1);
|
||||||
root.AddSubview (child2);
|
root.AddSubview (child2);
|
||||||
child2.AddSubview (child3);
|
child2.AddSubview (child3);
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
static YogaNode CalculateLayout (CGRect rootFrame, CGSize imageSize)
|
static YogaNode CalculateLayout (CGRect rootFrame, CGSize imageSize)
|
||||||
{
|
{
|
||||||
var rootNode = new YogaNode () {
|
var rootNode = new YogaNode () {
|
||||||
Width = (float)rootFrame.Width,
|
Width = (float)rootFrame.Width,
|
||||||
Height = (float)rootFrame.Height,
|
Height = (float)rootFrame.Height,
|
||||||
AlignItems = YogaAlign.Center,
|
AlignItems = YogaAlign.Center,
|
||||||
JustifyContent = YogaJustify.Center
|
JustifyContent = YogaJustify.Center
|
||||||
};
|
};
|
||||||
|
|
||||||
var child1Node = new YogaNode () {
|
var child1Node = new YogaNode () {
|
||||||
Width = 100,
|
Width = 100,
|
||||||
Height = 100
|
Height = 100
|
||||||
};
|
};
|
||||||
|
|
||||||
var child2Node = new YogaNode () {
|
var child2Node = new YogaNode () {
|
||||||
Width = 200,
|
Width = 200,
|
||||||
Height = 100
|
Height = 100
|
||||||
};
|
};
|
||||||
|
|
||||||
var child3Node = new YogaNode () {
|
var child3Node = new YogaNode () {
|
||||||
Width = 100,
|
Width = 100,
|
||||||
Height = 100
|
Height = 100
|
||||||
};
|
};
|
||||||
|
|
||||||
rootNode.Insert (0, child1Node);
|
rootNode.Insert (0, child1Node);
|
||||||
rootNode.Insert (1, child2Node);
|
rootNode.Insert (1, child2Node);
|
||||||
child2Node.Insert (0, child3Node);
|
child2Node.Insert (0, child3Node);
|
||||||
rootNode.CalculateLayout ();
|
rootNode.CalculateLayout ();
|
||||||
|
|
||||||
return rootNode;
|
return rootNode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user