public static void Headers(TableHeader[] headers) { _headers = headers; GUILayout.BeginHorizontal("Toolbar"); foreach (var tableHeader in _headers) { Header(tableHeader); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); }
public static bool Header(TableHeader header) { var controlID = GUIUtility.GetControlID(FocusType.Passive); var label = new GUIContent(header.Label); var headerPos = GUILayoutUtility.GetRect(label, StyleStore.ToolbarButton, GUILayout.Width(header.Width)); var resizeHandle = headerPos; resizeHandle.x = resizeHandle.x + headerPos.width; resizeHandle.width = RESIZE_HANDLE_SIZE; EditorGUIUtility.AddCursorRect(resizeHandle, MouseCursor.ResizeHorizontal); switch (Event.current.type) { case EventType.MouseDown: if (Event.current.button == 0 && resizeHandle.Contains(Event.current.mousePosition) ) { GUIUtility.hotControl = controlID; Event.current.Use(); } break; case EventType.MouseDrag: if (!Event.current.delta.x.Equals(0) && GUIUtility.hotControl == controlID) { Event.current.Use(); header.Width = header.Width + Event.current.delta.x; } break; case EventType.MouseUp: if (GUIUtility.hotControl == controlID) { GUIUtility.hotControl = 0; Event.current.Use(); } break; } return GUI.Button(headerPos, label, StyleStore.ToolbarButton); }
private void LoadInfo() { if (_selectedType != _loadedInfoForType) { _collection = typeof(GameState).GetMethod("FetchAll") .MakeGenericMethod(_selectedType) .Invoke(null, new object[] { false }) as IList; _props = _selectedType.GetProperties().OrderBy(prop => prop.Name); _headers = _props.Select(prop => { var header = new TableHeader { Label = prop.Name, Width = 100 }; switch (header.Label) { case "_Id": header.Label = "ID"; header.Width = 23; break; case "_EditorId": header.Label = "Editor ID"; break; } return header; }).ToArray(); _loadedInfoForType = _selectedType; } }