/// <summary> /// Renders the data table. /// </summary> /// <param name="table">Table.</param> /// <param name="widthPerCharacter">Width per character.</param> void RenderDataTable(SQLiteUnityKit.DataTable table) { if(null == table || null == table.Columns) { GUILayout.Label("DataTable is NULL"); return; } int[] columnWidths = new int[null != table.Columns ? table.Columns.Count : 0]; //Calculate size of each table for(int i=0; i<table.Columns.Count; i++) { columnWidths[i] = Mathf.Max(2, table.Columns[i].Length); } foreach(var row in table.Rows) { for(int j=0; j<columnWidths.Length; j++) { columnWidths[j] = Mathf.Max(columnWidths[j], row[j].ToString().Length); } } //Create string format string rowFormat = string.Empty; for(int i=0 ; i<columnWidths.Length; i++) { rowFormat += string.Format("{{{0},-{1}}}", i, columnWidths[i] + 1); } StringBuilder tableStr = new StringBuilder(); tableStr.AppendLine("Rows: " + table.Rows.Count + " Columns:" + table.Columns.Count); tableStr.AppendFormat(rowFormat, table.Columns.ToArray()); tableStr.AppendLine(); foreach(var row in table.Rows) { tableStr.AppendFormat(rowFormat, row.Data); tableStr.AppendLine(); } string str = tableStr.ToString(); Log (str); Debug.Log(str); }
/// <summary> /// Renders the data table. /// </summary> /// <param name="table">Table.</param> private void RenderDataTable(SQLiteUnityKit.DataTable table, float widthPerCharacter = 6.8f) { if(null == table || null == table.Columns) { EditorGUILayout.LabelField("DataTable is NULL"); return; } float[] columnWidths = new float[null != table.Columns ? table.Columns.Count : 0]; //Calculate size of each table for(int i=0; i<table.Columns.Count; i++) { columnWidths[i] = Mathf.Max(20f, (float)table.Columns[i].Length * widthPerCharacter); } if(null != table.Rows) { foreach(var row in table.Rows) { for(int j=0; j<columnWidths.Length; j++) { if(null != row[j]) { columnWidths[j] = Mathf.Max(columnWidths[j], (float)(row[j].ToString()).Length * widthPerCharacter); } } } } EditorGUILayout.BeginVertical(); { _TableScrollPosition = EditorGUILayout.BeginScrollView(_TableScrollPosition); { // Render Table Header EditorGUILayout.BeginHorizontal(); { for(int i=0; i<table.Columns.Count; i++) { EditorGUILayout.LabelField(table.Columns[i], EditorStyles.boldLabel, GUILayout.MaxWidth(columnWidths[i])); } } EditorGUILayout.EndHorizontal(); foreach(var row in table.Rows) { //Render row EditorGUILayout.BeginHorizontal(); { for(int i=0; i<table.Columns.Count; i++) { string item = null != row[i] ? row[i].ToString() : string.Empty; EditorGUILayout.LabelField( new GUIContent(item, item), GUILayout.MaxWidth(columnWidths[i])); } } EditorGUILayout.EndHorizontal(); } } EditorGUILayout.EndScrollView(); } EditorGUILayout.EndVertical(); }