/// <inheritdoc cref="Draw(int, IReorderableListAdaptor, DrawEmpty)"/> public void Draw(IReorderableListAdaptor adaptor, DrawEmpty drawEmpty) { int controlID = GUIUtility.GetControlID(FocusType.Passive); Draw(controlID, adaptor, drawEmpty); }
/// <summary> /// Generate and draw control from state object. /// </summary> /// <param name="adaptor">Reorderable list adaptor.</param> /// <param name="drawEmpty">Delegate for drawing empty list.</param> /// <param name="flags">Optional flags to pass into list field.</param> public static void DrawControlFromState(IReorderableListAdaptor adaptor, DrawEmpty drawEmpty, ReorderableListFlags flags) { int controlID = GUIUtility.GetControlID(FocusType.Passive); var control = GUIUtility.GetStateObject(typeof(ReorderableListControl), controlID) as ReorderableListControl; control.Flags = flags; control.Draw(controlID, adaptor, drawEmpty); }
/// <summary> /// Draw layout version of list control. /// </summary> /// <param name="controlID">Unique ID of list control.</param> /// <param name="adaptor">Reorderable list adaptor.</param> /// <param name="drawEmpty">Delegate for drawing empty list.</param> private void Draw(int controlID, IReorderableListAdaptor adaptor, DrawEmpty drawEmpty) { FixStyles(); PrepareState(controlID, adaptor); Rect position; if (adaptor.Count > 0) position = DrawLayoutListField(controlID, adaptor); else position = DrawLayoutEmptyList(drawEmpty); DrawFooterControls(position, controlID, adaptor); }
/// <summary> /// Draw content for empty list (layout version). /// </summary> /// <param name="drawEmpty">Callback to draw empty content.</param> /// <returns> /// Position of list container area in GUI (excludes footer area). /// </returns> private Rect DrawLayoutEmptyList(DrawEmpty drawEmpty) { Rect r = EditorGUILayout.BeginVertical(ContainerStyle); { if (drawEmpty != null) drawEmpty(); else GUILayout.Space(5); } EditorGUILayout.EndVertical(); // Allow room for footer buttons? if (HasFooterButtons) GUILayoutUtility.GetRect(0, FooterButtonStyle.fixedHeight - 1); return r; }
public string ToString(ObjectStyle defaultStyle) { StringBuilder sb = new StringBuilder(); if (!Number.IsEqualTo(xStart, defaultStyle.xStart)) { sb.AppendFormat("xstart:{0};", xStart); } if (!Number.IsEqualTo(yStart, defaultStyle.yStart)) { sb.AppendFormat("ystart:{0};", yStart); } if (relativeWidth != defaultStyle.relativeWidth) { sb.AppendFormat("width:{0}%;", relativeWidth ?? 100); } if (width != defaultStyle.width) { sb.AppendFormat("width:{0};", width ?? 0); } if (relativeHeight != defaultStyle.relativeHeight) { sb.AppendFormat("height:{0}%;", relativeHeight ?? 100); } if (height != defaultStyle.height) { sb.AppendFormat("height:{0};", height ?? 0); } if (hPadding == vPadding && ((hPadding != defaultStyle.hPadding || vPadding != defaultStyle.vPadding))) { sb.AppendFormat("padding:{0};", Padding ?? 0); } else { if (hPadding != defaultStyle.hPadding) { sb.AppendFormat("hpadding:{0};", hPadding ?? 0); } if (vPadding != defaultStyle.vPadding) { sb.AppendFormat("vpadding:{0};", vPadding ?? 0); } } if (hFill != defaultStyle.hFill) { sb.AppendFormat("hfill:{0};", (hFill ?? false).ToString().ToLower()); } if (vFill != defaultStyle.vFill) { sb.AppendFormat("vfill:{0};", (vFill ?? false).ToString().ToLower()); } if (border != defaultStyle.border) { sb.AppendFormat("border:{0};", border ?? 0); } if (innerVerticalBorder == innerHorizontalBorder && (innerVerticalBorder != defaultStyle.innerVerticalBorder || innerHorizontalBorder != defaultStyle.innerHorizontalBorder)) { sb.AppendFormat("innerborder:{0};", InnerBorder ?? 0); } else { if (innerHorizontalBorder != defaultStyle.innerHorizontalBorder) { sb.AppendFormat("innerhborder:{0};", innerHorizontalBorder ?? 0); } if (innerVerticalBorder != defaultStyle.innerVerticalBorder) { sb.AppendFormat("innervborder:{0};", innerVerticalBorder ?? 0); } } if (spacing != defaultStyle.spacing) { sb.AppendFormat("spacing:{0};", spacing ?? 0); } if (innerVSpacing == innerHSpacing && (innerVSpacing != defaultStyle.innerVSpacing || innerHSpacing != defaultStyle.innerHSpacing)) { sb.AppendFormat("innerspacing:{0};", InnerSpacing ?? 0); } else { if (innerHSpacing != defaultStyle.innerHSpacing) { sb.AppendFormat("innerhspacing:{0};", innerHSpacing ?? 0); } if (innerVSpacing != defaultStyle.innerVSpacing) { sb.AppendFormat("innervspacing:{0};", innerVSpacing ?? 0); } } if (HAlign != HorizontalAlignment.Left && HAlign != defaultStyle.HAlign) { switch (HAlign) { case HorizontalAlignment.Right: sb.Append("halign:right;"); break; case HorizontalAlignment.Center: sb.Append("halign:center;"); break; } } if (VAlign != VerticalAlignment.Top && VAlign != defaultStyle.VAlign) { switch (VAlign) { case VerticalAlignment.Bottom: sb.Append("valign:bottom;"); break; case VerticalAlignment.Center: sb.Append("valign:center;"); break; } } if (DrawEmpty != defaultStyle.DrawEmpty) { sb.AppendFormat("drawempty:{0};", DrawEmpty.ToString().ToLowerInvariant()); } if (AllowHBreak != defaultStyle.AllowHBreak) { sb.AppendFormat("allowhbreak:{0};", AllowHBreak.ToString().ToLowerInvariant()); } if (AllowVBreak != defaultStyle.AllowVBreak) { sb.AppendFormat("allowvbreak:{0};", AllowVBreak.ToString().ToLowerInvariant()); } if (!bgColor.Equal(defaultStyle.BgColor)) { sb.AppendFormat("bgcolor:{0};", BgColor.ToHTMLColor()); } if (!fgColor.Equal(defaultStyle.FgColor)) { sb.AppendFormat("fgcolor:{0};", FgColor.ToHTMLColor()); } if (!borderColor.Equals(defaultStyle.BorderColor)) { sb.AppendFormat("bordercolor:{0};", BorderColor.ToHTMLColor()); } return(sb.ToString().TrimEnd(';')); }
/// <inheritdoc cref="Draw(int, IReorderableListAdaptor, DrawEmpty)"/> public void Draw(IReorderableListAdaptor adaptor, DrawEmpty drawEmpty) { int controlID = GetReorderableListControlID(); Draw(controlID, adaptor, drawEmpty); }
/// <summary> /// Draw content for empty list (layout version). /// </summary> /// <param name="adaptor">Reorderable list adaptor.</param> /// <param name="drawEmpty">Callback to draw empty content.</param> /// <returns> /// Position of list container area in GUI (excludes footer area). /// </returns> private Rect DrawLayoutEmptyList(IReorderableListAdaptor adaptor, DrawEmpty drawEmpty) { Rect position = EditorGUILayout.BeginVertical(ContainerStyle); { if (drawEmpty != null) drawEmpty(); else Debug.LogError("Unexpected call to 'DrawLayoutEmptyList'"); s_CurrentListStack.Push(new ListInfo(_controlID, position)); try { adaptor.BeginGUI(); _insertionIndex = 0; _insertionPosition = position.y + 2; HandleDropInsertion(position, adaptor); adaptor.EndGUI(); } finally { s_CurrentListStack.Pop(); } } EditorGUILayout.EndVertical(); // Allow room for footer buttons? if (HasFooterButtons) GUILayoutUtility.GetRect(0, FooterButtonStyle.fixedHeight - 1); return position; }