/****************************************************
    文件：TableColumnHeader.cs
    作者：陶长春
    邮箱：376248129@qq.com
    日期：2024年12月12日 8:16:50
    UnityVersion: 2021.3.13f1
    功能：绘制表头样式
*****************************************************/
using System.Collections;
using UnityEngine;
using System.Collections.Generic;
using UnityEditor.IMGUI.Controls;
using UnityEditor;

namespace TFramework
{
    /// <summary>
    /// 表格表头（列标题）
    /// </summary>
    public class TableColumnHeader<T> : MultiColumnHeader where T : class, new()
    {
        /// <summary>
        /// 绘制单个列标题方法
        /// </summary>
        public TAction<Rect, TableColumn<T>, int> DrawHeaderMethod;
        public TableColumnHeader(MultiColumnHeaderState state) : base(state)
        {

        }

        /// <summary>
        /// 单击列标题时展开的上下文菜单
        /// </summary>
        /// <param name="menu">上下文菜单</param>
        protected override void AddColumnHeaderContextMenuItems(GenericMenu menu)
        {
            base.AddColumnHeaderContextMenuItems(menu);
        }

        /// <summary>
        /// 单击列标题时
        /// </summary>
        /// <param name="column">列标题数据</param>
        /// <param name="columnIndex">列标题索引</param>
        protected override void ColumnHeaderClicked(MultiColumnHeaderState.Column column, int columnIndex)
        {
            base.ColumnHeaderClicked(column, columnIndex);
        }

        /// <summary>
        /// 定义单个列标题GUI
        /// </summary>
        /// <param name="column">列标题数据</param>
        /// <param name="headerRect">列标题矩形</param>
        /// <param name="columnIndex">列标题索引</param>
        protected override void ColumnHeaderGUI(MultiColumnHeaderState.Column column, Rect headerRect, int columnIndex)
        {
            TableColumn<T> tableColumn = column as TableColumn<T>;
            if (DrawHeaderMethod != null)
            {
                DrawHeaderMethod.Invoke(headerRect, tableColumn, columnIndex);
            }
            else
                base.ColumnHeaderGUI(column, headerRect, columnIndex);
        }
    }
}