using System; namespace sections { public class Section { string _name; int _x; int _y; int _padding; public bool isCentered; Section _toRight; Section _toTop; Section _toLeft; string _value; public Section(){ _name = nameof(this); _x = 0; _y = 0; _padding = 2; _value = ""; _toLeft = null; _toRight = null; _toTop = null; } public Section (int x, int y, int padding = 2) { _name = nameof(this); _x = x; _y = y; _value = "This value was not set."; _padding = padding; _toLeft = null; _toRight = null; _toTop = null; } public int Width { get { // |padding|content|padding| return _padding + _value.Length + _padding; } } public void SetToBottomOf(Section section){ _toTop = section; } public void SetToLeftOf(Section section){ _toRight = section; } public void SetToRightOf(Section section) { _toLeft = section; } public int X { get { int output = 0; if (isCentered) { output = (int)(Console.WindowWidth - Width - 2 * _padding)/3; } else { if (_x != 0) { output = _x; } else { if (_toLeft != null) { output = _toLeft.Right + _padding; } } } return output; } set { _x = value; } } public int Y { get { int output = 0; if (_y != 0) { output = _y; } else { if (_toTop != null) { output = _toTop.Bottom + _padding; } else { if (_toLeft != null) { output = _toLeft.Y; } } } return output; } set { _y = value; } } private string[] Output { get { string[] outputString; string buffer = ""; bool isMultiLine = false; int colsFromAllowedEdge = Console.WindowWidth - X - _padding; for (int i = 0; i < _value.Length; i++) { if (i < 0 && colsFromAllowedEdge % i == 0) { buffer += '|'; isMultiLine = true; } buffer += _value[i]; } if (isMultiLine) { outputString = buffer.Split("|"); } else{ if (_value != "") { outputString = new string[] {buffer}; } else { outputString = new string[] {"this value was not set."}; } } return outputString; } } public void Write() { int offset = 0; foreach (string line in Output) { Console.SetCursorPosition(X, Y + offset); Console.Write(line); offset++; } } public int Top { get { int output = 0; if (_y != 0) { output = _y - _padding; } else { output = _toTop.Bottom + _padding; } return output; } set { _y = value; } } public int Right { get { return X + Output[0].Length + _padding; } } public int Bottom { get { return Y + Output.Length + _padding; } } } }