public override bool Draw(string label, ref AssetRef <T> obj, RenderContext rc) { object assetName = obj.ID.Value; if (DrawerCache.GetDrawer(typeof(string)).Draw(label, ref assetName, rc)) { obj = new AssetRef <T>((string)assetName); return(true); } return(false); }
public override bool Draw(string label, ref List <T> obj, RenderContext rc) { var arrayDrawer = DrawerCache.GetDrawer(typeof(T[])); object arrayAsObj = obj.ToArray(); if (arrayDrawer.Draw(label, ref arrayAsObj, rc)) { T[] array = (T[])arrayAsObj; obj = new List <T>(array); return(true); } return(false); }
protected override bool DrawNonNull(string label, ref object obj, RenderContext rc) { ImGui.PushID(label); if (!_drawRootNode || ImGui.CollapsingHeader(label, label, true, true)) { foreach (PropertyInfo pi in _properties) { if (_drawRootNode) { const int levelMargin = 5; ImGui.PushItemWidth(levelMargin); ImGui.LabelText("", ""); ImGui.PopItemWidth(); ImGui.SameLine(); } object originalValue = pi.GetValue(obj); object value = originalValue; Drawer drawer; if (value != null) { drawer = DrawerCache.GetDrawer(value.GetType()); } else { drawer = DrawerCache.GetDrawer(pi.PropertyType); } bool changed = drawer.Draw(pi.Name, ref value, rc); if (changed && originalValue != value || pi.PropertyType.GetTypeInfo().IsValueType) { if (pi.SetMethod != null) { pi.SetValue(obj, value); } } } } ImGui.PopID(); return(false); }
protected override bool DrawNonNull(string label, ref object obj, RenderContext rc) { T[] arr = (T[])obj; int length = arr.Length; bool newArray = false; bool arrayModified = false; if (ImGui.TreeNode($"{label}[{length}]###{label}")) { if (ImGui.IsLastItemHovered()) { ImGui.SetTooltip($"{TypeDrawn.GetElementType()}[{arr.Length}]"); } if (!newArray) { if (ImGui.SmallButton("-")) { int newLength = Math.Max(length - 1, 0); Array.Resize(ref arr, newLength); newArray = true; } ImGui.SameLine(); ImGui.Spacing(); ImGui.SameLine(); if (ImGui.SmallButton("+")) { Array.Resize(ref arr, length + 1); newArray = true; } } length = arr.Length; for (int i = 0; i < length; i++) { ImGui.PushStyleColor(ColorTarget.Button, RgbaFloat.Red.ToVector4()); if (ImGui.Button($"X##{i}", new System.Numerics.Vector2(15, 15))) { ShiftArrayDown(arr, i); Array.Resize(ref arr, length - 1); newArray = true; length -= 1; ImGui.PopStyleColor(); i--; continue; } ImGui.PopStyleColor(); ImGui.SameLine(); object element = arr[i]; Drawer drawer; if (element == null) { drawer = DrawerCache.GetDrawer(typeof(T)); } else { Type realType = element.GetType(); drawer = DrawerCache.GetDrawer(realType); } bool changed = drawer.Draw($"{TypeDrawn.GetElementType().Name}[{i}]", ref element, rc); if (changed || drawer.TypeDrawn.GetTypeInfo().IsValueType) { arr[i] = (T)element; arrayModified = true; } } ImGui.TreePop(); } else if (ImGui.IsLastItemHovered()) { ImGui.SetTooltip($"{TypeDrawn.GetElementType()}[{arr.Length}]"); } if (newArray) { obj = arr; return(true); } return(arrayModified); }