Skip to content
Closed
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
1 change: 1 addition & 0 deletions csharp/Facebook.Yoga/Facebook.Yoga.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Native.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaAlign.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaBaselineFunc.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaConfig.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaConstants.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaDimension.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaDirection.cs" />
Expand Down
13 changes: 13 additions & 0 deletions csharp/Facebook.Yoga/Native.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,19 @@ public static extern bool YGConfigIsExperimentalFeatureEnabled(
YGConfigHandle config,
YogaExperimentalFeature feature);

[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGConfigSetUseWebDefaults(
YGConfigHandle config,
bool useWebDefaults);

[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern bool YGConfigGetUseWebDefaults(YGConfigHandle config);

[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGConfigSetPointScaleFactor(
YGConfigHandle config,
float pixelsInPoint);

[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeInsertChild(
YGNodeHandle node,
Expand Down
67 changes: 67 additions & 0 deletions csharp/Facebook.Yoga/YogaConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

using System;

namespace Facebook.Yoga
{
public class YogaConfig
{
private Native.YGConfigHandle _ygConfig;

public YogaConfig()
{
_ygConfig = Native.YGConfigNew();
if (_ygConfig.IsInvalid)
{
throw new InvalidOperationException("Failed to allocate native memory");
}
}

internal Native.YGConfigHandle Handle
{
get {
return _ygConfig;
}
}

public void SetExperimentalFeatureEnabled(
YogaExperimentalFeature feature,
bool enabled)
{
Native.YGConfigSetExperimentalFeatureEnabled(_ygConfig, feature, enabled);
}

public bool IsExperimentalFeatureEnabled(YogaExperimentalFeature feature)
{
return Native.YGConfigIsExperimentalFeatureEnabled(_ygConfig, feature);
}

public bool UseWebDefaults
{
get
{
return Native.YGConfigGetUseWebDefaults(_ygConfig);
}

set
{
Native.YGConfigSetUseWebDefaults(_ygConfig, value);
}
}

public float PointScaleFactor
{
set
{
Native.YGConfigSetPointScaleFactor(_ygConfig, value);
}
}
}
}
47 changes: 11 additions & 36 deletions csharp/Facebook.Yoga/YogaNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,43 +24,10 @@

namespace Facebook.Yoga
{
public class YogaConfig
{

private Native.YGConfigHandle _ygConfig;

public YogaConfig()
{
_ygConfig = Native.YGConfigNew();
if (_ygConfig.IsInvalid)
{
throw new InvalidOperationException("Failed to allocate native memory");
}
}

internal Native.YGConfigHandle Handle {
get {
return _ygConfig;
}
}

public void SetExperimentalFeatureEnabled(
YogaExperimentalFeature feature,
bool enabled)
{
Native.YGConfigSetExperimentalFeatureEnabled(_ygConfig, feature, enabled);
}

public bool IsExperimentalFeatureEnabled(YogaExperimentalFeature feature)
{
return Native.YGConfigIsExperimentalFeatureEnabled(_ygConfig, feature);
}

}

public partial class YogaNode : IEnumerable<YogaNode>
{
private Native.YGNodeHandle _ygNode;
private YogaConfig _config;
private WeakReference _parent;
private List<YogaNode> _children;
private MeasureFunction _measureFunction;
Expand Down Expand Up @@ -89,15 +56,23 @@ public YogaNode(YogaConfig config)
{
YogaLogger.Initialize();

_ygNode = Native.YGNodeNewWithConfig(config.Handle);
if (config != null)
{
_config = config;
_ygNode = Native.YGNodeNewWithConfig(_config.Handle);
}
else
{
_ygNode = Native.YGNodeNew();
}
if (_ygNode.IsInvalid)
{
throw new InvalidOperationException("Failed to allocate native memory");
}
}

public YogaNode(YogaNode srcNode)
: this()
: this(srcNode._config)
{
CopyStyle(srcNode);
}
Expand Down