commit 614c7d2e02ea96139be14cd568165a8ca9f8d4db Author: TristanAncelet Date: Sat Feb 19 21:59:54 2022 -0600 initial commit diff --git a/section.cs b/section.cs new file mode 100644 index 0000000..f07b43d --- /dev/null +++ b/section.cs @@ -0,0 +1,164 @@ +using System; + +namespace sections +{ +public class Section { + int _x; + int _y; + int _padding; + public bool isCentered; + Section _toRight; + Section _toTop; + Section _toLeft; + + string _value; + + public Section(){ + _x = 0; + _y = 0; + _padding = 2; + _value = ""; + _toLeft = null; + _toRight = null; + _toTop = null; + } + public Section (int x, int y, int padding = 2) { + _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; + } + } + + + + public string Value { + get { + return _value; + } set { + _value = value; + } + } + + private string[] Output { + get { + string[] outputString; + string buffer = ""; + bool isMultiLine = false; + int colsFromAllowedEdge = (int)((Console.WindowWidth - X - _padding)/2); + 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; + } + } + } + } \ No newline at end of file diff --git a/window.cs b/window.cs new file mode 100644 index 0000000..20376cd --- /dev/null +++ b/window.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using sections; + +namespace window +{ + + public class Display + { + Dictionary sectionList; + + + public Display () { + sectionList = new Dictionary(); + } + + public void AddSection(Section section) { + sectionList.Add(sectionList.Count,section); + } + + public void Present() { + Console.Clear(); + foreach (Section section in sectionList.Values) { + section.Write(); + } + + } + } + +} \ No newline at end of file