TableCell class was added

This commit is contained in:
Evgeny Redikultsev
2024-01-27 21:19:06 +05:00
parent a9ffd8b903
commit a680e67ab3
13 changed files with 144 additions and 51 deletions

View File

@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelperCommon.Models.Tables
{
public enum CellRole
{
Title,
Header,
Regular
}
/// <summary>
/// Generic interface for cell of table
/// </summary>
/// <typeparam name="T"></typeparam>
public interface IShTableCell<T>
{
/// <summary>
/// Value of cell
/// </summary>
T Value { get; set; }
/// <summary>
/// Number of cell, joined with this one
/// </summary>
int ColumnSpan { get; set; }
/// <summary>
/// Role of the cell in table
/// </summary>
CellRole Role { get; set; }
}
}

View File

@@ -4,7 +4,7 @@ namespace StructureHelperCommon.Models.Tables
{
public interface IShTableRow<T>
{
List<T> Elements { get; }
List<IShTableCell<T>> Elements { get; }
int RowSize { get; }
}
}

View File

@@ -6,13 +6,13 @@ using System.Threading.Tasks;
namespace StructureHelperCommon.Models.Tables
{
public class ListTable<T>
public class ShTable<T>
{
private List<IShTableRow<T>> table;
public int RowSize { get; }
public ListTable(int rowSize)
public ShTable(int rowSize)
{
if (rowSize <= 0)
{
@@ -42,7 +42,7 @@ namespace StructureHelperCommon.Models.Tables
return table;
}
public List<T> GetElementsFromRow(int rowIndex)
public List<IShTableCell<T>> GetElementsFromRow(int rowIndex)
{
if (rowIndex >= 0 && rowIndex < table.Count)
{
@@ -66,7 +66,7 @@ namespace StructureHelperCommon.Models.Tables
if (columnIndex >= 0 && columnIndex < RowSize &&
rowIndex >= 0 && rowIndex < table.Count)
{
table[rowIndex].Elements[columnIndex] = value;
table[rowIndex].Elements[columnIndex].Value = value;
}
else
{

View File

@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelperCommon.Models.Tables
{
/// <inheritdoc/>
public class ShTableCell<T> : IShTableCell<T>
{
/// <inheritdoc/>
public T Value { get; set; }
/// <inheritdoc/>
public int ColumnSpan { get; set; }
/// <inheritdoc/>
public CellRole Role { get; set; }
public ShTableCell()
{
Role = CellRole.Regular;
ColumnSpan = 1;
}
}
}

View File

@@ -8,7 +8,7 @@ namespace StructureHelperCommon.Models.Tables
{
public class ShTableRow<T> : IShTableRow<T>
{
private List<T> elements;
private List<IShTableCell<T>> elements;
public int RowSize { get; }
@@ -20,15 +20,16 @@ namespace StructureHelperCommon.Models.Tables
}
RowSize = rowSize;
elements = new List<T>(rowSize);
elements = new List<IShTableCell<T>>(rowSize);
for (int i = 0; i < rowSize; i++)
{
elements.Add(default);
var newCell = new ShTableCell<T>();
elements.Add(newCell);
}
}
// Property to access elements in the row
public List<T> Elements => elements;
public List<IShTableCell<T>> Elements => elements;
internal void Add(object value)
{