Created
May 13, 2015 18:41
-
-
Save Zammy/5f676c4435271128eca6 to your computer and use it in GitHub Desktop.
Simple list/table view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void DevicesDraw() | |
{ | |
const int NAME_WIDTH = 50; | |
const int IP_WIDTH = 50; | |
GUILayout.BeginHorizontal(); | |
GUILayout.FlexibleSpace(); | |
GUILayout.Label("Devices", EditorStyles.largeLabel); | |
GUILayout.FlexibleSpace(); | |
GUILayout.EndHorizontal(); | |
GUILayout.Space(10); | |
GUILayout.BeginHorizontal(); | |
GUILayout.Label("Name", EditorStyles.boldLabel, GUILayout.MinWidth(NAME_WIDTH)); | |
GUILayout.Label("IP", EditorStyles.boldLabel, GUILayout.MinWidth(IP_WIDTH)); | |
GUILayout.EndHorizontal(); | |
sDeviceInfoReceiver.DevicesMutex.WaitOne(); | |
if (Event.current.type == EventType.MouseDown && Event.current.button == 0) | |
{ | |
var mousePos = Event.current.mousePosition; | |
Debug.Log (mousePos); | |
int itemHeight = 16; | |
int deviceCount = sDeviceInfoReceiver.Devices.Count; | |
int firstItemY = 80; | |
int endOfTableY = firstItemY + itemHeight * deviceCount; | |
if ((mousePos.y - firstItemY > 0) && (mousePos.y < endOfTableY)) | |
{ | |
int newSelectedDevice = (int)(mousePos.y - firstItemY) / (int) itemHeight; | |
Debug.Log("Changed selected device " + newSelectedDevice); | |
this.selectedDevice = newSelectedDevice; | |
} | |
return; | |
} | |
for (int i = 0; i < sDeviceInfoReceiver.Devices.Count; i++) | |
{ | |
var device = sDeviceInfoReceiver.Devices[i]; | |
GUILayout.BeginHorizontal(); | |
if (this.selectedDevice == i) | |
{ | |
GUILayout.Label("S ", EditorStyles.label, GUILayout.Width(10)); | |
} | |
GUILayout.Label(device.name, EditorStyles.label, GUILayout.MinWidth(NAME_WIDTH)); | |
GUILayout.Label(device.ip.ToString(), EditorStyles.label, GUILayout.MinWidth(IP_WIDTH)); | |
GUILayout.EndHorizontal(); | |
} | |
sDeviceInfoReceiver.DevicesMutex.ReleaseMutex(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment