1
This commit is contained in:
52
Src/Unity/Scripts/UX/Library/CellContainer.cs
Normal file
52
Src/Unity/Scripts/UX/Library/CellContainer.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public class CellContainer : VisualElement
|
||||
{
|
||||
public new class UxmlFactory : UxmlFactory<CellContainer, UxmlTraits> { }
|
||||
|
||||
public int CellSize { get; set; } = 64;
|
||||
public CellContainer()
|
||||
{
|
||||
|
||||
RegisterCallback<CustomStyleResolvedEvent>(x =>
|
||||
{
|
||||
MarkDirtyRepaint();
|
||||
});
|
||||
generateVisualContent += GenerateVisualContent;
|
||||
}
|
||||
|
||||
private void GenerateVisualContent(MeshGenerationContext obj)
|
||||
{
|
||||
if(contentRect.height<=0 || contentRect.width<=0)return;
|
||||
|
||||
var painter = obj.painter2D;
|
||||
|
||||
painter.lineWidth = resolvedStyle.borderTopWidth;
|
||||
painter.strokeColor = resolvedStyle.borderTopColor;
|
||||
|
||||
var yCount = contentRect.height / CellSize;
|
||||
var xCount = contentRect.width / CellSize;
|
||||
|
||||
for (var x = 1; x < xCount; x++)
|
||||
{
|
||||
painter.BeginPath();
|
||||
painter.MoveTo(new Vector2(x * CellSize, 0));
|
||||
painter.LineTo(new Vector2(x * CellSize, contentRect.height));
|
||||
painter.Stroke();
|
||||
}
|
||||
for (var y = 1; y < yCount; y++)
|
||||
{
|
||||
painter.BeginPath();
|
||||
painter.MoveTo(new Vector2(0, y * CellSize));
|
||||
painter.LineTo(new Vector2(contentRect.width, y * CellSize));
|
||||
painter.Stroke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user