Move YGLogger into YGConfig and associate YGNodeRef with log events
Summary: Moves the `YGLogger` into `YGConfig` and pass the `YGNodeRef` into the logger to be able to associate the log messages and assertions with the specific node. Tackles facebook/yoga#530 and facebook/yoga#446 Closes https://github.com/facebook/yoga/pull/531 Reviewed By: astreet Differential Revision: D4970149 Pulled By: emilsjolander fbshipit-source-id: b7fcdaa273143ea2fa35861620b2e4d79f04f0af
This commit is contained in:
committed by
Facebook Github Bot
parent
40eba60cf5
commit
91230ae177
@@ -11,8 +11,10 @@
|
|||||||
#import <yoga/YGEnums.h>
|
#import <yoga/YGEnums.h>
|
||||||
#import <yoga/Yoga.h>
|
#import <yoga/Yoga.h>
|
||||||
|
|
||||||
extern YGValue YGPointValue(CGFloat value) NS_SWIFT_UNAVAILABLE("Use the swift Int and FloatingPoint extensions instead");
|
extern YGValue YGPointValue(CGFloat value)
|
||||||
extern YGValue YGPercentValue(CGFloat value) NS_SWIFT_UNAVAILABLE("Use the swift Int and FloatingPoint extensions instead");
|
NS_SWIFT_UNAVAILABLE("Use the swift Int and FloatingPoint extensions instead");
|
||||||
|
extern YGValue YGPercentValue(CGFloat value)
|
||||||
|
NS_SWIFT_UNAVAILABLE("Use the swift Int and FloatingPoint extensions instead");
|
||||||
|
|
||||||
typedef NS_OPTIONS(NSInteger, YGDimensionFlexibility) {
|
typedef NS_OPTIONS(NSInteger, YGDimensionFlexibility) {
|
||||||
YGDimensionFlexibilityFlexibleWidth = 1 << 0,
|
YGDimensionFlexibilityFlexibleWidth = 1 << 0,
|
||||||
@@ -108,7 +110,8 @@ typedef NS_OPTIONS(NSInteger, YGDimensionFlexibility) {
|
|||||||
Perform a layout calculation and update the frames of the views in the hierarchy with the results.
|
Perform a layout calculation and update the frames of the views in the hierarchy with the results.
|
||||||
If the origin is not preserved, the root view's layout results will applied from {0,0}.
|
If the origin is not preserved, the root view's layout results will applied from {0,0}.
|
||||||
*/
|
*/
|
||||||
- (void)applyLayoutPreservingOrigin:(BOOL)preserveOrigin dimensionFlexibility:(YGDimensionFlexibility)dimensionFlexibility
|
- (void)applyLayoutPreservingOrigin:(BOOL)preserveOrigin
|
||||||
|
dimensionFlexibility:(YGDimensionFlexibility)dimensionFlexibility
|
||||||
NS_SWIFT_NAME(applyLayout(preservingOrigin:dimensionFlexibility:));
|
NS_SWIFT_NAME(applyLayout(preservingOrigin:dimensionFlexibility:));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -10,9 +10,12 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)BaselineFunction.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)BaselineFunction.cs" />
|
||||||
|
<Compile Include="$(MSBuildThisFileDirectory)Logger.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)MeasureFunction.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)MeasureFunction.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)MeasureOutput.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)MeasureOutput.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Native.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Native.cs" />
|
||||||
|
<Compile Include="$(MSBuildThisFileDirectory)YGConfigHandle.cs" />
|
||||||
|
<Compile Include="$(MSBuildThisFileDirectory)YGNodeHandle.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)YogaAlign.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)YogaAlign.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)YogaBaselineFunc.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)YogaBaselineFunc.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)YogaConfig.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)YogaConfig.cs" />
|
||||||
|
17
csharp/Facebook.Yoga/Logger.cs
Normal file
17
csharp/Facebook.Yoga/Logger.cs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Facebook.Yoga
|
||||||
|
{
|
||||||
|
public delegate void Logger(
|
||||||
|
YogaConfig config,
|
||||||
|
YogaNode node,
|
||||||
|
YogaLogLevel level,
|
||||||
|
string message);
|
||||||
|
}
|
@@ -26,96 +26,9 @@ namespace Facebook.Yoga
|
|||||||
private const string DllName = "yoga";
|
private const string DllName = "yoga";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
internal class YGNodeHandle : SafeHandle
|
|
||||||
{
|
|
||||||
#if (UNITY_IOS && !UNITY_EDITOR) || ENABLE_IL2CPP || __IOS__
|
|
||||||
private GCHandle _managed;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
private YGNodeHandle() : base(IntPtr.Zero, true)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool IsInvalid
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return this.handle == IntPtr.Zero;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override bool ReleaseHandle()
|
|
||||||
{
|
|
||||||
#if (UNITY_IOS && !UNITY_EDITOR) || ENABLE_IL2CPP || __IOS__
|
|
||||||
ReleaseManaged();
|
|
||||||
#endif
|
|
||||||
Native.YGNodeFree(this.handle);
|
|
||||||
GC.KeepAlive(this);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if (UNITY_IOS && !UNITY_EDITOR) || ENABLE_IL2CPP || __IOS__
|
|
||||||
public void SetContext(YogaNode node)
|
|
||||||
{
|
|
||||||
if (!_managed.IsAllocated)
|
|
||||||
{
|
|
||||||
#if ENABLE_IL2CPP
|
|
||||||
// Weak causes 'GCHandle value belongs to a different domain' error
|
|
||||||
_managed = GCHandle.Alloc(node);
|
|
||||||
#else
|
|
||||||
_managed = GCHandle.Alloc(node, GCHandleType.Weak);
|
|
||||||
#endif
|
|
||||||
Native.YGNodeSetContext(this.handle, GCHandle.ToIntPtr(_managed));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ReleaseManaged()
|
|
||||||
{
|
|
||||||
if (_managed.IsAllocated)
|
|
||||||
{
|
|
||||||
_managed.Free();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static YogaNode GetManaged(IntPtr ygNodePtr)
|
|
||||||
{
|
|
||||||
var node =
|
|
||||||
GCHandle.FromIntPtr(Native.YGNodeGetContext(ygNodePtr)).Target as YogaNode;
|
|
||||||
if (node == null)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException("YogaNode is already deallocated");
|
|
||||||
}
|
|
||||||
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
internal class YGConfigHandle : SafeHandle
|
|
||||||
{
|
|
||||||
private YGConfigHandle() : base(IntPtr.Zero, true)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool IsInvalid
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return this.handle == IntPtr.Zero;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override bool ReleaseHandle()
|
|
||||||
{
|
|
||||||
Native.YGConfigFree(this.handle);
|
|
||||||
GC.KeepAlive(this);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||||
public static extern void YGInteropSetLogger(
|
public static extern void YGInteropSetLogger(
|
||||||
[MarshalAs(UnmanagedType.FunctionPtr)] YogaLogger.Func func);
|
[MarshalAs(UnmanagedType.FunctionPtr)] YogaLogger logger);
|
||||||
|
|
||||||
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||||
public static extern YGNodeHandle YGNodeNew();
|
public static extern YGNodeHandle YGNodeNew();
|
||||||
@@ -129,6 +42,9 @@ namespace Facebook.Yoga
|
|||||||
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||||
public static extern void YGNodeReset(YGNodeHandle node);
|
public static extern void YGNodeReset(YGNodeHandle node);
|
||||||
|
|
||||||
|
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
public static extern YGConfigHandle YGConfigGetDefault();
|
||||||
|
|
||||||
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||||
public static extern YGConfigHandle YGConfigNew();
|
public static extern YGConfigHandle YGConfigNew();
|
||||||
|
|
||||||
@@ -445,15 +361,19 @@ namespace Facebook.Yoga
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region AOT
|
#region Context
|
||||||
|
|
||||||
#if (UNITY_IOS && !UNITY_EDITOR) || ENABLE_IL2CPP || __IOS__
|
|
||||||
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||||
public static extern IntPtr YGNodeGetContext(IntPtr node);
|
public static extern IntPtr YGNodeGetContext(IntPtr node);
|
||||||
|
|
||||||
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||||
public static extern void YGNodeSetContext(IntPtr node, IntPtr managed);
|
public static extern void YGNodeSetContext(IntPtr node, IntPtr managed);
|
||||||
#endif
|
|
||||||
|
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
public static extern IntPtr YGConfigGetContext(IntPtr config);
|
||||||
|
|
||||||
|
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
public static extern void YGConfigSetContext(IntPtr config, IntPtr managed);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
84
csharp/Facebook.Yoga/YGConfigHandle.cs
Normal file
84
csharp/Facebook.Yoga/YGConfigHandle.cs
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace Facebook.Yoga
|
||||||
|
{
|
||||||
|
internal class YGConfigHandle : SafeHandle
|
||||||
|
{
|
||||||
|
internal static readonly YGConfigHandle Default = Native.YGConfigGetDefault();
|
||||||
|
private GCHandle _managedConfigHandle;
|
||||||
|
|
||||||
|
private YGConfigHandle() : base(IntPtr.Zero, true)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool IsInvalid
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return this.handle == IntPtr.Zero;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool ReleaseHandle()
|
||||||
|
{
|
||||||
|
if (this.handle != Default.handle)
|
||||||
|
{
|
||||||
|
ReleaseManaged();
|
||||||
|
if (!IsInvalid)
|
||||||
|
{
|
||||||
|
Native.YGConfigFree(this.handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
GC.KeepAlive(this);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetContext(YogaConfig config)
|
||||||
|
{
|
||||||
|
if (!_managedConfigHandle.IsAllocated)
|
||||||
|
{
|
||||||
|
#if UNITY_5_4_OR_NEWER
|
||||||
|
// Weak causes 'GCHandle value belongs to a different domain' error
|
||||||
|
_managedConfigHandle = GCHandle.Alloc(config);
|
||||||
|
#else
|
||||||
|
_managedConfigHandle = GCHandle.Alloc(config, GCHandleType.Weak);
|
||||||
|
#endif
|
||||||
|
var managedConfigPtr = GCHandle.ToIntPtr(_managedConfigHandle);
|
||||||
|
Native.YGConfigSetContext(this.handle, managedConfigPtr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ReleaseManaged()
|
||||||
|
{
|
||||||
|
if (_managedConfigHandle.IsAllocated)
|
||||||
|
{
|
||||||
|
_managedConfigHandle.Free();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static YogaConfig GetManaged(IntPtr unmanagedConfigPtr)
|
||||||
|
{
|
||||||
|
if (unmanagedConfigPtr != IntPtr.Zero)
|
||||||
|
{
|
||||||
|
var managedConfigPtr = Native.YGConfigGetContext(unmanagedConfigPtr);
|
||||||
|
var config = GCHandle.FromIntPtr(managedConfigPtr).Target as YogaConfig;
|
||||||
|
if (config == null)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("YogaConfig is already deallocated");
|
||||||
|
}
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
80
csharp/Facebook.Yoga/YGNodeHandle.cs
Normal file
80
csharp/Facebook.Yoga/YGNodeHandle.cs
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace Facebook.Yoga
|
||||||
|
{
|
||||||
|
internal class YGNodeHandle : SafeHandle
|
||||||
|
{
|
||||||
|
private GCHandle _managedNodeHandle;
|
||||||
|
|
||||||
|
private YGNodeHandle() : base(IntPtr.Zero, true)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool IsInvalid
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return this.handle == IntPtr.Zero;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool ReleaseHandle()
|
||||||
|
{
|
||||||
|
ReleaseManaged();
|
||||||
|
if (!IsInvalid)
|
||||||
|
{
|
||||||
|
Native.YGNodeFree(this.handle);
|
||||||
|
GC.KeepAlive(this);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetContext(YogaNode node)
|
||||||
|
{
|
||||||
|
if (!_managedNodeHandle.IsAllocated)
|
||||||
|
{
|
||||||
|
#if UNITY_5_4_OR_NEWER
|
||||||
|
// Weak causes 'GCHandle value belongs to a different domain' error
|
||||||
|
_managedNodeHandle = GCHandle.Alloc(node);
|
||||||
|
#else
|
||||||
|
_managedNodeHandle = GCHandle.Alloc(node, GCHandleType.Weak);
|
||||||
|
#endif
|
||||||
|
var managedNodePtr = GCHandle.ToIntPtr(_managedNodeHandle);
|
||||||
|
Native.YGNodeSetContext(this.handle, managedNodePtr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ReleaseManaged()
|
||||||
|
{
|
||||||
|
if (_managedNodeHandle.IsAllocated)
|
||||||
|
{
|
||||||
|
_managedNodeHandle.Free();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static YogaNode GetManaged(IntPtr unmanagedNodePtr)
|
||||||
|
{
|
||||||
|
if (unmanagedNodePtr != IntPtr.Zero)
|
||||||
|
{
|
||||||
|
var managedNodePtr = Native.YGNodeGetContext(unmanagedNodePtr);
|
||||||
|
var node = GCHandle.FromIntPtr(managedNodePtr).Target as YogaNode;
|
||||||
|
if (node == null)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("YogaNode is already deallocated");
|
||||||
|
}
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -13,5 +13,5 @@ using System.Runtime.InteropServices;
|
|||||||
namespace Facebook.Yoga
|
namespace Facebook.Yoga
|
||||||
{
|
{
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||||
public delegate float YogaBaselineFunc(IntPtr node, float width, float height);
|
public delegate float YogaBaselineFunc(IntPtr unmanagedNodePtr, float width, float height);
|
||||||
}
|
}
|
||||||
|
@@ -8,29 +8,92 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
#if __IOS__
|
||||||
|
using ObjCRuntime;
|
||||||
|
#endif
|
||||||
|
#if ENABLE_IL2CPP
|
||||||
|
using AOT;
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace Facebook.Yoga
|
namespace Facebook.Yoga
|
||||||
{
|
{
|
||||||
public class YogaConfig
|
public class YogaConfig
|
||||||
{
|
{
|
||||||
private Native.YGConfigHandle _ygConfig;
|
internal static readonly YogaConfig Default = new YogaConfig(YGConfigHandle.Default);
|
||||||
|
private static YogaLogger _managedLogger;
|
||||||
|
|
||||||
public YogaConfig()
|
private YGConfigHandle _ygConfig;
|
||||||
|
private Logger _logger;
|
||||||
|
|
||||||
|
private YogaConfig(YGConfigHandle ygConfig)
|
||||||
{
|
{
|
||||||
_ygConfig = Native.YGConfigNew();
|
_ygConfig = ygConfig;
|
||||||
if (_ygConfig.IsInvalid)
|
if (_ygConfig.IsInvalid)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("Failed to allocate native memory");
|
throw new InvalidOperationException("Failed to allocate native memory");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_ygConfig.SetContext(this);
|
||||||
|
|
||||||
|
if (_ygConfig == YGConfigHandle.Default)
|
||||||
|
{
|
||||||
|
_managedLogger = LoggerInternal;
|
||||||
|
Native.YGInteropSetLogger(_managedLogger);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal Native.YGConfigHandle Handle
|
public YogaConfig()
|
||||||
|
: this(Native.YGConfigNew())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
internal YGConfigHandle Handle
|
||||||
{
|
{
|
||||||
get {
|
get {
|
||||||
return _ygConfig;
|
return _ygConfig;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if (UNITY_IOS && !UNITY_EDITOR) || ENABLE_IL2CPP || __IOS__
|
||||||
|
[MonoPInvokeCallback(typeof(YogaLogger))]
|
||||||
|
#endif
|
||||||
|
private static void LoggerInternal(
|
||||||
|
IntPtr unmanagedConfigPtr,
|
||||||
|
IntPtr unmanagedNodePtr,
|
||||||
|
YogaLogLevel level,
|
||||||
|
string message)
|
||||||
|
{
|
||||||
|
var config = YGConfigHandle.GetManaged(unmanagedConfigPtr);
|
||||||
|
if (config == null || config._logger == null)
|
||||||
|
{
|
||||||
|
// Default logger
|
||||||
|
Console.WriteLine(message);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var node = YGNodeHandle.GetManaged(unmanagedNodePtr);
|
||||||
|
config._logger(config, node, level, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (level == YogaLogLevel.Error || level == YogaLogLevel.Fatal)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Logger Logger
|
||||||
|
{
|
||||||
|
get {
|
||||||
|
return _logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
set {
|
||||||
|
_logger = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void SetExperimentalFeatureEnabled(
|
public void SetExperimentalFeatureEnabled(
|
||||||
YogaExperimentalFeature feature,
|
YogaExperimentalFeature feature,
|
||||||
bool enabled)
|
bool enabled)
|
||||||
@@ -68,5 +131,10 @@ namespace Facebook.Yoga
|
|||||||
{
|
{
|
||||||
return Native.YGConfigGetInstanceCount();
|
return Native.YGConfigGetInstanceCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void SetDefaultLogger(Logger logger)
|
||||||
|
{
|
||||||
|
Default.Logger = logger;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,5 +16,6 @@ namespace Facebook.Yoga
|
|||||||
Info,
|
Info,
|
||||||
Debug,
|
Debug,
|
||||||
Verbose,
|
Verbose,
|
||||||
|
Fatal,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -10,48 +10,12 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
#if __IOS__
|
|
||||||
using ObjCRuntime;
|
|
||||||
#endif
|
|
||||||
#if ENABLE_IL2CPP
|
|
||||||
using AOT;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace Facebook.Yoga
|
namespace Facebook.Yoga
|
||||||
{
|
|
||||||
internal static class YogaLogger
|
|
||||||
{
|
{
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||||
public delegate void Func(YogaLogLevel level, string message);
|
public delegate void YogaLogger(
|
||||||
|
IntPtr unmanagedConfigPtr,
|
||||||
private static bool _initialized;
|
IntPtr unmanagedNotePtr,
|
||||||
private static Func _managedLogger = LoggerInternal;
|
YogaLogLevel level,
|
||||||
|
string message);
|
||||||
public static Func Logger = null;
|
|
||||||
|
|
||||||
#if (UNITY_IOS && !UNITY_EDITOR) || ENABLE_IL2CPP || __IOS__
|
|
||||||
[MonoPInvokeCallback(typeof(Func))]
|
|
||||||
#endif
|
|
||||||
public static void LoggerInternal(YogaLogLevel level, string message)
|
|
||||||
{
|
|
||||||
if (Logger != null)
|
|
||||||
{
|
|
||||||
Logger(level, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (level == YogaLogLevel.Error)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Initialize()
|
|
||||||
{
|
|
||||||
if (!_initialized)
|
|
||||||
{
|
|
||||||
Native.YGInteropSetLogger(_managedLogger);
|
|
||||||
_initialized = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -14,7 +14,7 @@ namespace Facebook.Yoga
|
|||||||
{
|
{
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||||
public delegate YogaSize YogaMeasureFunc(
|
public delegate YogaSize YogaMeasureFunc(
|
||||||
IntPtr node,
|
IntPtr unmanagedNodePtr,
|
||||||
float width,
|
float width,
|
||||||
YogaMeasureMode widthMode,
|
YogaMeasureMode widthMode,
|
||||||
float height,
|
float height,
|
||||||
|
@@ -10,11 +10,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
#if (UNITY_IOS && !UNITY_EDITOR) || ENABLE_IL2CPP || __IOS__
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
#endif
|
|
||||||
#if __IOS__
|
#if __IOS__
|
||||||
using ObjCRuntime;
|
using ObjCRuntime;
|
||||||
#endif
|
#endif
|
||||||
@@ -26,49 +24,26 @@ namespace Facebook.Yoga
|
|||||||
{
|
{
|
||||||
public partial class YogaNode : IEnumerable<YogaNode>
|
public partial class YogaNode : IEnumerable<YogaNode>
|
||||||
{
|
{
|
||||||
private readonly Native.YGNodeHandle _ygNode;
|
private readonly YGNodeHandle _ygNode;
|
||||||
private readonly YogaConfig _config;
|
private readonly YogaConfig _config;
|
||||||
private WeakReference _parent;
|
private WeakReference _parent;
|
||||||
private List<YogaNode> _children;
|
private List<YogaNode> _children;
|
||||||
private MeasureFunction _measureFunction;
|
private MeasureFunction _measureFunction;
|
||||||
private BaselineFunction _baselineFunction;
|
private BaselineFunction _baselineFunction;
|
||||||
private object _data;
|
|
||||||
#if (UNITY_IOS && !UNITY_EDITOR) || ENABLE_IL2CPP || __IOS__
|
|
||||||
private static YogaMeasureFunc _managedMeasure;
|
|
||||||
private static YogaBaselineFunc _managedBaseline;
|
|
||||||
#else
|
|
||||||
private YogaMeasureFunc _managedMeasure;
|
private YogaMeasureFunc _managedMeasure;
|
||||||
private YogaBaselineFunc _managedBaseline;
|
private YogaBaselineFunc _managedBaseline;
|
||||||
#endif
|
private object _data;
|
||||||
|
|
||||||
public YogaNode()
|
public YogaNode(YogaConfig config = null)
|
||||||
{
|
{
|
||||||
YogaLogger.Initialize();
|
_config = config == null ? YogaConfig.Default : config;
|
||||||
|
|
||||||
_ygNode = Native.YGNodeNew();
|
|
||||||
if (_ygNode.IsInvalid)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException("Failed to allocate native memory");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public YogaNode(YogaConfig config)
|
|
||||||
{
|
|
||||||
YogaLogger.Initialize();
|
|
||||||
|
|
||||||
if (config != null)
|
|
||||||
{
|
|
||||||
_config = config;
|
|
||||||
_ygNode = Native.YGNodeNewWithConfig(_config.Handle);
|
_ygNode = Native.YGNodeNewWithConfig(_config.Handle);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_ygNode = Native.YGNodeNew();
|
|
||||||
}
|
|
||||||
if (_ygNode.IsInvalid)
|
if (_ygNode.IsInvalid)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("Failed to allocate native memory");
|
throw new InvalidOperationException("Failed to allocate native memory");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_ygNode.SetContext(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public YogaNode(YogaNode srcNode)
|
public YogaNode(YogaNode srcNode)
|
||||||
@@ -83,10 +58,9 @@ namespace Facebook.Yoga
|
|||||||
_baselineFunction = null;
|
_baselineFunction = null;
|
||||||
_data = null;
|
_data = null;
|
||||||
|
|
||||||
Native.YGNodeReset(_ygNode);
|
|
||||||
#if (UNITY_IOS && !UNITY_EDITOR) || ENABLE_IL2CPP || __IOS__
|
|
||||||
_ygNode.ReleaseManaged();
|
_ygNode.ReleaseManaged();
|
||||||
#endif
|
Native.YGNodeReset(_ygNode);
|
||||||
|
_ygNode.SetContext(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsDirty
|
public bool IsDirty
|
||||||
@@ -609,38 +583,15 @@ namespace Facebook.Yoga
|
|||||||
public void SetMeasureFunction(MeasureFunction measureFunction)
|
public void SetMeasureFunction(MeasureFunction measureFunction)
|
||||||
{
|
{
|
||||||
_measureFunction = measureFunction;
|
_measureFunction = measureFunction;
|
||||||
if (measureFunction != null)
|
_managedMeasure = measureFunction != null ? MeasureInternal : (YogaMeasureFunc)null;
|
||||||
{
|
|
||||||
#if (UNITY_IOS && !UNITY_EDITOR) || ENABLE_IL2CPP || __IOS__
|
|
||||||
_managedMeasure = MeasureInternalAOT;
|
|
||||||
_ygNode.SetContext(this);
|
|
||||||
#else
|
|
||||||
_managedMeasure = MeasureInternal;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_managedMeasure = null;
|
|
||||||
}
|
|
||||||
Native.YGNodeSetMeasureFunc(_ygNode, _managedMeasure);
|
Native.YGNodeSetMeasureFunc(_ygNode, _managedMeasure);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetBaselineFunction(BaselineFunction baselineFunction)
|
public void SetBaselineFunction(BaselineFunction baselineFunction)
|
||||||
{
|
{
|
||||||
_baselineFunction = baselineFunction;
|
_baselineFunction = baselineFunction;
|
||||||
if (baselineFunction != null)
|
_managedBaseline =
|
||||||
{
|
baselineFunction != null ? BaselineInternal : (YogaBaselineFunc)null;
|
||||||
#if (UNITY_IOS && !UNITY_EDITOR) || ENABLE_IL2CPP || __IOS__
|
|
||||||
_managedBaseline = BaselineInternalAOT;
|
|
||||||
_ygNode.SetContext(this);
|
|
||||||
#else
|
|
||||||
_managedBaseline = BaselineInternal;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_managedBaseline = null;
|
|
||||||
}
|
|
||||||
Native.YGNodeSetBaselineFunc(_ygNode, _managedBaseline);
|
Native.YGNodeSetBaselineFunc(_ygNode, _managedBaseline);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -655,63 +606,46 @@ namespace Facebook.Yoga
|
|||||||
|
|
||||||
#if (UNITY_IOS && !UNITY_EDITOR) || ENABLE_IL2CPP || __IOS__
|
#if (UNITY_IOS && !UNITY_EDITOR) || ENABLE_IL2CPP || __IOS__
|
||||||
[MonoPInvokeCallback(typeof(YogaMeasureFunc))]
|
[MonoPInvokeCallback(typeof(YogaMeasureFunc))]
|
||||||
private static YogaSize MeasureInternalAOT(
|
|
||||||
IntPtr ygNodePtr,
|
|
||||||
float width,
|
|
||||||
YogaMeasureMode widthMode,
|
|
||||||
float height,
|
|
||||||
YogaMeasureMode heightMode)
|
|
||||||
{
|
|
||||||
var node = Native.YGNodeHandle.GetManaged(ygNodePtr);
|
|
||||||
return node.MeasureInternal(IntPtr.Zero, width, widthMode, height, heightMode);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
private static YogaSize MeasureInternal(
|
||||||
private YogaSize MeasureInternal(
|
IntPtr unmanagedNodePtr,
|
||||||
IntPtr node,
|
|
||||||
float width,
|
float width,
|
||||||
YogaMeasureMode widthMode,
|
YogaMeasureMode widthMode,
|
||||||
float height,
|
float height,
|
||||||
YogaMeasureMode heightMode)
|
YogaMeasureMode heightMode)
|
||||||
{
|
{
|
||||||
if (_measureFunction == null)
|
var node = YGNodeHandle.GetManaged(unmanagedNodePtr);
|
||||||
|
if (node == null || node._measureFunction == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("Measure function is not defined.");
|
throw new InvalidOperationException("Measure function is not defined.");
|
||||||
}
|
}
|
||||||
|
return node._measureFunction(node, width, widthMode, height, heightMode);
|
||||||
return _measureFunction(this, width, widthMode, height, heightMode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (UNITY_IOS && !UNITY_EDITOR) || ENABLE_IL2CPP || __IOS__
|
#if (UNITY_IOS && !UNITY_EDITOR) || ENABLE_IL2CPP || __IOS__
|
||||||
[MonoPInvokeCallback(typeof(YogaBaselineFunc))]
|
[MonoPInvokeCallback(typeof(YogaBaselineFunc))]
|
||||||
private static float BaselineInternalAOT(
|
#endif
|
||||||
IntPtr ygNodePtr,
|
private static float BaselineInternal(
|
||||||
|
IntPtr unmanagedNodePtr,
|
||||||
float width,
|
float width,
|
||||||
float height)
|
float height)
|
||||||
{
|
{
|
||||||
var node = Native.YGNodeHandle.GetManaged(ygNodePtr);
|
var node = YGNodeHandle.GetManaged(unmanagedNodePtr);
|
||||||
return node.BaselineInternal(IntPtr.Zero, width, height);
|
if (node == null || node._baselineFunction == null)
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
private float BaselineInternal(IntPtr node, float width, float height)
|
|
||||||
{
|
|
||||||
if (_baselineFunction == null)
|
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("Baseline function is not defined.");
|
throw new InvalidOperationException("Baseline function is not defined.");
|
||||||
}
|
}
|
||||||
|
return node._baselineFunction(node, width, height);
|
||||||
return _baselineFunction(this, width, height);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Print(YogaPrintOptions options =
|
public string Print(YogaPrintOptions options =
|
||||||
YogaPrintOptions.Layout|YogaPrintOptions.Style|YogaPrintOptions.Children)
|
YogaPrintOptions.Layout|YogaPrintOptions.Style|YogaPrintOptions.Children)
|
||||||
{
|
{
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
YogaLogger.Func orig = YogaLogger.Logger;
|
Logger orig = _config.Logger;
|
||||||
YogaLogger.Logger = (level, message) => {sb.Append(message);};
|
_config.Logger = (config, node, level, message) => {sb.Append(message);};
|
||||||
Native.YGNodePrint(_ygNode, options);
|
Native.YGNodePrint(_ygNode, options);
|
||||||
YogaLogger.Logger = orig;
|
_config.Logger = orig;
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -9,19 +9,23 @@
|
|||||||
|
|
||||||
#include "YGInterop.h"
|
#include "YGInterop.h"
|
||||||
|
|
||||||
static YGInteropLoggerFunc gManagedFunc;
|
static YGInteropLogger gManagedLogger;
|
||||||
|
|
||||||
static int unmanagedLogger(YGLogLevel level, const char *format, va_list args) {
|
static int unmanagedLogger(const YGConfigRef config,
|
||||||
|
const YGNodeRef node,
|
||||||
|
YGLogLevel level,
|
||||||
|
const char *format,
|
||||||
|
va_list args) {
|
||||||
int result = 0;
|
int result = 0;
|
||||||
if (gManagedFunc) {
|
if (gManagedLogger) {
|
||||||
char buffer[256];
|
char message[8192];
|
||||||
result = vsnprintf(buffer, sizeof(buffer), format, args);
|
result = vsnprintf(message, sizeof(message), format, args);
|
||||||
(*gManagedFunc)(level, buffer);
|
(*gManagedLogger)(config, node, level, message);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void YGInteropSetLogger(YGInteropLoggerFunc managedFunc) {
|
void YGInteropSetLogger(YGInteropLogger managedLogger) {
|
||||||
gManagedFunc = managedFunc;
|
gManagedLogger = managedLogger;
|
||||||
YGSetLogger(&unmanagedLogger);
|
YGSetLogger(YGConfigGetDefault(), &unmanagedLogger);
|
||||||
}
|
}
|
||||||
|
@@ -13,8 +13,13 @@
|
|||||||
|
|
||||||
YG_EXTERN_C_BEGIN
|
YG_EXTERN_C_BEGIN
|
||||||
|
|
||||||
typedef void (*YGInteropLoggerFunc)(YGLogLevel level, const char *message);
|
typedef int (*YGInteropLogger)(const void *unmanagedConfigPtr,
|
||||||
|
const void *unmanagedNodePtr,
|
||||||
|
YGLogLevel level,
|
||||||
|
const char *message);
|
||||||
|
|
||||||
WIN_EXPORT void YGInteropSetLogger(YGInteropLoggerFunc managedFunc);
|
WIN_EXPORT YGConfigRef YGConfigGetDefault();
|
||||||
|
|
||||||
|
WIN_EXPORT void YGInteropSetLogger(YGInteropLogger managedLogger);
|
||||||
|
|
||||||
YG_EXTERN_C_END
|
YG_EXTERN_C_END
|
||||||
|
@@ -69,6 +69,7 @@ namespace Facebook.Yoga
|
|||||||
Assert.AreEqual(YogaFlexDirection.Row, node1.FlexDirection);
|
Assert.AreEqual(YogaFlexDirection.Row, node1.FlexDirection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !UNITY_5_4_OR_NEWER
|
||||||
public static void ForceGC()
|
public static void ForceGC()
|
||||||
{
|
{
|
||||||
YogaNodeTest.ForceGC();
|
YogaNodeTest.ForceGC();
|
||||||
@@ -132,5 +133,6 @@ namespace Facebook.Yoga
|
|||||||
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -248,6 +248,26 @@ namespace Facebook.Yoga
|
|||||||
Assert.AreEqual(0, child2.LayoutY);
|
Assert.AreEqual(0, child2.LayoutY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestPrintOneNode()
|
||||||
|
{
|
||||||
|
YogaNode node = new YogaNode();
|
||||||
|
node.Width = 100;
|
||||||
|
node.Height = 120;
|
||||||
|
node.CalculateLayout();
|
||||||
|
Assert.AreEqual("<div layout=\"width: 100; height: 120; top: 0; left: 0;\" style=\"width: 100px; height: 120px; \" ></div>", node.Print());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestPrintWithLogger()
|
||||||
|
{
|
||||||
|
YogaNode node = new YogaNode(new YogaConfig{Logger = (c, n, l, m) => {}});
|
||||||
|
node.Width = 110;
|
||||||
|
node.Height = 105;
|
||||||
|
node.CalculateLayout();
|
||||||
|
Assert.AreEqual("<div layout=\"width: 110; height: 105; top: 0; left: 0;\" style=\"width: 110px; height: 105px; \" ></div>", node.Print());
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestPrint()
|
public void TestPrint()
|
||||||
{
|
{
|
||||||
@@ -309,9 +329,10 @@ namespace Facebook.Yoga
|
|||||||
Assert.AreEqual(90.Pt(), node4.MaxHeight);
|
Assert.AreEqual(90.Pt(), node4.MaxHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !UNITY_5_4_OR_NEWER
|
||||||
public static void ForceGC()
|
public static void ForceGC()
|
||||||
{
|
{
|
||||||
GC.Collect(GC.MaxGeneration);
|
GC.Collect();
|
||||||
GC.WaitForPendingFinalizers();
|
GC.WaitForPendingFinalizers();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -438,6 +459,7 @@ namespace Facebook.Yoga
|
|||||||
return MeasureOutput.Make(120, 130);
|
return MeasureOutput.Make(120, 130);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestLayoutMargin() {
|
public void TestLayoutMargin() {
|
||||||
|
@@ -24,5 +24,5 @@ ROOT=`buck root|tail -1`
|
|||||||
DYLIB=`buck targets --show-output $TARGET|tail -1|awk '{print $2}'`
|
DYLIB=`buck targets --show-output $TARGET|tail -1|awk '{print $2}'`
|
||||||
cp $ROOT/$DYLIB .
|
cp $ROOT/$DYLIB .
|
||||||
|
|
||||||
mcs -debug -t:library -r:$NUNIT/nunit.framework.dll -out:YogaTest.dll *.cs ../../../csharp/Facebook.Yoga/*cs
|
mcs -debug -d:YOGA_ENABLE_GC_TEST -t:library -r:$NUNIT/nunit.framework.dll -out:YogaTest.dll *.cs ../../../csharp/Facebook.Yoga/*cs
|
||||||
MONO_PATH=$NUNIT mono --arch=64 --debug $NUNIT/nunit-console.exe YogaTest.dll
|
MONO_PATH=$NUNIT mono --arch=64 --debug $NUNIT/nunit-console.exe YogaTest.dll
|
||||||
|
1
enums.py
1
enums.py
@@ -90,6 +90,7 @@ ENUMS = {
|
|||||||
'Info',
|
'Info',
|
||||||
'Debug',
|
'Debug',
|
||||||
'Verbose',
|
'Verbose',
|
||||||
|
'Fatal',
|
||||||
],
|
],
|
||||||
'ExperimentalFeature': [
|
'ExperimentalFeature': [
|
||||||
# Mimic web flex-basis behavior.
|
# Mimic web flex-basis behavior.
|
||||||
|
@@ -20,6 +20,7 @@ public class YogaConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
long mNativePointer;
|
long mNativePointer;
|
||||||
|
private YogaLogger mLogger;
|
||||||
|
|
||||||
private native long jni_YGConfigNew();
|
private native long jni_YGConfigNew();
|
||||||
public YogaConfig() {
|
public YogaConfig() {
|
||||||
@@ -67,4 +68,14 @@ public class YogaConfig {
|
|||||||
public void setUseLegacyStretchBehaviour(boolean useLegacyStretchBehaviour) {
|
public void setUseLegacyStretchBehaviour(boolean useLegacyStretchBehaviour) {
|
||||||
jni_YGConfigSetUseLegacyStretchBehaviour(mNativePointer, useLegacyStretchBehaviour);
|
jni_YGConfigSetUseLegacyStretchBehaviour(mNativePointer, useLegacyStretchBehaviour);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private native void jni_YGConfigSetLogger(long nativePointer, Object logger);
|
||||||
|
public void setLogger(YogaLogger logger) {
|
||||||
|
mLogger = logger;
|
||||||
|
jni_YGConfigSetLogger(mNativePointer, logger);
|
||||||
|
}
|
||||||
|
|
||||||
|
public YogaLogger getLogger() {
|
||||||
|
return mLogger;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,7 +17,8 @@ public enum YogaLogLevel {
|
|||||||
WARN(1),
|
WARN(1),
|
||||||
INFO(2),
|
INFO(2),
|
||||||
DEBUG(3),
|
DEBUG(3),
|
||||||
VERBOSE(4);
|
VERBOSE(4),
|
||||||
|
FATAL(5);
|
||||||
|
|
||||||
private int mIntValue;
|
private int mIntValue;
|
||||||
|
|
||||||
@@ -36,6 +37,7 @@ public enum YogaLogLevel {
|
|||||||
case 2: return INFO;
|
case 2: return INFO;
|
||||||
case 3: return DEBUG;
|
case 3: return DEBUG;
|
||||||
case 4: return VERBOSE;
|
case 4: return VERBOSE;
|
||||||
|
case 5: return FATAL;
|
||||||
default: throw new IllegalArgumentException("Unknown enum value: " + value);
|
default: throw new IllegalArgumentException("Unknown enum value: " + value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -18,5 +18,5 @@ import com.facebook.proguard.annotations.DoNotStrip;
|
|||||||
@DoNotStrip
|
@DoNotStrip
|
||||||
public interface YogaLogger {
|
public interface YogaLogger {
|
||||||
@DoNotStrip
|
@DoNotStrip
|
||||||
void log(YogaLogLevel level, String message);
|
void log(YogaNode node, YogaLogLevel level, String message);
|
||||||
}
|
}
|
||||||
|
@@ -28,12 +28,6 @@ public class YogaNode {
|
|||||||
* Get native instance count. Useful for testing only.
|
* Get native instance count. Useful for testing only.
|
||||||
*/
|
*/
|
||||||
static native int jni_YGNodeGetInstanceCount();
|
static native int jni_YGNodeGetInstanceCount();
|
||||||
static native void jni_YGLog(int level, String message);
|
|
||||||
|
|
||||||
private static native void jni_YGSetLogger(Object logger);
|
|
||||||
public static void setLogger(YogaLogger logger) {
|
|
||||||
jni_YGSetLogger(logger);
|
|
||||||
}
|
|
||||||
|
|
||||||
private YogaNode mParent;
|
private YogaNode mParent;
|
||||||
private List<YogaNode> mChildren;
|
private List<YogaNode> mChildren;
|
||||||
|
@@ -14,8 +14,12 @@
|
|||||||
using namespace facebook::jni;
|
using namespace facebook::jni;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
static inline weak_ref<jobject> *YGNodeJobject(YGNodeRef node) {
|
struct JYogaNode : public JavaClass<JYogaNode> {
|
||||||
return reinterpret_cast<weak_ref<jobject> *>(YGNodeGetContext(node));
|
static constexpr auto kJavaDescriptor = "Lcom/facebook/yoga/YogaNode;";
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline weak_ref<JYogaNode> *YGNodeJobject(YGNodeRef node) {
|
||||||
|
return reinterpret_cast<weak_ref<JYogaNode> *>(YGNodeGetContext(node));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void YGTransferLayoutDirection(YGNodeRef node, alias_ref<jobject> javaNode) {
|
static void YGTransferLayoutDirection(YGNodeRef node, alias_ref<jobject> javaNode) {
|
||||||
@@ -90,7 +94,7 @@ static void YGTransferLayoutOutputsRecursive(YGNodeRef root) {
|
|||||||
YGTransferLayoutOutputsRecursive(YGNodeGetChild(root, i));
|
YGTransferLayoutOutputsRecursive(YGNodeGetChild(root, i));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
YGLog(YGLogLevelError, "Java YGNode was GCed during layout calculation\n");
|
YGLog(root, YGLogLevelError, "Java YGNode was GCed during layout calculation\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -99,7 +103,7 @@ static void YGPrint(YGNodeRef node) {
|
|||||||
if (auto obj = YGNodeJobject(node)->lockLocal()) {
|
if (auto obj = YGNodeJobject(node)->lockLocal()) {
|
||||||
cout << obj->toString() << endl;
|
cout << obj->toString() << endl;
|
||||||
} else {
|
} else {
|
||||||
YGLog(YGLogLevelError, "Java YGNode was GCed during layout calculation\n");
|
YGLog(node, YGLogLevelError, "Java YGNode was GCed during layout calculation\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,7 +140,7 @@ static YGSize YGJNIMeasureFunc(YGNodeRef node,
|
|||||||
|
|
||||||
return YGSize{*measuredWidth, *measuredHeight};
|
return YGSize{*measuredWidth, *measuredHeight};
|
||||||
} else {
|
} else {
|
||||||
YGLog(YGLogLevelError, "Java YGNode was GCed during layout calculation\n");
|
YGLog(node, YGLogLevelError, "Java YGNode was GCed during layout calculation\n");
|
||||||
return YGSize{
|
return YGSize{
|
||||||
widthMode == YGMeasureModeUndefined ? 0 : width,
|
widthMode == YGMeasureModeUndefined ? 0 : width,
|
||||||
heightMode == YGMeasureModeUndefined ? 0 : height,
|
heightMode == YGMeasureModeUndefined ? 0 : height,
|
||||||
@@ -148,20 +152,28 @@ struct JYogaLogLevel : public JavaClass<JYogaLogLevel> {
|
|||||||
static constexpr auto kJavaDescriptor = "Lcom/facebook/yoga/YogaLogLevel;";
|
static constexpr auto kJavaDescriptor = "Lcom/facebook/yoga/YogaLogLevel;";
|
||||||
};
|
};
|
||||||
|
|
||||||
static global_ref<jobject> *jLogger;
|
static int YGJNILogFunc(const YGConfigRef config,
|
||||||
static int YGLog(YGLogLevel level, const char *format, va_list args) {
|
const YGNodeRef node,
|
||||||
|
YGLogLevel level,
|
||||||
|
const char *format,
|
||||||
|
va_list args) {
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
int result = vsnprintf(buffer, sizeof(buffer), format, args);
|
int result = vsnprintf(buffer, sizeof(buffer), format, args);
|
||||||
|
|
||||||
static auto logFunc = findClassStatic("com/facebook/yoga/YogaLogger")
|
static auto logFunc =
|
||||||
->getMethod<void(local_ref<JYogaLogLevel>, jstring)>("log");
|
findClassStatic("com/facebook/yoga/YogaLogger")
|
||||||
|
->getMethod<void(local_ref<JYogaNode>, local_ref<JYogaLogLevel>, jstring)>("log");
|
||||||
|
|
||||||
static auto logLevelFromInt =
|
static auto logLevelFromInt =
|
||||||
JYogaLogLevel::javaClassStatic()->getStaticMethod<JYogaLogLevel::javaobject(jint)>("fromInt");
|
JYogaLogLevel::javaClassStatic()->getStaticMethod<JYogaLogLevel::javaobject(jint)>("fromInt");
|
||||||
|
|
||||||
logFunc(jLogger->get(),
|
if (auto obj = YGNodeJobject(node)->lockLocal()) {
|
||||||
|
auto jlogger = reinterpret_cast<global_ref<jobject> *>(YGConfigGetContext(config));
|
||||||
|
logFunc(jlogger->get(),
|
||||||
|
obj,
|
||||||
logLevelFromInt(JYogaLogLevel::javaClassStatic(), static_cast<jint>(level)),
|
logLevelFromInt(JYogaLogLevel::javaClassStatic(), static_cast<jint>(level)),
|
||||||
Environment::current()->NewStringUTF(buffer));
|
Environment::current()->NewStringUTF(buffer));
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -174,27 +186,6 @@ static inline YGConfigRef _jlong2YGConfigRef(jlong addr) {
|
|||||||
return reinterpret_cast<YGConfigRef>(static_cast<intptr_t>(addr));
|
return reinterpret_cast<YGConfigRef>(static_cast<intptr_t>(addr));
|
||||||
}
|
}
|
||||||
|
|
||||||
void jni_YGSetLogger(alias_ref<jclass> clazz, alias_ref<jobject> logger) {
|
|
||||||
if (jLogger) {
|
|
||||||
jLogger->releaseAlias();
|
|
||||||
delete jLogger;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (logger) {
|
|
||||||
jLogger = new global_ref<jobject>(make_global(logger));
|
|
||||||
YGSetLogger(YGLog);
|
|
||||||
} else {
|
|
||||||
jLogger = NULL;
|
|
||||||
YGSetLogger(NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void jni_YGLog(alias_ref<jclass> clazz, jint level, jstring message) {
|
|
||||||
const char *nMessage = Environment::current()->GetStringUTFChars(message, 0);
|
|
||||||
YGLog(static_cast<YGLogLevel>(level), "%s", nMessage);
|
|
||||||
Environment::current()->ReleaseStringUTFChars(message, nMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
jlong jni_YGNodeNew(alias_ref<jobject> thiz) {
|
jlong jni_YGNodeNew(alias_ref<jobject> thiz) {
|
||||||
const YGNodeRef node = YGNodeNew();
|
const YGNodeRef node = YGNodeNew();
|
||||||
YGNodeSetContext(node, new weak_ref<jobject>(make_weak(thiz)));
|
YGNodeSetContext(node, new weak_ref<jobject>(make_weak(thiz)));
|
||||||
@@ -225,7 +216,9 @@ void jni_YGNodeReset(alias_ref<jobject> thiz, jlong nativePointer) {
|
|||||||
|
|
||||||
void jni_YGNodePrint(alias_ref<jobject> thiz, jlong nativePointer) {
|
void jni_YGNodePrint(alias_ref<jobject> thiz, jlong nativePointer) {
|
||||||
const YGNodeRef node = _jlong2YGNodeRef(nativePointer);
|
const YGNodeRef node = _jlong2YGNodeRef(nativePointer);
|
||||||
YGNodePrint(node, (YGPrintOptions) (YGPrintOptionsStyle | YGPrintOptionsLayout | YGPrintOptionsChildren));
|
YGNodePrint(node,
|
||||||
|
(YGPrintOptions)(YGPrintOptionsStyle | YGPrintOptionsLayout |
|
||||||
|
YGPrintOptionsChildren));
|
||||||
}
|
}
|
||||||
|
|
||||||
void jni_YGNodeInsertChild(alias_ref<jobject>, jlong nativePointer, jlong childPointer, jint index) {
|
void jni_YGNodeInsertChild(alias_ref<jobject>, jlong nativePointer, jlong childPointer, jint index) {
|
||||||
@@ -393,26 +386,56 @@ void jni_YGConfigFree(alias_ref<jobject>, jlong nativePointer) {
|
|||||||
YGConfigFree(config);
|
YGConfigFree(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
void jni_YGConfigSetExperimentalFeatureEnabled(alias_ref<jobject>, jlong nativePointer, jint feature, jboolean enabled) {
|
void jni_YGConfigSetExperimentalFeatureEnabled(alias_ref<jobject>,
|
||||||
|
jlong nativePointer,
|
||||||
|
jint feature,
|
||||||
|
jboolean enabled) {
|
||||||
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
|
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
|
||||||
YGConfigSetExperimentalFeatureEnabled(config, static_cast<YGExperimentalFeature>(feature), enabled);
|
YGConfigSetExperimentalFeatureEnabled(config,
|
||||||
|
static_cast<YGExperimentalFeature>(feature),
|
||||||
|
enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
void jni_YGConfigSetUseWebDefaults(alias_ref<jobject>, jlong nativePointer, jboolean useWebDefaults) {
|
void jni_YGConfigSetUseWebDefaults(alias_ref<jobject>,
|
||||||
|
jlong nativePointer,
|
||||||
|
jboolean useWebDefaults) {
|
||||||
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
|
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
|
||||||
YGConfigSetUseWebDefaults(config, useWebDefaults);
|
YGConfigSetUseWebDefaults(config, useWebDefaults);
|
||||||
}
|
}
|
||||||
|
|
||||||
void jni_YGConfigSetPointScaleFactor(alias_ref<jobject>, jlong nativePointer, jfloat pixelsInPoint) {
|
void jni_YGConfigSetPointScaleFactor(alias_ref<jobject>,
|
||||||
|
jlong nativePointer,
|
||||||
|
jfloat pixelsInPoint) {
|
||||||
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
|
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
|
||||||
YGConfigSetPointScaleFactor(config, pixelsInPoint);
|
YGConfigSetPointScaleFactor(config, pixelsInPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
void jni_YGConfigSetUseLegacyStretchBehaviour(alias_ref<jobject>, jlong nativePointer, jboolean useLegacyStretchBehaviour) {
|
void jni_YGConfigSetUseLegacyStretchBehaviour(alias_ref<jobject>,
|
||||||
|
jlong nativePointer,
|
||||||
|
jboolean useLegacyStretchBehaviour) {
|
||||||
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
|
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
|
||||||
YGConfigSetUseLegacyStretchBehaviour(config, useLegacyStretchBehaviour);
|
YGConfigSetUseLegacyStretchBehaviour(config, useLegacyStretchBehaviour);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void jni_YGConfigSetLogger(alias_ref<jobject>, jlong nativePointer, alias_ref<jobject> logger) {
|
||||||
|
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
|
||||||
|
|
||||||
|
auto context = YGConfigGetContext(config);
|
||||||
|
if (context) {
|
||||||
|
auto jlogger = reinterpret_cast<global_ref<jobject> *>(context);
|
||||||
|
jlogger->releaseAlias();
|
||||||
|
delete jlogger;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (logger) {
|
||||||
|
YGConfigSetContext(config, new global_ref<jobject>(make_global(logger)));
|
||||||
|
YGConfigSetLogger(config, YGJNILogFunc);
|
||||||
|
} else {
|
||||||
|
YGConfigSetContext(config, NULL);
|
||||||
|
YGConfigSetLogger(config, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
jint jni_YGNodeGetInstanceCount(alias_ref<jclass> clazz) {
|
jint jni_YGNodeGetInstanceCount(alias_ref<jclass> clazz) {
|
||||||
return YGNodeGetInstanceCount();
|
return YGNodeGetInstanceCount();
|
||||||
}
|
}
|
||||||
@@ -498,8 +521,6 @@ jint JNI_OnLoad(JavaVM *vm, void *) {
|
|||||||
YGMakeNativeMethod(jni_YGNodeStyleGetAspectRatio),
|
YGMakeNativeMethod(jni_YGNodeStyleGetAspectRatio),
|
||||||
YGMakeNativeMethod(jni_YGNodeStyleSetAspectRatio),
|
YGMakeNativeMethod(jni_YGNodeStyleSetAspectRatio),
|
||||||
YGMakeNativeMethod(jni_YGNodeGetInstanceCount),
|
YGMakeNativeMethod(jni_YGNodeGetInstanceCount),
|
||||||
YGMakeNativeMethod(jni_YGSetLogger),
|
|
||||||
YGMakeNativeMethod(jni_YGLog),
|
|
||||||
YGMakeNativeMethod(jni_YGNodePrint),
|
YGMakeNativeMethod(jni_YGNodePrint),
|
||||||
});
|
});
|
||||||
registerNatives("com/facebook/yoga/YogaConfig",
|
registerNatives("com/facebook/yoga/YogaConfig",
|
||||||
@@ -510,6 +531,7 @@ jint JNI_OnLoad(JavaVM *vm, void *) {
|
|||||||
YGMakeNativeMethod(jni_YGConfigSetUseWebDefaults),
|
YGMakeNativeMethod(jni_YGConfigSetUseWebDefaults),
|
||||||
YGMakeNativeMethod(jni_YGConfigSetPointScaleFactor),
|
YGMakeNativeMethod(jni_YGConfigSetPointScaleFactor),
|
||||||
YGMakeNativeMethod(jni_YGConfigSetUseLegacyStretchBehaviour),
|
YGMakeNativeMethod(jni_YGConfigSetUseLegacyStretchBehaviour),
|
||||||
|
YGMakeNativeMethod(jni_YGConfigSetLogger),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -124,38 +124,6 @@ public class YogaNodeTest {
|
|||||||
assertEquals(Float.MAX_VALUE, node.getLayoutHeight(), 0.01f);
|
assertEquals(Float.MAX_VALUE, node.getLayoutHeight(), 0.01f);
|
||||||
}
|
}
|
||||||
|
|
||||||
private YogaLogLevel mLogLevel;
|
|
||||||
private String mLogMessage;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testLogger() {
|
|
||||||
YogaNode.setLogger(new YogaLogger() {
|
|
||||||
public void log(YogaLogLevel level, String message) {
|
|
||||||
mLogLevel = level;
|
|
||||||
mLogMessage = message;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
YogaNode.jni_YGLog(YogaLogLevel.DEBUG.intValue(), "Hello");
|
|
||||||
assertEquals(YogaLogLevel.DEBUG, mLogLevel);
|
|
||||||
assertEquals("Hello", mLogMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testUpdateLogger() {
|
|
||||||
YogaNode.setLogger(new YogaLogger() {
|
|
||||||
public void log(YogaLogLevel level, String message) {}
|
|
||||||
});
|
|
||||||
YogaNode.setLogger(new YogaLogger() {
|
|
||||||
public void log(YogaLogLevel level, String message) {
|
|
||||||
mLogLevel = level;
|
|
||||||
mLogMessage = message;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
YogaNode.jni_YGLog(YogaLogLevel.VERBOSE.intValue(), "Flexbox");
|
|
||||||
assertEquals(YogaLogLevel.VERBOSE, mLogLevel);
|
|
||||||
assertEquals("Flexbox", mLogMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCopyStyle() {
|
public void testCopyStyle() {
|
||||||
final YogaNode node0 = new YogaNode();
|
final YogaNode node0 = new YogaNode();
|
||||||
|
@@ -59,12 +59,13 @@ module.exports = {
|
|||||||
JUSTIFY_SPACE_BETWEEN: 3,
|
JUSTIFY_SPACE_BETWEEN: 3,
|
||||||
JUSTIFY_SPACE_AROUND: 4,
|
JUSTIFY_SPACE_AROUND: 4,
|
||||||
|
|
||||||
LOG_LEVEL_COUNT: 5,
|
LOG_LEVEL_COUNT: 6,
|
||||||
LOG_LEVEL_ERROR: 0,
|
LOG_LEVEL_ERROR: 0,
|
||||||
LOG_LEVEL_WARN: 1,
|
LOG_LEVEL_WARN: 1,
|
||||||
LOG_LEVEL_INFO: 2,
|
LOG_LEVEL_INFO: 2,
|
||||||
LOG_LEVEL_DEBUG: 3,
|
LOG_LEVEL_DEBUG: 3,
|
||||||
LOG_LEVEL_VERBOSE: 4,
|
LOG_LEVEL_VERBOSE: 4,
|
||||||
|
LOG_LEVEL_FATAL: 5,
|
||||||
|
|
||||||
MEASURE_MODE_COUNT: 3,
|
MEASURE_MODE_COUNT: 3,
|
||||||
MEASURE_MODE_UNDEFINED: 0,
|
MEASURE_MODE_UNDEFINED: 0,
|
||||||
|
@@ -8,23 +8,33 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <yoga/Yoga.h>
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <yoga/Yoga.h>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
char writeBuffer[4096];
|
char writeBuffer[4096];
|
||||||
int _unmanagedLogger(YGLogLevel level, const char *format, va_list args) {
|
int _unmanagedLogger(const YGConfigRef config,
|
||||||
return vsnprintf(writeBuffer + strlen(writeBuffer), sizeof(writeBuffer) - strlen(writeBuffer), format, args);
|
const YGNodeRef node,
|
||||||
|
YGLogLevel level,
|
||||||
|
const char *format,
|
||||||
|
va_list args) {
|
||||||
|
return vsnprintf(writeBuffer + strlen(writeBuffer),
|
||||||
|
sizeof(writeBuffer) - strlen(writeBuffer),
|
||||||
|
format,
|
||||||
|
args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(YogaTest, logger_default_node_should_print_no_style_info) {
|
TEST(YogaTest, logger_default_node_should_print_no_style_info) {
|
||||||
writeBuffer[0] = '\0';
|
writeBuffer[0] = '\0';
|
||||||
YGSetLogger(_unmanagedLogger);
|
const YGConfigRef config = YGConfigNew();
|
||||||
const YGNodeRef root = YGNodeNew();
|
YGConfigSetLogger(config, _unmanagedLogger);
|
||||||
|
const YGNodeRef root = YGNodeNewWithConfig(config);
|
||||||
YGNodeCalculateLayout(root, YGUnitUndefined, YGUnitUndefined, YGDirectionLTR);
|
YGNodeCalculateLayout(root, YGUnitUndefined, YGUnitUndefined, YGDirectionLTR);
|
||||||
YGNodePrint(root, (YGPrintOptions)(YGPrintOptionsLayout | YGPrintOptionsChildren | YGPrintOptionsStyle));
|
YGNodePrint(root,
|
||||||
YGSetLogger(NULL);
|
(YGPrintOptions)(YGPrintOptionsLayout | YGPrintOptionsChildren |
|
||||||
|
YGPrintOptionsStyle));
|
||||||
|
YGConfigSetLogger(config, NULL);
|
||||||
YGNodeFree(root);
|
YGNodeFree(root);
|
||||||
|
|
||||||
const char *expected = "<div layout=\"width: 0; height: 0; top: 0; left: 0;\" style=\"\" ></div>";
|
const char *expected = "<div layout=\"width: 0; height: 0; top: 0; left: 0;\" style=\"\" ></div>";
|
||||||
@@ -33,8 +43,9 @@ TEST(YogaTest, logger_default_node_should_print_no_style_info) {
|
|||||||
|
|
||||||
TEST(YogaTest, logger_node_with_percentage_absolute_position_and_margin) {
|
TEST(YogaTest, logger_node_with_percentage_absolute_position_and_margin) {
|
||||||
writeBuffer[0] = '\0';
|
writeBuffer[0] = '\0';
|
||||||
YGSetLogger(_unmanagedLogger);
|
const YGConfigRef config = YGConfigNew();
|
||||||
const YGNodeRef root = YGNodeNew();
|
YGConfigSetLogger(config, _unmanagedLogger);
|
||||||
|
const YGNodeRef root = YGNodeNewWithConfig(config);
|
||||||
YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute);
|
YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute);
|
||||||
YGNodeStyleSetWidthPercent(root, 50);
|
YGNodeStyleSetWidthPercent(root, 50);
|
||||||
YGNodeStyleSetHeightPercent(root, 75);
|
YGNodeStyleSetHeightPercent(root, 75);
|
||||||
@@ -42,27 +53,37 @@ TEST(YogaTest, logger_node_with_percentage_absolute_position_and_margin) {
|
|||||||
YGNodeStyleSetMargin(root, YGEdgeRight, 10);
|
YGNodeStyleSetMargin(root, YGEdgeRight, 10);
|
||||||
YGNodeStyleSetMarginAuto(root, YGEdgeLeft);
|
YGNodeStyleSetMarginAuto(root, YGEdgeLeft);
|
||||||
YGNodeCalculateLayout(root, YGUnitUndefined, YGUnitUndefined, YGDirectionLTR);
|
YGNodeCalculateLayout(root, YGUnitUndefined, YGUnitUndefined, YGDirectionLTR);
|
||||||
YGNodePrint(root, (YGPrintOptions)(YGPrintOptionsLayout | YGPrintOptionsChildren | YGPrintOptionsStyle));
|
YGNodePrint(root,
|
||||||
YGSetLogger(NULL);
|
(YGPrintOptions)(YGPrintOptionsLayout | YGPrintOptionsChildren |
|
||||||
|
YGPrintOptionsStyle));
|
||||||
|
YGConfigSetLogger(config, NULL);
|
||||||
YGNodeFree(root);
|
YGNodeFree(root);
|
||||||
|
|
||||||
const char * expected = "<div layout=\"width: 0; height: 0; top: 0; left: 0;\" style=\"flex: 1; margin-left: auto; margin-right: 10px; width: 50%; height: 75%; position: absolute; \" ></div>";
|
const char *expected = "<div layout=\"width: 0; height: 0; top: 0; left: 0;\" style=\"flex: 1; "
|
||||||
|
"margin-left: auto; margin-right: 10px; width: 50%; height: 75%; "
|
||||||
|
"position: absolute; \" ></div>";
|
||||||
ASSERT_STREQ(expected, writeBuffer);
|
ASSERT_STREQ(expected, writeBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(YogaTest, logger_node_with_children_should_print_indented) {
|
TEST(YogaTest, logger_node_with_children_should_print_indented) {
|
||||||
writeBuffer[0] = '\0';
|
writeBuffer[0] = '\0';
|
||||||
YGSetLogger(_unmanagedLogger);
|
const YGConfigRef config = YGConfigNew();
|
||||||
const YGNodeRef root = YGNodeNew();
|
YGConfigSetLogger(config, _unmanagedLogger);
|
||||||
const YGNodeRef child0 = YGNodeNew();
|
const YGNodeRef root = YGNodeNewWithConfig(config);
|
||||||
const YGNodeRef child1 = YGNodeNew();
|
const YGNodeRef child0 = YGNodeNewWithConfig(config);
|
||||||
|
const YGNodeRef child1 = YGNodeNewWithConfig(config);
|
||||||
YGNodeInsertChild(root, child0, 0);
|
YGNodeInsertChild(root, child0, 0);
|
||||||
YGNodeInsertChild(root, child1, 1);
|
YGNodeInsertChild(root, child1, 1);
|
||||||
YGNodeCalculateLayout(root, YGUnitUndefined, YGUnitUndefined, YGDirectionLTR);
|
YGNodeCalculateLayout(root, YGUnitUndefined, YGUnitUndefined, YGDirectionLTR);
|
||||||
YGNodePrint(root, (YGPrintOptions)(YGPrintOptionsLayout | YGPrintOptionsChildren | YGPrintOptionsStyle));
|
YGNodePrint(root,
|
||||||
YGSetLogger(NULL);
|
(YGPrintOptions)(YGPrintOptionsLayout | YGPrintOptionsChildren |
|
||||||
|
YGPrintOptionsStyle));
|
||||||
|
YGConfigSetLogger(config, NULL);
|
||||||
YGNodeFreeRecursive(root);
|
YGNodeFreeRecursive(root);
|
||||||
|
|
||||||
const char * expected = "<div layout=\"width: 0; height: 0; top: 0; left: 0;\" style=\"\" >\n <div layout=\"width: 0; height: 0; top: 0; left: 0;\" style=\"\" ></div>\n <div layout=\"width: 0; height: 0; top: 0; left: 0;\" style=\"\" ></div>\n</div>";
|
const char *expected = "<div layout=\"width: 0; height: 0; top: 0; left: 0;\" style=\"\" >\n "
|
||||||
|
"<div layout=\"width: 0; height: 0; top: 0; left: 0;\" style=\"\" "
|
||||||
|
"></div>\n <div layout=\"width: 0; height: 0; top: 0; left: 0;\" "
|
||||||
|
"style=\"\" ></div>\n</div>";
|
||||||
ASSERT_STREQ(expected, writeBuffer);
|
ASSERT_STREQ(expected, writeBuffer);
|
||||||
}
|
}
|
||||||
|
@@ -30,11 +30,8 @@ static YGSize _simulate_wrapping_text(YGNodeRef node,
|
|||||||
YGMeasureMode widthMode,
|
YGMeasureMode widthMode,
|
||||||
float height,
|
float height,
|
||||||
YGMeasureMode heightMode) {
|
YGMeasureMode heightMode) {
|
||||||
if(widthMode == YGMeasureModeUndefined || width >= 68)
|
if (widthMode == YGMeasureModeUndefined || width >= 68) {
|
||||||
{
|
return YGSize{.width = 68, .height = 16};
|
||||||
return YGSize{
|
|
||||||
.width = 68, .height = 16
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return YGSize{
|
return YGSize{
|
||||||
@@ -196,8 +193,7 @@ TEST(YogaTest, dont_measure_when_min_equals_max_mixed_height_percent) {
|
|||||||
YGNodeFreeRecursive(root);
|
YGNodeFreeRecursive(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(YogaTest, measure_enough_size_should_be_in_single_line)
|
TEST(YogaTest, measure_enough_size_should_be_in_single_line) {
|
||||||
{
|
|
||||||
const YGNodeRef root = YGNodeNew();
|
const YGNodeRef root = YGNodeNew();
|
||||||
YGNodeStyleSetWidth(root, 100);
|
YGNodeStyleSetWidth(root, 100);
|
||||||
|
|
||||||
@@ -215,8 +211,7 @@ TEST(YogaTest, measure_enough_size_should_be_in_single_line)
|
|||||||
YGNodeFreeRecursive(root);
|
YGNodeFreeRecursive(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(YogaTest, measure_not_enough_size_should_wrap)
|
TEST(YogaTest, measure_not_enough_size_should_wrap) {
|
||||||
{
|
|
||||||
const YGNodeRef root = YGNodeNew();
|
const YGNodeRef root = YGNodeNew();
|
||||||
YGNodeStyleSetWidth(root, 55);
|
YGNodeStyleSetWidth(root, 55);
|
||||||
|
|
||||||
@@ -234,8 +229,7 @@ TEST(YogaTest, measure_not_enough_size_should_wrap)
|
|||||||
YGNodeFreeRecursive(root);
|
YGNodeFreeRecursive(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(YogaTest, measure_zero_space_should_grow)
|
TEST(YogaTest, measure_zero_space_should_grow) {
|
||||||
{
|
|
||||||
const YGNodeRef root = YGNodeNew();
|
const YGNodeRef root = YGNodeNew();
|
||||||
YGNodeStyleSetHeight(root, 200);
|
YGNodeStyleSetHeight(root, 200);
|
||||||
YGNodeStyleSetFlexDirection(root, YGFlexDirectionColumn);
|
YGNodeStyleSetFlexDirection(root, YGFlexDirectionColumn);
|
||||||
@@ -539,7 +533,6 @@ TEST(YogaTest, measure_no_padding) {
|
|||||||
YGConfigFree(config);
|
YGConfigFree(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if GTEST_HAS_DEATH_TEST
|
#if GTEST_HAS_DEATH_TEST
|
||||||
TEST(YogaDeathTest, cannot_add_child_to_node_with_measure_func) {
|
TEST(YogaDeathTest, cannot_add_child_to_node_with_measure_func) {
|
||||||
const YGNodeRef root = YGNodeNew();
|
const YGNodeRef root = YGNodeNew();
|
||||||
@@ -570,4 +563,3 @@ TEST(YogaTest, can_nullify_measure_func_on_any_node) {
|
|||||||
ASSERT_TRUE(YGNodeGetMeasureFunc(root) == NULL);
|
ASSERT_TRUE(YGNodeGetMeasureFunc(root) == NULL);
|
||||||
YGNodeFreeRecursive(root);
|
YGNodeFreeRecursive(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -11,6 +11,7 @@
|
|||||||
#include <yoga/Yoga.h>
|
#include <yoga/Yoga.h>
|
||||||
|
|
||||||
extern int32_t gNodeInstanceCount;
|
extern int32_t gNodeInstanceCount;
|
||||||
|
extern int32_t gConfigInstanceCount;
|
||||||
|
|
||||||
static int testMallocCount;
|
static int testMallocCount;
|
||||||
static int testCallocCount;
|
static int testCallocCount;
|
||||||
@@ -39,6 +40,7 @@ static void testFree(void *ptr) {
|
|||||||
|
|
||||||
TEST(YogaTest, memory_func_default) {
|
TEST(YogaTest, memory_func_default) {
|
||||||
gNodeInstanceCount = 0; // Reset YGNode instance count for memory func test
|
gNodeInstanceCount = 0; // Reset YGNode instance count for memory func test
|
||||||
|
gConfigInstanceCount = 0; // Reset YGConfig instance count for memory func test
|
||||||
YGSetMemoryFuncs(NULL, NULL, NULL, NULL);
|
YGSetMemoryFuncs(NULL, NULL, NULL, NULL);
|
||||||
const YGNodeRef root = YGNodeNew();
|
const YGNodeRef root = YGNodeNew();
|
||||||
const YGNodeRef root_child0 = YGNodeNew();
|
const YGNodeRef root_child0 = YGNodeNew();
|
||||||
@@ -48,6 +50,7 @@ TEST(YogaTest, memory_func_default) {
|
|||||||
|
|
||||||
TEST(YogaTest, memory_func_test_funcs) {
|
TEST(YogaTest, memory_func_test_funcs) {
|
||||||
gNodeInstanceCount = 0; // Reset YGNode instance count for memory func test
|
gNodeInstanceCount = 0; // Reset YGNode instance count for memory func test
|
||||||
|
gConfigInstanceCount = 0; // Reset YGConfig instance count for memory func test
|
||||||
YGSetMemoryFuncs(&testMalloc, &testCalloc, &testRealloc, &testFree);
|
YGSetMemoryFuncs(&testMalloc, &testCalloc, &testRealloc, &testFree);
|
||||||
const YGNodeRef root = YGNodeNew();
|
const YGNodeRef root = YGNodeNew();
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
@@ -65,6 +68,7 @@ TEST(YogaTest, memory_func_test_funcs) {
|
|||||||
#if GTEST_HAS_DEATH_TEST
|
#if GTEST_HAS_DEATH_TEST
|
||||||
TEST(YogaDeathTest, memory_func_assert_zero_nodes) {
|
TEST(YogaDeathTest, memory_func_assert_zero_nodes) {
|
||||||
gNodeInstanceCount = 0; // Reset YGNode instance count for memory func test
|
gNodeInstanceCount = 0; // Reset YGNode instance count for memory func test
|
||||||
|
gConfigInstanceCount = 0; // Reset YGConfig instance count for memory func test
|
||||||
const YGNodeRef root = YGNodeNew();
|
const YGNodeRef root = YGNodeNew();
|
||||||
ASSERT_DEATH(YGSetMemoryFuncs(&testMalloc, &testCalloc, &testRealloc, &testFree),
|
ASSERT_DEATH(YGSetMemoryFuncs(&testMalloc, &testCalloc, &testRealloc, &testFree),
|
||||||
"Cannot set memory functions: all node must be freed first");
|
"Cannot set memory functions: all node must be freed first");
|
||||||
@@ -73,6 +77,7 @@ TEST(YogaDeathTest, memory_func_assert_zero_nodes) {
|
|||||||
|
|
||||||
TEST(YogaDeathTest, memory_func_assert_all_non_null) {
|
TEST(YogaDeathTest, memory_func_assert_all_non_null) {
|
||||||
gNodeInstanceCount = 0; // Reset YGNode instance count for memory func test
|
gNodeInstanceCount = 0; // Reset YGNode instance count for memory func test
|
||||||
|
gConfigInstanceCount = 0; // Reset YGConfig instance count for memory func test
|
||||||
ASSERT_DEATH(YGSetMemoryFuncs(NULL, &testCalloc, &testRealloc, &testFree),
|
ASSERT_DEATH(YGSetMemoryFuncs(NULL, &testCalloc, &testRealloc, &testFree),
|
||||||
"Cannot set memory functions: functions must be all NULL or Non-NULL");
|
"Cannot set memory functions: functions must be all NULL or Non-NULL");
|
||||||
}
|
}
|
||||||
|
@@ -137,6 +137,8 @@ const char *YGLogLevelToString(const YGLogLevel value){
|
|||||||
return "debug";
|
return "debug";
|
||||||
case YGLogLevelVerbose:
|
case YGLogLevelVerbose:
|
||||||
return "verbose";
|
return "verbose";
|
||||||
|
case YGLogLevelFatal:
|
||||||
|
return "fatal";
|
||||||
}
|
}
|
||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
@@ -212,4 +214,3 @@ const char *YGWrapToString(const YGWrap value){
|
|||||||
}
|
}
|
||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -87,13 +87,14 @@ typedef YG_ENUM_BEGIN(YGJustify) {
|
|||||||
} YG_ENUM_END(YGJustify);
|
} YG_ENUM_END(YGJustify);
|
||||||
WIN_EXPORT const char *YGJustifyToString(const YGJustify value);
|
WIN_EXPORT const char *YGJustifyToString(const YGJustify value);
|
||||||
|
|
||||||
#define YGLogLevelCount 5
|
#define YGLogLevelCount 6
|
||||||
typedef YG_ENUM_BEGIN(YGLogLevel) {
|
typedef YG_ENUM_BEGIN(YGLogLevel) {
|
||||||
YGLogLevelError,
|
YGLogLevelError,
|
||||||
YGLogLevelWarn,
|
YGLogLevelWarn,
|
||||||
YGLogLevelInfo,
|
YGLogLevelInfo,
|
||||||
YGLogLevelDebug,
|
YGLogLevelDebug,
|
||||||
YGLogLevelVerbose,
|
YGLogLevelVerbose,
|
||||||
|
YGLogLevelFatal,
|
||||||
} YG_ENUM_END(YGLogLevel);
|
} YG_ENUM_END(YGLogLevel);
|
||||||
WIN_EXPORT const char *YGLogLevelToString(const YGLogLevel value);
|
WIN_EXPORT const char *YGLogLevelToString(const YGLogLevel value);
|
||||||
|
|
||||||
|
@@ -35,20 +35,6 @@
|
|||||||
#define FB_ASSERTIONS_ENABLED 1
|
#define FB_ASSERTIONS_ENABLED 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if FB_ASSERTIONS_ENABLED
|
|
||||||
#define YG_ABORT() abort()
|
|
||||||
#else
|
|
||||||
#define YG_ABORT()
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef YG_ASSERT
|
|
||||||
#define YG_ASSERT(X, message) \
|
|
||||||
if (!(X)) { \
|
|
||||||
YGLog(YGLogLevelError, "%s", message); \
|
|
||||||
YG_ABORT(); \
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef NS_ENUM
|
#ifdef NS_ENUM
|
||||||
// Cannot use NSInteger as NSInteger has a different size than int (which is the default type of a
|
// Cannot use NSInteger as NSInteger has a different size than int (which is the default type of a
|
||||||
// enum).
|
// enum).
|
||||||
|
@@ -21,12 +21,12 @@ struct YGNodeList {
|
|||||||
|
|
||||||
YGNodeListRef YGNodeListNew(const uint32_t initialCapacity) {
|
YGNodeListRef YGNodeListNew(const uint32_t initialCapacity) {
|
||||||
const YGNodeListRef list = gYGMalloc(sizeof(struct YGNodeList));
|
const YGNodeListRef list = gYGMalloc(sizeof(struct YGNodeList));
|
||||||
YG_ASSERT(list != NULL, "Could not allocate memory for list");
|
YGAssert(list != NULL, "Could not allocate memory for list");
|
||||||
|
|
||||||
list->capacity = initialCapacity;
|
list->capacity = initialCapacity;
|
||||||
list->count = 0;
|
list->count = 0;
|
||||||
list->items = gYGMalloc(sizeof(YGNodeRef) * list->capacity);
|
list->items = gYGMalloc(sizeof(YGNodeRef) * list->capacity);
|
||||||
YG_ASSERT(list->items != NULL, "Could not allocate memory for items");
|
YGAssert(list->items != NULL, "Could not allocate memory for items");
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
@@ -61,7 +61,7 @@ void YGNodeListInsert(YGNodeListRef *listp, const YGNodeRef node, const uint32_t
|
|||||||
if (list->count == list->capacity) {
|
if (list->count == list->capacity) {
|
||||||
list->capacity *= 2;
|
list->capacity *= 2;
|
||||||
list->items = gYGRealloc(list->items, sizeof(YGNodeRef) * list->capacity);
|
list->items = gYGRealloc(list->items, sizeof(YGNodeRef) * list->capacity);
|
||||||
YG_ASSERT(list->items != NULL, "Could not extend allocation for items");
|
YGAssert(list->items != NULL, "Could not extend allocation for items");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint32_t i = list->count; i > index; i--) {
|
for (uint32_t i = list->count; i > index; i--) {
|
||||||
|
344
yoga/Yoga.c
344
yoga/Yoga.c
@@ -99,6 +99,8 @@ typedef struct YGConfig {
|
|||||||
bool useWebDefaults;
|
bool useWebDefaults;
|
||||||
bool useLegacyStretchBehaviour;
|
bool useLegacyStretchBehaviour;
|
||||||
float pointScaleFactor;
|
float pointScaleFactor;
|
||||||
|
YGLogger logger;
|
||||||
|
void *context;
|
||||||
} YGConfig;
|
} YGConfig;
|
||||||
|
|
||||||
typedef struct YGNode {
|
typedef struct YGNode {
|
||||||
@@ -200,13 +202,33 @@ static YGNode gYGNodeDefaults = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifdef ANDROID
|
||||||
|
static int YGAndroidLog(const YGConfigRef config,
|
||||||
|
const YGNodeRef node,
|
||||||
|
YGLogLevel level,
|
||||||
|
const char *format,
|
||||||
|
va_list args);
|
||||||
|
#else
|
||||||
|
static int YGDefaultLog(const YGConfigRef config,
|
||||||
|
const YGNodeRef node,
|
||||||
|
YGLogLevel level,
|
||||||
|
const char *format,
|
||||||
|
va_list args);
|
||||||
|
#endif
|
||||||
|
|
||||||
static YGConfig gYGConfigDefaults = {
|
static YGConfig gYGConfigDefaults = {
|
||||||
.experimentalFeatures =
|
.experimentalFeatures =
|
||||||
{
|
{
|
||||||
[YGExperimentalFeatureWebFlexBasis] = false,
|
[YGExperimentalFeatureWebFlexBasis] = false,
|
||||||
},
|
},
|
||||||
.useWebDefaults = false,
|
.useWebDefaults = false,
|
||||||
.pointScaleFactor = 1.0f
|
.pointScaleFactor = 1.0f,
|
||||||
|
#ifdef ANDROID
|
||||||
|
.logger = &YGAndroidLog,
|
||||||
|
#else
|
||||||
|
.logger = &YGDefaultLog,
|
||||||
|
#endif
|
||||||
|
.context = NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void YGNodeMarkDirtyInternal(const YGNodeRef node);
|
static void YGNodeMarkDirtyInternal(const YGNodeRef node);
|
||||||
@@ -220,9 +242,16 @@ static YGValue YGValueZero = {.value = 0, .unit = YGUnitPoint};
|
|||||||
|
|
||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
#include <android/log.h>
|
#include <android/log.h>
|
||||||
static int YGAndroidLog(YGLogLevel level, const char *format, va_list args) {
|
static int YGAndroidLog(const YGConfigRef config,
|
||||||
|
const YGNodeRef node,
|
||||||
|
YGLogLevel level,
|
||||||
|
const char *format,
|
||||||
|
va_list args) {
|
||||||
int androidLevel = YGLogLevelDebug;
|
int androidLevel = YGLogLevelDebug;
|
||||||
switch (level) {
|
switch (level) {
|
||||||
|
case YGLogLevelFatal:
|
||||||
|
androidLevel = ANDROID_LOG_FATAL;
|
||||||
|
break;
|
||||||
case YGLogLevelError:
|
case YGLogLevelError:
|
||||||
androidLevel = ANDROID_LOG_ERROR;
|
androidLevel = ANDROID_LOG_ERROR;
|
||||||
break;
|
break;
|
||||||
@@ -239,14 +268,18 @@ static int YGAndroidLog(YGLogLevel level, const char *format, va_list args) {
|
|||||||
androidLevel = ANDROID_LOG_VERBOSE;
|
androidLevel = ANDROID_LOG_VERBOSE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
const int result = __android_log_vprint(androidLevel, "YG-layout", format, args);
|
const int result = __android_log_vprint(androidLevel, "yoga", format, args);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
static YGLogger gLogger = &YGAndroidLog;
|
|
||||||
#else
|
#else
|
||||||
static int YGDefaultLog(YGLogLevel level, const char *format, va_list args) {
|
static int YGDefaultLog(const YGConfigRef config,
|
||||||
|
const YGNodeRef node,
|
||||||
|
YGLogLevel level,
|
||||||
|
const char *format,
|
||||||
|
va_list args) {
|
||||||
switch (level) {
|
switch (level) {
|
||||||
case YGLogLevelError:
|
case YGLogLevelError:
|
||||||
|
case YGLogLevelFatal:
|
||||||
return vfprintf(stderr, format, args);
|
return vfprintf(stderr, format, args);
|
||||||
case YGLogLevelWarn:
|
case YGLogLevelWarn:
|
||||||
case YGLogLevelInfo:
|
case YGLogLevelInfo:
|
||||||
@@ -256,14 +289,11 @@ static int YGDefaultLog(YGLogLevel level, const char *format, va_list args) {
|
|||||||
return vprintf(format, args);
|
return vprintf(format, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static YGLogger gLogger = &YGDefaultLog;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static inline const YGValue *YGComputedEdgeValue(const YGValue edges[YGEdgeCount],
|
static inline const YGValue *YGComputedEdgeValue(const YGValue edges[YGEdgeCount],
|
||||||
const YGEdge edge,
|
const YGEdge edge,
|
||||||
const YGValue *const defaultValue) {
|
const YGValue *const defaultValue) {
|
||||||
YG_ASSERT(edge <= YGEdgeEnd, "Cannot get computed value of multi-edge shorthands");
|
|
||||||
|
|
||||||
if (edges[edge].unit != YGUnitUndefined) {
|
if (edges[edge].unit != YGUnitUndefined) {
|
||||||
return &edges[edge];
|
return &edges[edge];
|
||||||
}
|
}
|
||||||
@@ -311,7 +341,7 @@ int32_t gConfigInstanceCount = 0;
|
|||||||
|
|
||||||
WIN_EXPORT YGNodeRef YGNodeNewWithConfig(const YGConfigRef config) {
|
WIN_EXPORT YGNodeRef YGNodeNewWithConfig(const YGConfigRef config) {
|
||||||
const YGNodeRef node = gYGMalloc(sizeof(YGNode));
|
const YGNodeRef node = gYGMalloc(sizeof(YGNode));
|
||||||
YG_ASSERT(node, "Could not allocate memory for node");
|
YGAssertWithConfig(config, node != NULL, "Could not allocate memory for node");
|
||||||
gNodeInstanceCount++;
|
gNodeInstanceCount++;
|
||||||
|
|
||||||
memcpy(node, &gYGNodeDefaults, sizeof(YGNode));
|
memcpy(node, &gYGNodeDefaults, sizeof(YGNode));
|
||||||
@@ -354,9 +384,10 @@ void YGNodeFreeRecursive(const YGNodeRef root) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void YGNodeReset(const YGNodeRef node) {
|
void YGNodeReset(const YGNodeRef node) {
|
||||||
YG_ASSERT(YGNodeGetChildCount(node) == 0,
|
YGAssertWithNode(node,
|
||||||
|
YGNodeGetChildCount(node) == 0,
|
||||||
"Cannot reset a node which still has children attached");
|
"Cannot reset a node which still has children attached");
|
||||||
YG_ASSERT(node->parent == NULL, "Cannot reset a node still attached to a parent");
|
YGAssertWithNode(node, node->parent == NULL, "Cannot reset a node still attached to a parent");
|
||||||
|
|
||||||
YGNodeListFree(node->children);
|
YGNodeListFree(node->children);
|
||||||
|
|
||||||
@@ -377,9 +408,15 @@ int32_t YGConfigGetInstanceCount(void) {
|
|||||||
return gConfigInstanceCount;
|
return gConfigInstanceCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Export only for C#
|
||||||
|
YGConfigRef YGConfigGetDefault() {
|
||||||
|
return &gYGConfigDefaults;
|
||||||
|
}
|
||||||
|
|
||||||
YGConfigRef YGConfigNew(void) {
|
YGConfigRef YGConfigNew(void) {
|
||||||
const YGConfigRef config = gYGMalloc(sizeof(YGConfig));
|
const YGConfigRef config = gYGMalloc(sizeof(YGConfig));
|
||||||
YG_ASSERT(config, "Could not allocate memory for config");
|
YGLog(NULL, config != NULL, "Could not allocate memory for config");
|
||||||
|
|
||||||
gConfigInstanceCount++;
|
gConfigInstanceCount++;
|
||||||
memcpy(config, &gYGConfigDefaults, sizeof(YGConfig));
|
memcpy(config, &gYGConfigDefaults, sizeof(YGConfig));
|
||||||
return config;
|
return config;
|
||||||
@@ -408,7 +445,8 @@ void YGNodeSetMeasureFunc(const YGNodeRef node, YGMeasureFunc measureFunc) {
|
|||||||
if (measureFunc == NULL) {
|
if (measureFunc == NULL) {
|
||||||
node->measure = NULL;
|
node->measure = NULL;
|
||||||
} else {
|
} else {
|
||||||
YG_ASSERT(YGNodeGetChildCount(node) == 0,
|
YGAssertWithNode(node,
|
||||||
|
YGNodeGetChildCount(node) == 0,
|
||||||
"Cannot set measure function: Nodes with measure functions cannot have children.");
|
"Cannot set measure function: Nodes with measure functions cannot have children.");
|
||||||
node->measure = measureFunc;
|
node->measure = measureFunc;
|
||||||
}
|
}
|
||||||
@@ -427,9 +465,11 @@ YGBaselineFunc YGNodeGetBaselineFunc(const YGNodeRef node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void YGNodeInsertChild(const YGNodeRef node, const YGNodeRef child, const uint32_t index) {
|
void YGNodeInsertChild(const YGNodeRef node, const YGNodeRef child, const uint32_t index) {
|
||||||
YG_ASSERT(child->parent == NULL, "Child already has a parent, it must be removed first.");
|
YGAssertWithNode(node, child->parent == NULL, "Child already has a parent, it must be removed first.");
|
||||||
YG_ASSERT(node->measure == NULL,
|
YGAssertWithNode(node,
|
||||||
|
node->measure == NULL,
|
||||||
"Cannot add child: Nodes with measure functions cannot have children.");
|
"Cannot add child: Nodes with measure functions cannot have children.");
|
||||||
|
|
||||||
YGNodeListInsert(&node->children, child, index);
|
YGNodeListInsert(&node->children, child, index);
|
||||||
child->parent = node;
|
child->parent = node;
|
||||||
YGNodeMarkDirtyInternal(node);
|
YGNodeMarkDirtyInternal(node);
|
||||||
@@ -456,9 +496,11 @@ inline uint32_t YGNodeGetChildCount(const YGNodeRef node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void YGNodeMarkDirty(const YGNodeRef node) {
|
void YGNodeMarkDirty(const YGNodeRef node) {
|
||||||
YG_ASSERT(node->measure != NULL,
|
YGAssertWithNode(node,
|
||||||
|
node->measure != NULL,
|
||||||
"Only leaf nodes with custom measure functions"
|
"Only leaf nodes with custom measure functions"
|
||||||
"should manually mark themselves as dirty");
|
"should manually mark themselves as dirty");
|
||||||
|
|
||||||
YGNodeMarkDirtyInternal(node);
|
YGNodeMarkDirtyInternal(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -488,14 +530,17 @@ float YGNodeStyleGetFlexGrow(const YGNodeRef node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
float YGNodeStyleGetFlexShrink(const YGNodeRef node) {
|
float YGNodeStyleGetFlexShrink(const YGNodeRef node) {
|
||||||
return YGFloatIsUndefined(node->style.flexShrink) ? (node->config->useWebDefaults ? kWebDefaultFlexShrink : kDefaultFlexShrink) : node->style.flexShrink;
|
return YGFloatIsUndefined(node->style.flexShrink)
|
||||||
|
? (node->config->useWebDefaults ? kWebDefaultFlexShrink : kDefaultFlexShrink)
|
||||||
|
: node->style.flexShrink;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline float YGNodeResolveFlexShrink(const YGNodeRef node) {
|
static inline float YGNodeResolveFlexShrink(const YGNodeRef node) {
|
||||||
if (!YGFloatIsUndefined(node->style.flexShrink)) {
|
if (!YGFloatIsUndefined(node->style.flexShrink)) {
|
||||||
return node->style.flexShrink;
|
return node->style.flexShrink;
|
||||||
}
|
}
|
||||||
if (!node->config->useWebDefaults && !YGFloatIsUndefined(node->style.flex) && node->style.flex < 0.0f) {
|
if (!node->config->useWebDefaults && !YGFloatIsUndefined(node->style.flex) &&
|
||||||
|
node->style.flex < 0.0f) {
|
||||||
return -node->style.flex;
|
return -node->style.flex;
|
||||||
}
|
}
|
||||||
return node->config->useWebDefaults ? kWebDefaultFlexShrink : kDefaultFlexShrink;
|
return node->config->useWebDefaults ? kWebDefaultFlexShrink : kDefaultFlexShrink;
|
||||||
@@ -533,8 +578,7 @@ static inline const YGValue *YGNodeResolveFlexBasisPtr(const YGNodeRef node) {
|
|||||||
if (node->style.instanceName.value != paramName || \
|
if (node->style.instanceName.value != paramName || \
|
||||||
node->style.instanceName.unit != YGUnitPoint) { \
|
node->style.instanceName.unit != YGUnitPoint) { \
|
||||||
node->style.instanceName.value = paramName; \
|
node->style.instanceName.value = paramName; \
|
||||||
node->style.instanceName.unit = \
|
node->style.instanceName.unit = YGFloatIsUndefined(paramName) ? YGUnitAuto : YGUnitPoint; \
|
||||||
YGFloatIsUndefined(paramName) ? YGUnitAuto : YGUnitPoint; \
|
|
||||||
YGNodeMarkDirtyInternal(node); \
|
YGNodeMarkDirtyInternal(node); \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
@@ -543,8 +587,7 @@ static inline const YGValue *YGNodeResolveFlexBasisPtr(const YGNodeRef node) {
|
|||||||
if (node->style.instanceName.value != paramName || \
|
if (node->style.instanceName.value != paramName || \
|
||||||
node->style.instanceName.unit != YGUnitPercent) { \
|
node->style.instanceName.unit != YGUnitPercent) { \
|
||||||
node->style.instanceName.value = paramName; \
|
node->style.instanceName.value = paramName; \
|
||||||
node->style.instanceName.unit = \
|
node->style.instanceName.unit = YGFloatIsUndefined(paramName) ? YGUnitAuto : YGUnitPercent; \
|
||||||
YGFloatIsUndefined(paramName) ? YGUnitAuto : YGUnitPercent; \
|
|
||||||
YGNodeMarkDirtyInternal(node); \
|
YGNodeMarkDirtyInternal(node); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
@@ -655,7 +698,7 @@ static inline const YGValue *YGNodeResolveFlexBasisPtr(const YGNodeRef node) {
|
|||||||
|
|
||||||
#define YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(type, name, instanceName) \
|
#define YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(type, name, instanceName) \
|
||||||
type YGNodeLayoutGet##name(const YGNodeRef node, const YGEdge edge) { \
|
type YGNodeLayoutGet##name(const YGNodeRef node, const YGEdge edge) { \
|
||||||
YG_ASSERT(edge <= YGEdgeEnd, "Cannot get layout properties of multi-edge shorthands"); \
|
YGAssertWithNode(node, edge < YGEdgeEnd, "Cannot get layout properties of multi-edge shorthands"); \
|
||||||
\
|
\
|
||||||
if (edge == YGEdgeLeft) { \
|
if (edge == YGEdgeLeft) { \
|
||||||
if (node->layout.direction == YGDirectionRTL) { \
|
if (node->layout.direction == YGDirectionRTL) { \
|
||||||
@@ -772,42 +815,53 @@ static inline bool YGFloatsEqual(const float a, const float b) {
|
|||||||
return fabs(a - b) < 0.0001f;
|
return fabs(a - b) < 0.0001f;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void YGIndent(const uint32_t n) {
|
static void YGIndent(const YGNodeRef node, const uint32_t n) {
|
||||||
for (uint32_t i = 0; i < n; i++) {
|
for (uint32_t i = 0; i < n; i++) {
|
||||||
YGLog(YGLogLevelDebug, " ");
|
YGLog(node, YGLogLevelDebug, " ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void YGPrintNumberIfNotUndefinedf(const char *str, const float number) {
|
static void YGPrintNumberIfNotUndefinedf(const YGNodeRef node,
|
||||||
|
const char *str,
|
||||||
|
const float number) {
|
||||||
if (!YGFloatIsUndefined(number)) {
|
if (!YGFloatIsUndefined(number)) {
|
||||||
YGLog(YGLogLevelDebug, "%s: %g; ", str, number);
|
YGLog(node, YGLogLevelDebug, "%s: %g; ", str, number);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void YGPrintNumberIfNotUndefined(const char *str, const YGValue *const number) {
|
static void YGPrintNumberIfNotUndefined(const YGNodeRef node,
|
||||||
|
const char *str,
|
||||||
|
const YGValue *const number) {
|
||||||
if (number->unit != YGUnitUndefined) {
|
if (number->unit != YGUnitUndefined) {
|
||||||
if (number->unit == YGUnitAuto) {
|
if (number->unit == YGUnitAuto) {
|
||||||
YGLog(YGLogLevelDebug, "%s: auto; ", str);
|
YGLog(node, YGLogLevelDebug, "%s: auto; ", str);
|
||||||
} else {
|
} else {
|
||||||
const char *unit = number->unit == YGUnitPoint ? "px" : "%";
|
const char *unit = number->unit == YGUnitPoint ? "px" : "%";
|
||||||
YGLog(YGLogLevelDebug, "%s: %g%s; ", str, number->value, unit);
|
YGLog(node, YGLogLevelDebug, "%s: %g%s; ", str, number->value, unit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void YGPrintNumberIfNotAuto(const char *str, const YGValue *const number) {
|
static void YGPrintNumberIfNotAuto(const YGNodeRef node,
|
||||||
|
const char *str,
|
||||||
|
const YGValue *const number) {
|
||||||
if (number->unit != YGUnitAuto) {
|
if (number->unit != YGUnitAuto) {
|
||||||
YGPrintNumberIfNotUndefined(str, number);
|
YGPrintNumberIfNotUndefined(node, str, number);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void YGPrintEdgeIfNotUndefined(const char *str, const YGValue *edges, const YGEdge edge) {
|
static void YGPrintEdgeIfNotUndefined(const YGNodeRef node,
|
||||||
YGPrintNumberIfNotUndefined(str, YGComputedEdgeValue(edges, YGEdgeLeft, &YGValueUndefined));
|
const char *str,
|
||||||
|
const YGValue *edges,
|
||||||
|
const YGEdge edge) {
|
||||||
|
YGPrintNumberIfNotUndefined(node, str, YGComputedEdgeValue(edges, YGEdgeLeft, &YGValueUndefined));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void YGPrintNumberIfNotZero(const char *str, const YGValue *const number) {
|
static void YGPrintNumberIfNotZero(const YGNodeRef node,
|
||||||
|
const char *str,
|
||||||
|
const YGValue *const number) {
|
||||||
if (!YGFloatsEqual(number->value, 0)) {
|
if (!YGFloatsEqual(number->value, 0)) {
|
||||||
YGPrintNumberIfNotUndefined(str, number);
|
YGPrintNumberIfNotUndefined(node, str, number);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -816,14 +870,14 @@ static bool YGFourValuesEqual(const YGValue four[4]) {
|
|||||||
YGValueEqual(four[0], four[3]);
|
YGValueEqual(four[0], four[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void YGPrintEdges(const char *str, const YGValue *edges) {
|
static void YGPrintEdges(const YGNodeRef node, const char *str, const YGValue *edges) {
|
||||||
if (YGFourValuesEqual(edges)) {
|
if (YGFourValuesEqual(edges)) {
|
||||||
YGPrintNumberIfNotZero(str, &edges[YGEdgeLeft]);
|
YGPrintNumberIfNotZero(node, str, &edges[YGEdgeLeft]);
|
||||||
} else {
|
} else {
|
||||||
for (YGEdge edge = YGEdgeLeft; edge < YGEdgeCount; edge++) {
|
for (YGEdge edge = YGEdgeLeft; edge < YGEdgeCount; edge++) {
|
||||||
char buf[30];
|
char buf[30];
|
||||||
snprintf(buf, sizeof(buf), "%s-%s", str, YGEdgeToString(edge));
|
snprintf(buf, sizeof(buf), "%s-%s", str, YGEdgeToString(edge));
|
||||||
YGPrintNumberIfNotZero(buf, &edges[edge]);
|
YGPrintNumberIfNotZero(node, buf, &edges[edge]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -831,98 +885,103 @@ static void YGPrintEdges(const char *str, const YGValue *edges) {
|
|||||||
static void YGNodePrintInternal(const YGNodeRef node,
|
static void YGNodePrintInternal(const YGNodeRef node,
|
||||||
const YGPrintOptions options,
|
const YGPrintOptions options,
|
||||||
const uint32_t level) {
|
const uint32_t level) {
|
||||||
YGIndent(level);
|
YGIndent(node, level);
|
||||||
YGLog(YGLogLevelDebug, "<div ");
|
YGLog(node, YGLogLevelDebug, "<div ");
|
||||||
|
|
||||||
if (node->print) {
|
if (node->print) {
|
||||||
node->print(node);
|
node->print(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options & YGPrintOptionsLayout) {
|
if (options & YGPrintOptionsLayout) {
|
||||||
YGLog(YGLogLevelDebug, "layout=\"");
|
YGLog(node, YGLogLevelDebug, "layout=\"");
|
||||||
YGLog(YGLogLevelDebug, "width: %g; ", node->layout.dimensions[YGDimensionWidth]);
|
YGLog(node, YGLogLevelDebug, "width: %g; ", node->layout.dimensions[YGDimensionWidth]);
|
||||||
YGLog(YGLogLevelDebug, "height: %g; ", node->layout.dimensions[YGDimensionHeight]);
|
YGLog(node, YGLogLevelDebug, "height: %g; ", node->layout.dimensions[YGDimensionHeight]);
|
||||||
YGLog(YGLogLevelDebug, "top: %g; ", node->layout.position[YGEdgeTop]);
|
YGLog(node, YGLogLevelDebug, "top: %g; ", node->layout.position[YGEdgeTop]);
|
||||||
YGLog(YGLogLevelDebug, "left: %g;", node->layout.position[YGEdgeLeft]);
|
YGLog(node, YGLogLevelDebug, "left: %g;", node->layout.position[YGEdgeLeft]);
|
||||||
YGLog(YGLogLevelDebug, "\" ");
|
YGLog(node, YGLogLevelDebug, "\" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options & YGPrintOptionsStyle) {
|
if (options & YGPrintOptionsStyle) {
|
||||||
YGLog(YGLogLevelDebug, "style=\"");
|
YGLog(node, YGLogLevelDebug, "style=\"");
|
||||||
if (node->style.flexDirection != gYGNodeDefaults.style.flexDirection) {
|
if (node->style.flexDirection != gYGNodeDefaults.style.flexDirection) {
|
||||||
YGLog(YGLogLevelDebug,
|
YGLog(node,
|
||||||
|
YGLogLevelDebug,
|
||||||
"flex-direction: %s; ",
|
"flex-direction: %s; ",
|
||||||
YGFlexDirectionToString(node->style.flexDirection));
|
YGFlexDirectionToString(node->style.flexDirection));
|
||||||
}
|
}
|
||||||
if (node->style.justifyContent != gYGNodeDefaults.style.justifyContent) {
|
if (node->style.justifyContent != gYGNodeDefaults.style.justifyContent) {
|
||||||
YGLog(YGLogLevelDebug,
|
YGLog(node,
|
||||||
|
YGLogLevelDebug,
|
||||||
"justify-content: %s; ",
|
"justify-content: %s; ",
|
||||||
YGJustifyToString(node->style.justifyContent));
|
YGJustifyToString(node->style.justifyContent));
|
||||||
}
|
}
|
||||||
if (node->style.alignItems != gYGNodeDefaults.style.alignItems) {
|
if (node->style.alignItems != gYGNodeDefaults.style.alignItems) {
|
||||||
YGLog(YGLogLevelDebug, "align-items: %s; ", YGAlignToString(node->style.alignItems));
|
YGLog(node, YGLogLevelDebug, "align-items: %s; ", YGAlignToString(node->style.alignItems));
|
||||||
}
|
}
|
||||||
if (node->style.alignContent != gYGNodeDefaults.style.alignContent) {
|
if (node->style.alignContent != gYGNodeDefaults.style.alignContent) {
|
||||||
YGLog(YGLogLevelDebug, "align-content: %s; ", YGAlignToString(node->style.alignContent));
|
YGLog(node, YGLogLevelDebug, "align-content: %s; ", YGAlignToString(node->style.alignContent));
|
||||||
}
|
}
|
||||||
if (node->style.alignSelf != gYGNodeDefaults.style.alignSelf) {
|
if (node->style.alignSelf != gYGNodeDefaults.style.alignSelf) {
|
||||||
YGLog(YGLogLevelDebug, "align-self: %s; ", YGAlignToString(node->style.alignSelf));
|
YGLog(node, YGLogLevelDebug, "align-self: %s; ", YGAlignToString(node->style.alignSelf));
|
||||||
}
|
}
|
||||||
|
|
||||||
YGPrintNumberIfNotUndefinedf("flex-grow", node->style.flexGrow);
|
YGPrintNumberIfNotUndefinedf(node, "flex-grow", node->style.flexGrow);
|
||||||
YGPrintNumberIfNotUndefinedf("flex-shrink", node->style.flexShrink);
|
YGPrintNumberIfNotUndefinedf(node, "flex-shrink", node->style.flexShrink);
|
||||||
YGPrintNumberIfNotAuto("flex-basis", &node->style.flexBasis);
|
YGPrintNumberIfNotAuto(node, "flex-basis", &node->style.flexBasis);
|
||||||
YGPrintNumberIfNotUndefinedf("flex", node->style.flex);
|
YGPrintNumberIfNotUndefinedf(node, "flex", node->style.flex);
|
||||||
|
|
||||||
if (node->style.flexWrap != gYGNodeDefaults.style.flexWrap) {
|
if (node->style.flexWrap != gYGNodeDefaults.style.flexWrap) {
|
||||||
YGLog(YGLogLevelDebug, "flexWrap: %s; ", YGWrapToString(node->style.flexWrap));
|
YGLog(node, YGLogLevelDebug, "flexWrap: %s; ", YGWrapToString(node->style.flexWrap));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node->style.overflow != gYGNodeDefaults.style.overflow) {
|
if (node->style.overflow != gYGNodeDefaults.style.overflow) {
|
||||||
YGLog(YGLogLevelDebug, "overflow: %s; ", YGOverflowToString(node->style.overflow));
|
YGLog(node, YGLogLevelDebug, "overflow: %s; ", YGOverflowToString(node->style.overflow));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node->style.display != gYGNodeDefaults.style.display) {
|
if (node->style.display != gYGNodeDefaults.style.display) {
|
||||||
YGLog(YGLogLevelDebug, "display: %s; ", YGDisplayToString(node->style.display));
|
YGLog(node, YGLogLevelDebug, "display: %s; ", YGDisplayToString(node->style.display));
|
||||||
}
|
}
|
||||||
|
|
||||||
YGPrintEdges("margin", node->style.margin);
|
YGPrintEdges(node, "margin", node->style.margin);
|
||||||
YGPrintEdges("padding", node->style.padding);
|
YGPrintEdges(node, "padding", node->style.padding);
|
||||||
YGPrintEdges("border", node->style.border);
|
YGPrintEdges(node, "border", node->style.border);
|
||||||
|
|
||||||
YGPrintNumberIfNotAuto("width", &node->style.dimensions[YGDimensionWidth]);
|
YGPrintNumberIfNotAuto(node, "width", &node->style.dimensions[YGDimensionWidth]);
|
||||||
YGPrintNumberIfNotAuto("height", &node->style.dimensions[YGDimensionHeight]);
|
YGPrintNumberIfNotAuto(node, "height", &node->style.dimensions[YGDimensionHeight]);
|
||||||
YGPrintNumberIfNotAuto("max-width", &node->style.maxDimensions[YGDimensionWidth]);
|
YGPrintNumberIfNotAuto(node, "max-width", &node->style.maxDimensions[YGDimensionWidth]);
|
||||||
YGPrintNumberIfNotAuto("max-height", &node->style.maxDimensions[YGDimensionHeight]);
|
YGPrintNumberIfNotAuto(node, "max-height", &node->style.maxDimensions[YGDimensionHeight]);
|
||||||
YGPrintNumberIfNotAuto("min-width", &node->style.minDimensions[YGDimensionWidth]);
|
YGPrintNumberIfNotAuto(node, "min-width", &node->style.minDimensions[YGDimensionWidth]);
|
||||||
YGPrintNumberIfNotAuto("min-height", &node->style.minDimensions[YGDimensionHeight]);
|
YGPrintNumberIfNotAuto(node, "min-height", &node->style.minDimensions[YGDimensionHeight]);
|
||||||
|
|
||||||
if (node->style.positionType != gYGNodeDefaults.style.positionType) {
|
if (node->style.positionType != gYGNodeDefaults.style.positionType) {
|
||||||
YGLog(YGLogLevelDebug, "position: %s; ", YGPositionTypeToString(node->style.positionType));
|
YGLog(node,
|
||||||
|
YGLogLevelDebug,
|
||||||
|
"position: %s; ",
|
||||||
|
YGPositionTypeToString(node->style.positionType));
|
||||||
}
|
}
|
||||||
|
|
||||||
YGPrintEdgeIfNotUndefined("left", node->style.position, YGEdgeLeft);
|
YGPrintEdgeIfNotUndefined(node, "left", node->style.position, YGEdgeLeft);
|
||||||
YGPrintEdgeIfNotUndefined("right", node->style.position, YGEdgeRight);
|
YGPrintEdgeIfNotUndefined(node, "right", node->style.position, YGEdgeRight);
|
||||||
YGPrintEdgeIfNotUndefined("top", node->style.position, YGEdgeTop);
|
YGPrintEdgeIfNotUndefined(node, "top", node->style.position, YGEdgeTop);
|
||||||
YGPrintEdgeIfNotUndefined("bottom", node->style.position, YGEdgeBottom);
|
YGPrintEdgeIfNotUndefined(node, "bottom", node->style.position, YGEdgeBottom);
|
||||||
YGLog(YGLogLevelDebug, "\" ");
|
YGLog(node, YGLogLevelDebug, "\" ");
|
||||||
|
|
||||||
if (node->measure != NULL) {
|
if (node->measure != NULL) {
|
||||||
YGLog(YGLogLevelDebug, "has-custom-measure=\"true\"");
|
YGLog(node, YGLogLevelDebug, "has-custom-measure=\"true\"");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
YGLog(YGLogLevelDebug, ">");
|
YGLog(node, YGLogLevelDebug, ">");
|
||||||
|
|
||||||
const uint32_t childCount = YGNodeListCount(node->children);
|
const uint32_t childCount = YGNodeListCount(node->children);
|
||||||
if (options & YGPrintOptionsChildren && childCount > 0) {
|
if (options & YGPrintOptionsChildren && childCount > 0) {
|
||||||
for (uint32_t i = 0; i < childCount; i++) {
|
for (uint32_t i = 0; i < childCount; i++) {
|
||||||
YGLog(YGLogLevelDebug, "\n");
|
YGLog(node, YGLogLevelDebug, "\n");
|
||||||
YGNodePrintInternal(YGNodeGetChild(node, i), options, level + 1);
|
YGNodePrintInternal(YGNodeGetChild(node, i), options, level + 1);
|
||||||
}
|
}
|
||||||
YGIndent(level);
|
YGIndent(node, level);
|
||||||
YGLog(YGLogLevelDebug, "\n");
|
YGLog(node, YGLogLevelDebug, "\n");
|
||||||
}
|
}
|
||||||
YGLog(YGLogLevelDebug, "</div>");
|
YGLog(node, YGLogLevelDebug, "</div>");
|
||||||
}
|
}
|
||||||
|
|
||||||
void YGNodePrint(const YGNodeRef node, const YGPrintOptions options) {
|
void YGNodePrint(const YGNodeRef node, const YGPrintOptions options) {
|
||||||
@@ -1076,7 +1135,9 @@ static float YGBaseline(const YGNodeRef node) {
|
|||||||
const float baseline = node->baseline(node,
|
const float baseline = node->baseline(node,
|
||||||
node->layout.measuredDimensions[YGDimensionWidth],
|
node->layout.measuredDimensions[YGDimensionWidth],
|
||||||
node->layout.measuredDimensions[YGDimensionHeight]);
|
node->layout.measuredDimensions[YGDimensionHeight]);
|
||||||
YG_ASSERT(!YGFloatIsUndefined(baseline), "Expect custom baseline function to not return NaN")
|
YGAssertWithNode(node,
|
||||||
|
!YGFloatIsUndefined(baseline),
|
||||||
|
"Expect custom baseline function to not return NaN");
|
||||||
return baseline;
|
return baseline;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1459,8 +1520,12 @@ static void YGNodeComputeFlexBasisForChild(const YGNodeRef node,
|
|||||||
|
|
||||||
YGConstrainMaxSizeForMode(
|
YGConstrainMaxSizeForMode(
|
||||||
child, YGFlexDirectionRow, parentWidth, parentWidth, &childWidthMeasureMode, &childWidth);
|
child, YGFlexDirectionRow, parentWidth, parentWidth, &childWidthMeasureMode, &childWidth);
|
||||||
YGConstrainMaxSizeForMode(
|
YGConstrainMaxSizeForMode(child,
|
||||||
child, YGFlexDirectionColumn, parentHeight, parentWidth, &childHeightMeasureMode, &childHeight);
|
YGFlexDirectionColumn,
|
||||||
|
parentHeight,
|
||||||
|
parentWidth,
|
||||||
|
&childHeightMeasureMode,
|
||||||
|
&childHeight);
|
||||||
|
|
||||||
// Measure the child
|
// Measure the child
|
||||||
YGLayoutNodeInternal(child,
|
YGLayoutNodeInternal(child,
|
||||||
@@ -1640,7 +1705,7 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions(const YGNodeRef node,
|
|||||||
const YGMeasureMode heightMeasureMode,
|
const YGMeasureMode heightMeasureMode,
|
||||||
const float parentWidth,
|
const float parentWidth,
|
||||||
const float parentHeight) {
|
const float parentHeight) {
|
||||||
YG_ASSERT(node->measure, "Expected node to have custom measure function");
|
YGAssertWithNode(node, node->measure != NULL, "Expected node to have custom measure function");
|
||||||
|
|
||||||
const float paddingAndBorderAxisRow =
|
const float paddingAndBorderAxisRow =
|
||||||
YGNodePaddingAndBorderForAxis(node, YGFlexDirectionRow, availableWidth);
|
YGNodePaddingAndBorderForAxis(node, YGFlexDirectionRow, availableWidth);
|
||||||
@@ -1876,11 +1941,12 @@ static void YGNodelayoutImpl(const YGNodeRef node,
|
|||||||
const float parentHeight,
|
const float parentHeight,
|
||||||
const bool performLayout,
|
const bool performLayout,
|
||||||
const YGConfigRef config) {
|
const YGConfigRef config) {
|
||||||
YG_ASSERT(YGFloatIsUndefined(availableWidth) ? widthMeasureMode == YGMeasureModeUndefined : true,
|
YGAssertWithNode(node,
|
||||||
|
YGFloatIsUndefined(availableWidth) ? widthMeasureMode == YGMeasureModeUndefined : true,
|
||||||
"availableWidth is indefinite so widthMeasureMode must be "
|
"availableWidth is indefinite so widthMeasureMode must be "
|
||||||
"YGMeasureModeUndefined");
|
"YGMeasureModeUndefined");
|
||||||
YG_ASSERT(YGFloatIsUndefined(availableHeight) ? heightMeasureMode == YGMeasureModeUndefined
|
YGAssertWithNode(node,
|
||||||
: true,
|
YGFloatIsUndefined(availableHeight) ? heightMeasureMode == YGMeasureModeUndefined : true,
|
||||||
"availableHeight is indefinite so heightMeasureMode must be "
|
"availableHeight is indefinite so heightMeasureMode must be "
|
||||||
"YGMeasureModeUndefined");
|
"YGMeasureModeUndefined");
|
||||||
|
|
||||||
@@ -2203,10 +2269,12 @@ static void YGNodelayoutImpl(const YGNodeRef node,
|
|||||||
if (measureModeMainDim != YGMeasureModeExactly) {
|
if (measureModeMainDim != YGMeasureModeExactly) {
|
||||||
if (!YGFloatIsUndefined(minInnerMainDim) && sizeConsumedOnCurrentLine < minInnerMainDim) {
|
if (!YGFloatIsUndefined(minInnerMainDim) && sizeConsumedOnCurrentLine < minInnerMainDim) {
|
||||||
availableInnerMainDim = minInnerMainDim;
|
availableInnerMainDim = minInnerMainDim;
|
||||||
} else if (!YGFloatIsUndefined(maxInnerMainDim) && sizeConsumedOnCurrentLine > maxInnerMainDim) {
|
} else if (!YGFloatIsUndefined(maxInnerMainDim) &&
|
||||||
|
sizeConsumedOnCurrentLine > maxInnerMainDim) {
|
||||||
availableInnerMainDim = maxInnerMainDim;
|
availableInnerMainDim = maxInnerMainDim;
|
||||||
} else {
|
} else {
|
||||||
if (!node->config->useLegacyStretchBehaviour && (totalFlexGrowFactors == 0 || YGResolveFlexGrow(node) == 0)) {
|
if (!node->config->useLegacyStretchBehaviour &&
|
||||||
|
(totalFlexGrowFactors == 0 || YGResolveFlexGrow(node) == 0)) {
|
||||||
// If we don't have any children to flex or we can't flex the node itself,
|
// If we don't have any children to flex or we can't flex the node itself,
|
||||||
// space we've used is all space we need
|
// space we've used is all space we need
|
||||||
availableInnerMainDim = sizeConsumedOnCurrentLine;
|
availableInnerMainDim = sizeConsumedOnCurrentLine;
|
||||||
@@ -2218,7 +2286,8 @@ static void YGNodelayoutImpl(const YGNodeRef node,
|
|||||||
if (!YGFloatIsUndefined(availableInnerMainDim)) {
|
if (!YGFloatIsUndefined(availableInnerMainDim)) {
|
||||||
remainingFreeSpace = availableInnerMainDim - sizeConsumedOnCurrentLine;
|
remainingFreeSpace = availableInnerMainDim - sizeConsumedOnCurrentLine;
|
||||||
} else if (sizeConsumedOnCurrentLine < 0) {
|
} else if (sizeConsumedOnCurrentLine < 0) {
|
||||||
// availableInnerMainDim is indefinite which means the node is being sized based on its content.
|
// availableInnerMainDim is indefinite which means the node is being sized based on its
|
||||||
|
// content.
|
||||||
// sizeConsumedOnCurrentLine is negative which means the node will allocate 0 points for
|
// sizeConsumedOnCurrentLine is negative which means the node will allocate 0 points for
|
||||||
// its content. Consequently, remainingFreeSpace is 0 - sizeConsumedOnCurrentLine.
|
// its content. Consequently, remainingFreeSpace is 0 - sizeConsumedOnCurrentLine.
|
||||||
remainingFreeSpace = -sizeConsumedOnCurrentLine;
|
remainingFreeSpace = -sizeConsumedOnCurrentLine;
|
||||||
@@ -3281,7 +3350,8 @@ bool YGLayoutNodeInternal(const YGNodeRef node,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void YGConfigSetPointScaleFactor(const YGConfigRef config, const float pixelsInPoint) {
|
void YGConfigSetPointScaleFactor(const YGConfigRef config, const float pixelsInPoint) {
|
||||||
YG_ASSERT(pixelsInPoint >= 0.0f, "Scale factor should not be less than zero");
|
YGAssertWithConfig(config, pixelsInPoint >= 0.0f, "Scale factor should not be less than zero");
|
||||||
|
|
||||||
// We store points for Pixel as we will use it for rounding
|
// We store points for Pixel as we will use it for rounding
|
||||||
if (pixelsInPoint == 0.0f) {
|
if (pixelsInPoint == 0.0f) {
|
||||||
// Zero is used to skip rounding
|
// Zero is used to skip rounding
|
||||||
@@ -3291,7 +3361,10 @@ void YGConfigSetPointScaleFactor(const YGConfigRef config, const float pixelsInP
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static float YGRoundValueToPixelGrid(const float value, const float pointScaleFactor, const bool forceCeil, const bool forceFloor) {
|
static float YGRoundValueToPixelGrid(const float value,
|
||||||
|
const float pointScaleFactor,
|
||||||
|
const bool forceCeil,
|
||||||
|
const bool forceFloor) {
|
||||||
float fractial = fmodf(value, pointScaleFactor);
|
float fractial = fmodf(value, pointScaleFactor);
|
||||||
if (YGFloatsEqual(fractial, 0)) {
|
if (YGFloatsEqual(fractial, 0)) {
|
||||||
// Still remove fractial as fractial could be extremely small.
|
// Still remove fractial as fractial could be extremely small.
|
||||||
@@ -3307,7 +3380,10 @@ static float YGRoundValueToPixelGrid(const float value, const float pointScaleFa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void YGRoundToPixelGrid(const YGNodeRef node, const float pointScaleFactor, const float absoluteLeft, const float absoluteTop) {
|
static void YGRoundToPixelGrid(const YGNodeRef node,
|
||||||
|
const float pointScaleFactor,
|
||||||
|
const float absoluteLeft,
|
||||||
|
const float absoluteTop) {
|
||||||
if (pointScaleFactor == 0.0f) {
|
if (pointScaleFactor == 0.0f) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -3328,13 +3404,17 @@ static void YGRoundToPixelGrid(const YGNodeRef node, const float pointScaleFacto
|
|||||||
// lead to unwanted text truncation.
|
// lead to unwanted text truncation.
|
||||||
const bool hasMeasure = node->measure != NULL;
|
const bool hasMeasure = node->measure != NULL;
|
||||||
|
|
||||||
node->layout.position[YGEdgeLeft] = YGRoundValueToPixelGrid(nodeLeft, pointScaleFactor, false, hasMeasure);
|
node->layout.position[YGEdgeLeft] =
|
||||||
node->layout.position[YGEdgeTop] = YGRoundValueToPixelGrid(nodeTop, pointScaleFactor, false, hasMeasure);
|
YGRoundValueToPixelGrid(nodeLeft, pointScaleFactor, false, hasMeasure);
|
||||||
|
node->layout.position[YGEdgeTop] =
|
||||||
|
YGRoundValueToPixelGrid(nodeTop, pointScaleFactor, false, hasMeasure);
|
||||||
|
|
||||||
node->layout.dimensions[YGDimensionWidth] =
|
node->layout.dimensions[YGDimensionWidth] =
|
||||||
YGRoundValueToPixelGrid(absoluteNodeRight, pointScaleFactor, hasMeasure, false) - YGRoundValueToPixelGrid(absoluteNodeLeft, pointScaleFactor, false, hasMeasure);
|
YGRoundValueToPixelGrid(absoluteNodeRight, pointScaleFactor, hasMeasure, false) -
|
||||||
|
YGRoundValueToPixelGrid(absoluteNodeLeft, pointScaleFactor, false, hasMeasure);
|
||||||
node->layout.dimensions[YGDimensionHeight] =
|
node->layout.dimensions[YGDimensionHeight] =
|
||||||
YGRoundValueToPixelGrid(absoluteNodeBottom, pointScaleFactor, hasMeasure, false) - YGRoundValueToPixelGrid(absoluteNodeTop, pointScaleFactor, false, hasMeasure);
|
YGRoundValueToPixelGrid(absoluteNodeBottom, pointScaleFactor, hasMeasure, false) -
|
||||||
|
YGRoundValueToPixelGrid(absoluteNodeTop, pointScaleFactor, false, hasMeasure);
|
||||||
|
|
||||||
const uint32_t childCount = YGNodeListCount(node->children);
|
const uint32_t childCount = YGNodeListCount(node->children);
|
||||||
for (uint32_t i = 0; i < childCount; i++) {
|
for (uint32_t i = 0; i < childCount; i++) {
|
||||||
@@ -3375,8 +3455,7 @@ void YGNodeCalculateLayout(const YGNodeRef node,
|
|||||||
height = YGResolveValue(node->resolvedDimensions[dim[YGFlexDirectionColumn]], parentHeight) +
|
height = YGResolveValue(node->resolvedDimensions[dim[YGFlexDirectionColumn]], parentHeight) +
|
||||||
YGNodeMarginForAxis(node, YGFlexDirectionColumn, parentWidth);
|
YGNodeMarginForAxis(node, YGFlexDirectionColumn, parentWidth);
|
||||||
heightMeasureMode = YGMeasureModeExactly;
|
heightMeasureMode = YGMeasureModeExactly;
|
||||||
} else if (YGResolveValue(&node->style.maxDimensions[YGDimensionHeight], parentHeight) >=
|
} else if (YGResolveValue(&node->style.maxDimensions[YGDimensionHeight], parentHeight) >= 0.0f) {
|
||||||
0.0f) {
|
|
||||||
height = YGResolveValue(&node->style.maxDimensions[YGDimensionHeight], parentHeight);
|
height = YGResolveValue(&node->style.maxDimensions[YGDimensionHeight], parentHeight);
|
||||||
heightMeasureMode = YGMeasureModeAtMost;
|
heightMeasureMode = YGMeasureModeAtMost;
|
||||||
} else {
|
} else {
|
||||||
@@ -3404,25 +3483,63 @@ void YGNodeCalculateLayout(const YGNodeRef node,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void YGSetLogger(YGLogger logger) {
|
void YGConfigSetLogger(const YGConfigRef config, YGLogger logger) {
|
||||||
if (logger != NULL) {
|
if (logger != NULL) {
|
||||||
gLogger = logger;
|
config->logger = logger;
|
||||||
} else {
|
} else {
|
||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
gLogger = &YGAndroidLog;
|
config->logger = &YGAndroidLog;
|
||||||
#else
|
#else
|
||||||
gLogger = &YGDefaultLog;
|
config->logger = &YGDefaultLog;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void YGLog(YGLogLevel level, const char *format, ...) {
|
static void YGVLog(const YGConfigRef config,
|
||||||
|
const YGNodeRef node,
|
||||||
|
YGLogLevel level,
|
||||||
|
const char *format,
|
||||||
|
va_list args) {
|
||||||
|
const YGConfigRef logConfig = config != NULL ? config : &gYGConfigDefaults;
|
||||||
|
logConfig->logger(logConfig, node, level, format, args);
|
||||||
|
|
||||||
|
if (level == YGLogLevelFatal) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void YGLogWithConfig(const YGConfigRef config, YGLogLevel level, const char *format, ...) {
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
gLogger(level, format, args);
|
YGVLog(config, NULL, level, format, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void YGLog(const YGNodeRef node, YGLogLevel level, const char *format, ...) {
|
||||||
|
va_list args;
|
||||||
|
va_start(args, format);
|
||||||
|
YGVLog(node == NULL ? NULL : node->config, node, level, format, args);
|
||||||
|
va_end(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
void YGAssert(const bool condition, const char *message) {
|
||||||
|
if (!condition) {
|
||||||
|
YGLog(NULL, YGLogLevelFatal, "%s\n", message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void YGAssertWithNode(const YGNodeRef node, const bool condition, const char *message) {
|
||||||
|
if (!condition) {
|
||||||
|
YGLog(node, YGLogLevelFatal, "%s\n", message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void YGAssertWithConfig(const YGConfigRef config, const bool condition, const char *message) {
|
||||||
|
if (!condition) {
|
||||||
|
YGLogWithConfig(config, YGLogLevelFatal, "%s\n", message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void YGConfigSetExperimentalFeatureEnabled(const YGConfigRef config,
|
void YGConfigSetExperimentalFeatureEnabled(const YGConfigRef config,
|
||||||
const YGExperimentalFeature feature,
|
const YGExperimentalFeature feature,
|
||||||
const bool enabled) {
|
const bool enabled) {
|
||||||
@@ -3438,7 +3555,8 @@ void YGConfigSetUseWebDefaults(const YGConfigRef config, const bool enabled) {
|
|||||||
config->useWebDefaults = enabled;
|
config->useWebDefaults = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
void YGConfigSetUseLegacyStretchBehaviour(const YGConfigRef config, const bool useLegacyStretchBehaviour) {
|
void YGConfigSetUseLegacyStretchBehaviour(const YGConfigRef config,
|
||||||
|
const bool useLegacyStretchBehaviour) {
|
||||||
config->useLegacyStretchBehaviour = useLegacyStretchBehaviour;
|
config->useLegacyStretchBehaviour = useLegacyStretchBehaviour;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3446,10 +3564,18 @@ bool YGConfigGetUseWebDefaults(const YGConfigRef config) {
|
|||||||
return config->useWebDefaults;
|
return config->useWebDefaults;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void YGConfigSetContext(const YGConfigRef config, void *context) {
|
||||||
|
config->context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *YGConfigGetContext(const YGConfigRef config) {
|
||||||
|
return config->context;
|
||||||
|
}
|
||||||
|
|
||||||
void YGSetMemoryFuncs(YGMalloc ygmalloc, YGCalloc yccalloc, YGRealloc ygrealloc, YGFree ygfree) {
|
void YGSetMemoryFuncs(YGMalloc ygmalloc, YGCalloc yccalloc, YGRealloc ygrealloc, YGFree ygfree) {
|
||||||
YG_ASSERT(gNodeInstanceCount == 0 && gConfigInstanceCount == 0,
|
YGAssert(gNodeInstanceCount == 0 && gConfigInstanceCount == 0,
|
||||||
"Cannot set memory functions: all node must be freed first");
|
"Cannot set memory functions: all node must be freed first");
|
||||||
YG_ASSERT((ygmalloc == NULL && yccalloc == NULL && ygrealloc == NULL && ygfree == NULL) ||
|
YGAssert((ygmalloc == NULL && yccalloc == NULL && ygrealloc == NULL && ygfree == NULL) ||
|
||||||
(ygmalloc != NULL && yccalloc != NULL && ygrealloc != NULL && ygfree != NULL),
|
(ygmalloc != NULL && yccalloc != NULL && ygrealloc != NULL && ygfree != NULL),
|
||||||
"Cannot set memory functions: functions must be all NULL or Non-NULL");
|
"Cannot set memory functions: functions must be all NULL or Non-NULL");
|
||||||
|
|
||||||
|
35
yoga/Yoga.h
35
yoga/Yoga.h
@@ -55,7 +55,11 @@ typedef YGSize (*YGMeasureFunc)(YGNodeRef node,
|
|||||||
YGMeasureMode heightMode);
|
YGMeasureMode heightMode);
|
||||||
typedef float (*YGBaselineFunc)(YGNodeRef node, const float width, const float height);
|
typedef float (*YGBaselineFunc)(YGNodeRef node, const float width, const float height);
|
||||||
typedef void (*YGPrintFunc)(YGNodeRef node);
|
typedef void (*YGPrintFunc)(YGNodeRef node);
|
||||||
typedef int (*YGLogger)(YGLogLevel level, const char *format, va_list args);
|
typedef int (*YGLogger)(const YGConfigRef config,
|
||||||
|
const YGNodeRef node,
|
||||||
|
YGLogLevel level,
|
||||||
|
const char *format,
|
||||||
|
va_list args);
|
||||||
|
|
||||||
typedef void *(*YGMalloc)(size_t size);
|
typedef void *(*YGMalloc)(size_t size);
|
||||||
typedef void *(*YGCalloc)(size_t count, size_t size);
|
typedef void *(*YGCalloc)(size_t count, size_t size);
|
||||||
@@ -218,17 +222,27 @@ YG_NODE_LAYOUT_EDGE_PROPERTY(float, Margin);
|
|||||||
YG_NODE_LAYOUT_EDGE_PROPERTY(float, Border);
|
YG_NODE_LAYOUT_EDGE_PROPERTY(float, Border);
|
||||||
YG_NODE_LAYOUT_EDGE_PROPERTY(float, Padding);
|
YG_NODE_LAYOUT_EDGE_PROPERTY(float, Padding);
|
||||||
|
|
||||||
WIN_EXPORT void YGSetLogger(YGLogger logger);
|
WIN_EXPORT void YGConfigSetLogger(const YGConfigRef config, YGLogger logger);
|
||||||
WIN_EXPORT void YGLog(YGLogLevel level, const char *message, ...);
|
WIN_EXPORT void YGLog(const YGNodeRef node, YGLogLevel level, const char *message, ...);
|
||||||
|
WIN_EXPORT void YGLogWithConfig(const YGConfigRef config, YGLogLevel level, const char *format, ...);
|
||||||
|
WIN_EXPORT void YGAssert(const bool condition, const char *message);
|
||||||
|
WIN_EXPORT void YGAssertWithNode(const YGNodeRef node, const bool condition, const char *message);
|
||||||
|
WIN_EXPORT void YGAssertWithConfig(const YGConfigRef config,
|
||||||
|
const bool condition,
|
||||||
|
const char *message);
|
||||||
|
|
||||||
// Set this to number of pixels in 1 point to round calculation results
|
// Set this to number of pixels in 1 point to round calculation results
|
||||||
// If you want to avoid rounding - set PointScaleFactor to 0
|
// If you want to avoid rounding - set PointScaleFactor to 0
|
||||||
WIN_EXPORT void YGConfigSetPointScaleFactor(const YGConfigRef config, const float pixelsInPoint);
|
WIN_EXPORT void YGConfigSetPointScaleFactor(const YGConfigRef config, const float pixelsInPoint);
|
||||||
|
|
||||||
// Yoga previously had an error where containers would take the maximum space possible instead of the minimum
|
// Yoga previously had an error where containers would take the maximum space possible instead of
|
||||||
// like they are supposed to. In practice this resulted in implicit behaviour similar to align-self: stretch;
|
// the minimum
|
||||||
// Because this was such a long-standing bug we must allow legacy users to switch back to this behaviour.
|
// like they are supposed to. In practice this resulted in implicit behaviour similar to align-self:
|
||||||
WIN_EXPORT void YGConfigSetUseLegacyStretchBehaviour(const YGConfigRef config, const bool useLegacyStretchBehaviour);
|
// stretch;
|
||||||
|
// Because this was such a long-standing bug we must allow legacy users to switch back to this
|
||||||
|
// behaviour.
|
||||||
|
WIN_EXPORT void YGConfigSetUseLegacyStretchBehaviour(const YGConfigRef config,
|
||||||
|
const bool useLegacyStretchBehaviour);
|
||||||
|
|
||||||
// YGConfig
|
// YGConfig
|
||||||
WIN_EXPORT YGConfigRef YGConfigNew(void);
|
WIN_EXPORT YGConfigRef YGConfigNew(void);
|
||||||
@@ -245,9 +259,14 @@ WIN_EXPORT bool YGConfigIsExperimentalFeatureEnabled(const YGConfigRef config,
|
|||||||
// Using the web defaults is the prefered configuration for new projects.
|
// Using the web defaults is the prefered configuration for new projects.
|
||||||
// Usage of non web defaults should be considered as legacy.
|
// Usage of non web defaults should be considered as legacy.
|
||||||
WIN_EXPORT void YGConfigSetUseWebDefaults(const YGConfigRef config, const bool enabled);
|
WIN_EXPORT void YGConfigSetUseWebDefaults(const YGConfigRef config, const bool enabled);
|
||||||
|
|
||||||
WIN_EXPORT bool YGConfigGetUseWebDefaults(const YGConfigRef config);
|
WIN_EXPORT bool YGConfigGetUseWebDefaults(const YGConfigRef config);
|
||||||
|
|
||||||
|
// Export only for C#
|
||||||
|
WIN_EXPORT YGConfigRef YGConfigGetDefault(void);
|
||||||
|
|
||||||
|
WIN_EXPORT void YGConfigSetContext(const YGConfigRef config, void *context);
|
||||||
|
WIN_EXPORT void *YGConfigGetContext(const YGConfigRef config);
|
||||||
|
|
||||||
WIN_EXPORT void
|
WIN_EXPORT void
|
||||||
YGSetMemoryFuncs(YGMalloc ygmalloc, YGCalloc yccalloc, YGRealloc ygrealloc, YGFree ygfree);
|
YGSetMemoryFuncs(YGMalloc ygmalloc, YGCalloc yccalloc, YGRealloc ygrealloc, YGFree ygfree);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user