Skip to content

Instantly share code, notes, and snippets.

@mattpodwysocki
Created September 6, 2016 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattpodwysocki/0b52d3394e1a895dd612b6ca00db03d8 to your computer and use it in GitHub Desktop.
Save mattpodwysocki/0b52d3394e1a895dd612b6ca00db03d8 to your computer and use it in GitHub Desktop.
using System;
namespace CSSLayoutApp
{
public class CSSNode : IDisposable
{
private bool _isDisposed;
private readonly IntPtr _cssNode;
public CSSNode()
{
_cssNode = Native.CSSNodeNew();
Native.CSSNodeInit(_cssNode);
}
public CSSNode(IntPtr cssNode)
{
_cssNode = cssNode;
}
private void CheckDisposed()
{
if (_isDisposed)
{
throw new ObjectDisposedException("CSSNode");
}
}
public void Dispose()
{
if (!_isDisposed)
{
_isDisposed = true;
Native.CSSNodeFree(_cssNode);
}
}
public CSSNode this[int index]
{
get
{
CheckDisposed();
var ptr = Native.CSSNodeGetChild(_cssNode, (uint)index);
return new CSSNode(ptr);
}
}
public int Count
{
get
{
CheckDisposed();
return (int)Native.CSSNodeChildCount(_cssNode);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment