https://github.com/paulnonatomic/uielementtable
A Unity UIElement based Table
https://github.com/paulnonatomic/uielementtable
Last synced: about 1 year ago
JSON representation
A Unity UIElement based Table
- Host: GitHub
- URL: https://github.com/paulnonatomic/uielementtable
- Owner: PaulNonatomic
- Created: 2024-11-18T06:47:03.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-28T09:45:39.000Z (over 1 year ago)
- Last Synced: 2025-02-28T16:37:48.764Z (over 1 year ago)
- Language: C#
- Size: 67.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# UIElement Table
## Overview
UIElement Table is a Unity package that provides a way to draw tables with UIElements.
## Installation
To install UIElement Table into your Unity project, add the package from the git URL: https://github.com/PaulNonatomic/UIElementTable.git using the Unity package manager.
## Usage
```csharp
// Create a table
_table = new DataBindingUITable();
rootVisualElement.Add(_table);
// Style the table
var styleSheet = Resources.Load("CustomTable");
_table.SetCustomStyleSheet(styleSheet);
// Show row numbers (optional)
_table.ShowRowNumbers(new ColumnDefinition("#", 50f));
// Define columns using AddColumn with a cell creation func
_table.AddColumn(
new ColumnDefinition("Name", 150f),
person => new Label(person.Name)
);
_table.AddColumn(
new ColumnDefinition("Age", 75f),
person => new Label(person.Age.ToString())
);
_table.AddColumn(
new ColumnDefinition("Country"),
person => new Label(person.Country)
);
// Listen for cell clicks
_table.RegisterCallback(evt =>
{
var cell = _table.GetCell(evt.ColumnIndex, evt.RowIndex);
var label = cell.Q();
Debug.Log($"Clicked on cell: Column={evt.ColumnIndex}, Row={evt.RowIndex}, Value={label.text}");
});
// Populate the table with data
var people = new List
{
new Person("Alice", 30, "USA"),
new Person("Bob", 25, "Canada"),
new Person("Charlie", 35, "UK")
};
_table.SetData(people);
public class Person
{
public string Name;
public int Age;
public string Country;
public Person(string name, int age, string country)
{
Name = name;
Age = age;
Country = country;
}
}
```
