Skip to content

Commit

Permalink
Some review fixes (ForNeVeR#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
ForNeVeR committed Mar 23, 2019
1 parent 69a25bb commit 90bc3ac
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 65 deletions.
86 changes: 27 additions & 59 deletions src/WpfMath/Atoms/MatrixAtom.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text.RegularExpressions;
using WpfMath.Boxes;
Expand All @@ -14,81 +15,49 @@ internal class MatrixAtom:Atom
/// <summary>
/// Initializes a new <see cref="MatrixAtom"/> with the specified cell atoms.
/// </summary>
public MatrixAtom(SourceSpan source,List<List<Atom>> _tblcells,VerticalAlignment cellValignment=VerticalAlignment.Center, HorizontalAlignment cellHAlignment = HorizontalAlignment.Center, double tbPad=0.35, double lrpad = 0.35):base(source)
public MatrixAtom(
SourceSpan source,
List<List<Atom>> tableCells,
VerticalAlignment cellValignment = VerticalAlignment.Center,
HorizontalAlignment cellHAlignment = HorizontalAlignment.Center,
double tbPad = 0.35,
double lrpad = 0.35) : base(source)
{
MatrixCells = _tblcells;
MatrixCells = new ReadOnlyCollection<ReadOnlyCollection<Atom>>(
tableCells.Select(row => new ReadOnlyCollection<Atom>(row)).ToList());
this.CellHorizontalAlignment = cellHAlignment;
this.CellVerticalAlignment = cellValignment;
CellBottomTopPadding = tbPad;
CellLeftRightPadding = lrpad;
}

#region Properties
/// <summary>
/// Gets or sets the Matrix cell <see cref="Atom"/>s contained in this Matrix.
/// </summary>
public List<List<Atom>> MatrixCells
{
get; private set;
}
public ReadOnlyCollection<ReadOnlyCollection<Atom>> MatrixCells { get; }

/// <summary>
/// Gets or sets the top and bottom padding of the cells.
/// </summary>
public double CellBottomTopPadding
{
get;
private set;
}
public double CellBottomTopPadding { get; }

/// <summary>
/// Gets or sets the left and right padding of the cells.
/// </summary>
public double CellLeftRightPadding
{
get;
private set;
}
public double CellLeftRightPadding { get; }

/// <summary>
/// Gets the number of rows in this <see cref="MatrixAtom"/>.
/// </summary>
public int RowCount
{
get
{
if (MatrixCells == null)
{
return 0;
}
else
{
return MatrixCells.Count;
}
}
}
public int RowCount => MatrixCells.Count;

/// <summary>
/// Gets the number of columns in this <see cref="MatrixAtom"/>.
/// </summary>
public int ColumnCount
{
get
{
if (MatrixCells == null||MatrixCells[0]==null)
{
return 0;
}
else
{
return MatrixCells[0].Count;
}
}
}
public int ColumnCount => MatrixCells[0]?.Count ?? 0;

public VerticalAlignment CellVerticalAlignment { get; private set; }
public HorizontalAlignment CellHorizontalAlignment { get; private set; }
#endregion
public VerticalAlignment CellVerticalAlignment { get; }
public HorizontalAlignment CellHorizontalAlignment { get; }

protected override Box CreateBoxCore(TexEnvironment environment)
{
Expand All @@ -98,7 +67,7 @@ protected override Box CreateBoxCore(TexEnvironment environment)

//Region for adjustment vars
double maxrowWidth = 0;

//stores the max cell height for each row
var RowsMaxCellHeight = new List<double>();
for (int i = 0; i < RowCount; i++)
Expand All @@ -120,7 +89,7 @@ protected override Box CreateBoxCore(TexEnvironment environment)
resultBox.Add(new StrutBox(maxrowWidth, CellBottomTopPadding / 2, 0, 0));

var rowbox = new HorizontalBox() {Tag= $"Row:{i}",};

for (int j = 0; j < ColumnCount; j++)
{
double maxrowHeight = 0;
Expand All @@ -143,7 +112,7 @@ protected override Box CreateBoxCore(TexEnvironment environment)
ColumnsMaxCellWidth[j] = rowcellbox.TotalWidth > ColumnsMaxCellWidth[j] ? rowcellbox.TotalWidth : ColumnsMaxCellWidth[j];
rowcellbox.Tag = "innercell";
//cell box holder
var rowcolbox = new VerticalBox(){Tag=$"Cell{i}:{j}",ShowBounds=false};
var rowcolbox = new VerticalBox() { Tag = $"Cell{i}:{j}" };

var celltoppad = new StrutBox(rowcellbox.TotalWidth, CellBottomTopPadding / 2, 0, 0){Tag = $"CellTopPad{i}:{j}",};
var cellbottompad = new StrutBox(rowcellbox.TotalWidth, CellBottomTopPadding / 2, 0, 0){Tag = $"CellBottomPad{i}:{j}",};
Expand All @@ -163,7 +132,7 @@ protected override Box CreateBoxCore(TexEnvironment environment)
RowsMaxCellHeight[i] = maxrowHeight > RowsMaxCellHeight[i] ? maxrowHeight : RowsMaxCellHeight[i];

}

rowbox.Shift = 0;
resultBox.Add(rowbox);
//row bottom pad
Expand Down Expand Up @@ -192,7 +161,7 @@ protected override Box CreateBoxCore(TexEnvironment environment)
else if(rowcolitem is VerticalBox && rowcolitem.Tag.ToString() == $"Cell{rows}:{columns}")
{
double cellVShift = RowsMaxCellHeight[rows] - rowcolitem.TotalHeight;

double cellHShift = ColumnsMaxCellWidth[columns]-rowcolitem.TotalWidth;
((HorizontalBox)Matrixrowitem).Children[j - 1].Shift = rowcolitem.Depth;// + (cellVShift / 2);//.Width += cellHShift / 2;
((HorizontalBox)Matrixrowitem).Children[j + 1].Shift = rowcolitem.Depth;// +(cellVShift / 2);// Width += cellHShift / 2;
Expand Down Expand Up @@ -224,7 +193,7 @@ protected override Box CreateBoxCore(TexEnvironment environment)
var currowcolitem = ((HorizontalBox)Matrixrowitem).Children[j];
var prevrowcolitem = j > 0 ? ((HorizontalBox)Matrixrowitem).Children[j - 1] : ((HorizontalBox)Matrixrowitem).Children[j];
var nextrowcolitem = j < ((HorizontalBox)Matrixrowitem).Children.Count-1 ? ((HorizontalBox)Matrixrowitem).Children[j + 1] : ((HorizontalBox)Matrixrowitem).Children[j];

if (currowcolitem is VerticalBox&& Regex.IsMatch(currowcolitem.Tag.ToString(), @"Cell[0-9]+:[0-9]+"))
{
rowwidth += currowcolitem.TotalWidth;
Expand Down Expand Up @@ -277,7 +246,7 @@ protected override Box CreateBoxCore(TexEnvironment environment)
}
break;
}

//case HorizontalAlignment.Stretch:
// {
// if (prevrowcolitem is StrutBox && prevrowcolitem.Tag.ToString() == leftstructboxtag)
Expand Down Expand Up @@ -306,7 +275,7 @@ protected override Box CreateBoxCore(TexEnvironment environment)
var curcellitem = ((VerticalBox)currowcolitem).Children[k];
var prevcellitem =k>0? ((VerticalBox)currowcolitem).Children[k-1]:((VerticalBox)currowcolitem).Children[k];
var nextcellitem =k<(((VerticalBox)currowcolitem).Children.Count -1)? ((VerticalBox)currowcolitem).Children[k+1]:((VerticalBox)currowcolitem).Children[k];

if (curcellitem.Tag.ToString() == "innercell" )
{
cellheight += curcellitem.TotalHeight;
Expand Down Expand Up @@ -365,7 +334,7 @@ protected override Box CreateBoxCore(TexEnvironment environment)
// cellheight += prevcellitem.TotalHeight;
// if (prevcellitem.Height > (currowcolitem.Height / 2))
// {

// }
// }
// if (nextcellitem.Tag.ToString() == bottomstructboxtag)
Expand Down Expand Up @@ -400,7 +369,7 @@ protected override Box CreateBoxCore(TexEnvironment environment)
default:
break;
}

if (prevrowcolitem is StrutBox && prevrowcolitem.Tag.ToString() == leftstructboxtag)
{
prevrowcolitem.Shift += MatrixCellGaps[rows][columns].Item2;
Expand Down Expand Up @@ -456,6 +425,5 @@ protected override Box CreateBoxCore(TexEnvironment environment)

return finalbox;
}

}
}
7 changes: 1 addition & 6 deletions src/WpfMath/Boxes/Box.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,7 @@ public Brush Background
get;
set;
}

/// <summary>
/// Gets or sets a value that specifies whether the bounds of this box should be shown.
/// </summary>
public bool ShowBounds{get; set;}


public object Tag{get; set;}

public double TotalHeight
Expand Down

0 comments on commit 90bc3ac

Please sign in to comment.