Skip to content

Commit

Permalink
Merge pull request #1 from brezza92/b_dev_flexbox
Browse files Browse the repository at this point in the history
B dev flexbox
  • Loading branch information
brezza92 authored Mar 30, 2020
2 parents 1c626f6 + 89a2429 commit ac5412d
Show file tree
Hide file tree
Showing 39 changed files with 6,266 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Marius.Yoga/Extension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace System.Runtime.CompilerServices
{
public class ExtensionAttribute : Attribute { }
}
83 changes: 83 additions & 0 deletions src/Marius.Yoga/Marius.Yoga.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{9060957D-FF0B-4B14-BB87-EE24B5170365}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Marius.Yoga</RootNamespace>
<AssemblyName>Marius.Yoga</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Extension.cs" />
<Compile Include="YogaArray.cs" />
<Compile Include="YogaCachedMeasurement.cs" />
<Compile Include="YogaCollectFlexItemsRowValues.cs" />
<Compile Include="YogaConfig.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="YogaDelegates.cs" />
<Compile Include="YogaLayout.cs" />
<Compile Include="YogaMath.cs" />
<Compile Include="YogaNode.Layout.cs" />
<Compile Include="YogaNode.cs" />
<Compile Include="YogaNode.Public.cs" />
<Compile Include="YogaNode.Spacing.cs" />
<Compile Include="YogaSize.cs" />
<Compile Include="YogaStyle.cs" />
<Compile Include="YogaValue.cs" />
<Compile Include="YogaAlign.cs" />
<Compile Include="YogaDimension.cs" />
<Compile Include="YogaDirection.cs" />
<Compile Include="YogaDisplay.cs" />
<Compile Include="YogaEdge.cs" />
<Compile Include="YogaExperimentalFeature.cs" />
<Compile Include="YogaFlexDirection.cs" />
<Compile Include="YogaJustify.cs" />
<Compile Include="YogaMeasureMode.cs" />
<Compile Include="YogaNodeType.cs" />
<Compile Include="YogaOverflow.cs" />
<Compile Include="YogaPositionType.cs" />
<Compile Include="YogaPrintOptions.cs" />
<Compile Include="YogaUnit.cs" />
<Compile Include="YogaExtensions.cs" />
<Compile Include="YogaWrap.cs" />
</ItemGroup>
<ItemGroup>
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
36 changes: 36 additions & 0 deletions src/Marius.Yoga/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Marius.Layout")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Marius.Layout")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("9060957d-ff0b-4b14-bb87-ee24b5170365")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
22 changes: 22 additions & 0 deletions src/Marius.Yoga/YogaAlign.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* Copyright (c) 2018-present, Marius Klimantavičius
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

namespace Marius.Yoga
{
public enum YogaAlign
{
Auto,
FlexStart,
Center,
FlexEnd,
Stretch,
Baseline,
SpaceBetween,
SpaceAround,
}
}
133 changes: 133 additions & 0 deletions src/Marius.Yoga/YogaArray.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* Copyright (c) 2018-present, Marius Klimantavičius
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

using System;

namespace Marius.Yoga
{
public static class YogaArray
{
public static YogaArray<T> From<T>(T[] other)
{
var result = new T[other.Length];
for (var i = 0; i < result.Length; i++)
result[i] = other[i];
return new YogaArray<T>(result);
}

public static YogaArray<T> From<T>(YogaArray<T> other)
{
var result = new T[other.Length];
for (var i = 0; i < result.Length; i++)
result[i] = other[i];
return new YogaArray<T>(result);
}

public static bool Equal(YogaArray<float> val1, YogaArray<float> val2)
{
var areEqual = true;
for (var i = 0; i < val1.Length && areEqual; ++i)
areEqual = FloatsEqual(val1[i], val2[i]);

return areEqual;
}

public static bool Equal(YogaArray<float?> val1, YogaArray<float?> val2)
{
var areEqual = true;
for (var i = 0; i < val1.Length && areEqual; ++i)
areEqual = FloatsEqual(val1[i], val2[i]);

return areEqual;
}

public static bool Equal(YogaArray<YogaValue> val1, YogaArray<YogaValue> val2)
{
var areEqual = true;
for (var i = 0; i < val1.Length && areEqual; ++i)
areEqual = val1[i].Equals(val2[i]);

return areEqual;
}

private static bool FloatsEqual(float? a, float? b)
{
if (a != null && b != null)
return Math.Abs(a.Value - b.Value) < 0.0001f;

return a == null && b == null;
}
}

public class YogaArray<T>
{
private readonly T[] _array;

public T this[int index]
{
get { return _array[index]; }
set { _array[index] = value; }
}

public T this[YogaEdge index]
{
get { return _array[(int)index]; }
set { _array[(int)index] = value; }
}

public T this[YogaFlexDirection index]
{
get { return _array[(int)index]; }
set { _array[(int)index] = value; }
}

public T this[YogaDimension index]
{
get { return _array[(int)index]; }
set { _array[(int)index] = value; }
}

public int Length
{
get { return _array.Length; }
}

public YogaArray(int length)
{
_array = new T[length];
}

public YogaArray(params T[] values)
{
_array = values;
}

public void CopyFrom(YogaArray<T> from)
{
from._array.CopyTo(_array, 0);
}

public void Clear()
{
for (var i = 0; i < _array.Length; i++)
_array[i] = default(T);
}

public override int GetHashCode()
{
if (_array == null)
return 0;

var hashCode = 0;
for (var i = 0; i < _array.Length; i++)
hashCode = (hashCode << 5) ^ _array[i].GetHashCode();

return hashCode;
}
}
}
93 changes: 93 additions & 0 deletions src/Marius.Yoga/YogaCachedMeasurement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* Copyright (c) 2018-present, Marius Klimantavičius
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

using System;

namespace Marius.Yoga
{
public sealed class YogaCachedMeasurement
{
public float? AvailableWidth;
public float? AvailableHeight;
public YogaMeasureMode WidthMeasureMode;
public YogaMeasureMode HeightMeasureMode;

public float? ComputedWidth;
public float? ComputedHeight;

public YogaCachedMeasurement()
{
AvailableWidth = 0;
AvailableHeight = 0;
WidthMeasureMode = (YogaMeasureMode)(-1);
HeightMeasureMode = (YogaMeasureMode)(-1);
ComputedWidth = -1;
ComputedHeight = -1;
}

public static bool operator ==(YogaCachedMeasurement self, YogaCachedMeasurement measurement)
{
if (object.ReferenceEquals(self, measurement))
return true;

if (object.ReferenceEquals(self, null) || object.ReferenceEquals(measurement, null))
return false;

var isEqual = self.WidthMeasureMode == measurement.WidthMeasureMode && self.HeightMeasureMode == measurement.HeightMeasureMode;

isEqual = isEqual && self.AvailableWidth == measurement.AvailableWidth;
isEqual = isEqual && self.AvailableHeight == measurement.AvailableHeight;
isEqual = isEqual && self.ComputedWidth == measurement.ComputedWidth;
isEqual = isEqual && self.ComputedHeight == measurement.ComputedHeight;

return isEqual;
}

public static bool operator !=(YogaCachedMeasurement self, YogaCachedMeasurement measurement)
{
return !(self == measurement);
}

public void CopyFrom(YogaCachedMeasurement other)
{
AvailableWidth = other.AvailableWidth;
AvailableHeight = other.AvailableHeight;
WidthMeasureMode = other.WidthMeasureMode;
HeightMeasureMode = other.HeightMeasureMode;
ComputedWidth = other.ComputedWidth;
ComputedHeight = other.ComputedHeight;
}

public void Clear()
{
AvailableWidth = 0;
AvailableHeight = 0;
WidthMeasureMode = (YogaMeasureMode)(-1);
HeightMeasureMode = (YogaMeasureMode)(-1);
ComputedWidth = -1;
ComputedHeight = -1;
}

public override bool Equals(object obj)
{
var other = obj as YogaCachedMeasurement;
return other == this;
}

public override int GetHashCode()
{
return AvailableWidth.GetHashCode() +
AvailableHeight.GetHashCode() +
WidthMeasureMode.GetHashCode() +
HeightMeasureMode.GetHashCode() +
ComputedWidth.GetHashCode() +
ComputedHeight.GetHashCode();

}
};
}
Loading

0 comments on commit ac5412d

Please sign in to comment.