public static string ToMardownTableString <T>(this IEnumerable <T> rows) { var builder = new TableBuilder(); var properties = typeof(T).GetProperties().Where(p => p.PropertyType.IsRenderable()).ToArray(); var fields = typeof(T).GetFields().Where(f => f.FieldType.IsRenderable()).ToArray(); builder.WithHeader(properties.Select(p => p.Name).Concat(fields.Select(f => f.Name)).ToArray()); foreach (var row in rows) { builder.WithRow(properties.Select(p => p.GetValue(row, null)) .Concat(fields.Select(f => f.GetValue(row))).ToArray()); } return(builder.ToString()); }
//-------------------------------------------------------------------------------------------- public static T CopyElement <T>(this T source, T target) where T : VisualElement { var styleValues = new List <object>(); styleValues.Add(target.style.width = source.resolvedStyle.width == 0 ? new StyleLength(StyleKeyword.Auto) : source.resolvedStyle.width); styleValues.Add(target.style.height = source.resolvedStyle.height == 0 ? new StyleLength(StyleKeyword.Auto) : source.resolvedStyle.height); styleValues.Add(target.style.maxWidth = source.resolvedStyle.maxWidth.value == 0 ? new StyleLength(StyleKeyword.Auto) : source.resolvedStyle.maxWidth.value); styleValues.Add(target.style.maxHeight = source.resolvedStyle.maxHeight.value == 0 ? new StyleLength(StyleKeyword.Auto) : source.resolvedStyle.maxHeight.value); styleValues.Add(target.style.minWidth = source.resolvedStyle.minWidth.value == 0 ? new StyleLength(StyleKeyword.Auto) : source.resolvedStyle.minWidth.value); styleValues.Add(target.style.minHeight = source.resolvedStyle.minHeight.value == 0 ? new StyleLength(StyleKeyword.Auto) : source.resolvedStyle.minHeight.value); // styleValues.Add(target.style.flexBasis = source.resolvedStyle.flexBasis.keyword == StyleKeyword.Auto // ? new StyleLength(StyleKeyword.Auto) // : source.resolvedStyle.flexBasis.keyword == StyleKeyword.Undefined // ? new StyleLength(StyleKeyword.Auto) // : source.resolvedStyle.flexBasis.keyword); // // Debug.Log($"target flexBasis {target.style.flexBasis.value}"); // Debug.Log($"source style flexBasis {source.style.flexBasis.value}"); // Debug.Log($"source resolvedStyle flexBasis {source.resolvedStyle.flexBasis.value}"); styleValues.Add(target.style.flexGrow = source.resolvedStyle.flexGrow); styleValues.Add(target.style.flexShrink = source.resolvedStyle.flexShrink); styleValues.Add(target.style.flexDirection = source.resolvedStyle.flexDirection); styleValues.Add(target.style.flexWrap = source.resolvedStyle.flexWrap); // target.style.left = source.resolvedStyle.left; // target.style.top = source.resolvedStyle.top; // target.style.right = source.resolvedStyle.right; // target.style.bottom = source.resolvedStyle.bottom; styleValues.Add(target.style.marginLeft = source.resolvedStyle.marginLeft); styleValues.Add(target.style.marginTop = source.resolvedStyle.marginTop); styleValues.Add(target.style.marginRight = source.resolvedStyle.marginRight); styleValues.Add(target.style.marginBottom = source.resolvedStyle.marginBottom); styleValues.Add(target.style.paddingLeft = source.resolvedStyle.paddingLeft); styleValues.Add(target.style.paddingTop = source.resolvedStyle.paddingTop); styleValues.Add(target.style.paddingRight = source.resolvedStyle.paddingRight); styleValues.Add(target.style.paddingBottom = source.resolvedStyle.paddingBottom); // target.style.position = source.resolvedStyle.position; styleValues.Add(target.style.alignSelf = source.resolvedStyle.alignSelf); styleValues.Add(target.style.unityTextAlign = source.resolvedStyle.unityTextAlign); styleValues.Add(target.style.unityFontStyleAndWeight = source.resolvedStyle.unityFontStyleAndWeight); styleValues.Add(target.style.fontSize = source.resolvedStyle.fontSize); styleValues.Add(target.style.whiteSpace = source.resolvedStyle.whiteSpace); styleValues.Add(target.style.color = source.resolvedStyle.color); styleValues.Add(target.style.backgroundColor = source.resolvedStyle.backgroundColor); styleValues.Add(target.style.unityFont = source.resolvedStyle.unityFont); styleValues.Add(target.style.unityBackgroundScaleMode = source.resolvedStyle.unityBackgroundScaleMode); styleValues.Add(target.style.unityBackgroundImageTintColor = source.resolvedStyle.unityBackgroundImageTintColor); styleValues.Add(target.style.alignItems = source.resolvedStyle.alignItems); styleValues.Add(target.style.alignContent = source.resolvedStyle.alignContent); styleValues.Add(target.style.justifyContent = source.resolvedStyle.justifyContent); styleValues.Add(target.style.borderLeftColor = source.resolvedStyle.borderLeftColor); styleValues.Add(target.style.borderRightColor = source.resolvedStyle.borderRightColor); styleValues.Add(target.style.borderTopColor = source.resolvedStyle.borderTopColor); styleValues.Add(target.style.borderBottomColor = source.resolvedStyle.borderBottomColor); styleValues.Add(target.style.borderLeftWidth = source.resolvedStyle.borderLeftWidth); styleValues.Add(target.style.borderRightWidth = source.resolvedStyle.borderRightWidth); styleValues.Add(target.style.borderTopWidth = source.resolvedStyle.borderTopWidth); styleValues.Add(target.style.borderBottomWidth = source.resolvedStyle.borderBottomWidth); styleValues.Add(target.style.borderTopLeftRadius = source.resolvedStyle.borderTopLeftRadius); styleValues.Add(target.style.borderTopRightRadius = source.resolvedStyle.borderTopRightRadius); styleValues.Add(target.style.borderBottomLeftRadius = source.resolvedStyle.borderBottomLeftRadius); styleValues.Add(target.style.borderBottomRightRadius = source.resolvedStyle.borderBottomRightRadius); // styleValues.Add(target.style.unitySliceLeft = source.resolvedStyle.unitySliceLeft); // styleValues.Add(target.style.unitySliceTop = source.resolvedStyle.unitySliceTop); // styleValues.Add(target.style.unitySliceRight = source.resolvedStyle.unitySliceRight); // styleValues.Add(target.style.unitySliceBottom = source.resolvedStyle.unitySliceBottom); styleValues.Add(target.style.opacity = source.resolvedStyle.opacity); styleValues.Add(target.style.visibility = source.resolvedStyle.visibility); styleValues.Add(target.style.display = source.resolvedStyle.display); var table = new TableBuilder(); table.WithHeader("Name", "Value"); styleValues.ForEach(x => { if (x is IResolvedStyle style) { table.WithRow(x.GetType().Name, style.GetType().Name); } }); table.ToConsole(); return(target); }
// -- Apply Style data to element from StyleStore ---------------- public static T FromStyleData <T>(this VisualElementStyleStore source, T target, bool buildTable = false) where T : VisualElement { var styleValues = new Dictionary <string, object> { { nameof(target.style.width), target.style.width = source.Width }, { nameof(target.style.height), target.style.height = source.Height }, { nameof(target.style.maxWidth), target.style.maxWidth = (source.MaxWidth.value == 0 || source.MaxWidth == StyleKeyword.Null) ? new StyleLength(StyleKeyword.Auto) : source.MaxWidth.value }, { nameof(target.style.maxHeight), target.style.maxHeight = source.MaxHeight.value == 0 ? new StyleLength(StyleKeyword.Auto) : source.MaxHeight.value }, { nameof(target.style.minWidth), target.style.minWidth = source.MinWidth.value == 0 ? new StyleLength(StyleKeyword.Auto) : source.MinWidth.value }, { nameof(target.style.minHeight), target.style.minHeight = source.MinHeight.value == 0 ? new StyleLength(StyleKeyword.Auto) : source.MinHeight.value }, { nameof(target.style.flexBasis), target.style.flexBasis = source.FlexBasis.value == 0 ? new StyleLength(StyleKeyword.Auto) : source.FlexBasis.value }, { nameof(target.style.flexGrow), target.style.flexGrow = source.FlexGrow }, { nameof(target.style.flexShrink), target.style.flexShrink = source.FlexShrink }, { nameof(target.style.flexDirection), target.style.flexDirection = (FlexDirection)source.FlexDirection.value }, { nameof(target.style.flexWrap), target.style.flexWrap = (Wrap)source.FlexWrap.value }, { nameof(target.style.marginLeft), target.style.marginLeft = source.MarginLeft }, { nameof(target.style.marginTop), target.style.marginTop = source.MarginTop }, { nameof(target.style.marginRight), target.style.marginRight = source.MarginRight }, { nameof(target.style.marginBottom), target.style.marginBottom = source.MarginBottom }, { nameof(target.style.paddingLeft), target.style.paddingLeft = source.PaddingLeft }, { nameof(target.style.paddingTop), target.style.paddingTop = source.PaddingTop }, { nameof(target.style.paddingRight), target.style.paddingRight = source.PaddingRight }, { nameof(target.style.paddingBottom), target.style.paddingBottom = source.PaddingBottom }, { nameof(target.style.alignSelf), target.style.alignSelf = (Align)source.AlignSelf.value }, { nameof(target.style.unityTextAlign), target.style.unityTextAlign = (TextAnchor)source.UnityTextAlign.value }, { nameof(target.style.unityFontStyleAndWeight), target.style.unityFontStyleAndWeight = (FontStyle)source.UnityFontStyleAndWeight.value }, { nameof(target.style.fontSize), target.style.fontSize = source.FontSize }, { nameof(target.style.whiteSpace), target.style.whiteSpace = (WhiteSpace)source.WhiteSpace.value }, { nameof(target.style.color), target.style.color = source.Color }, { nameof(target.style.backgroundColor), target.style.backgroundColor = source.BackgroundColor }, { nameof(target.style.unityFont), target.style.unityFont = source.UnityFont }, { nameof(target.style.unityBackgroundScaleMode), target.style.unityBackgroundScaleMode = (ScaleMode)source.UnityBackgroundScaleMode.value }, { nameof(target.style.unityBackgroundImageTintColor), target.style.unityBackgroundImageTintColor = source.UnityBackgroundImageTintColor }, { nameof(target.style.alignItems), target.style.alignItems = (Align)source.AlignItems.value }, { nameof(target.style.alignContent), target.style.alignContent = (Align)source.AlignContent.value }, { nameof(target.style.justifyContent), target.style.justifyContent = (Justify)source.JustifyContent.value }, { nameof(target.style.borderLeftColor), target.style.borderLeftColor = source.BorderLeftColor }, { nameof(target.style.borderRightColor), target.style.borderRightColor = source.BorderRightColor }, { nameof(target.style.borderTopColor), target.style.borderTopColor = source.BorderTopColor }, { nameof(target.style.borderBottomColor), target.style.borderBottomColor = source.BorderBottomColor }, { nameof(target.style.borderLeftWidth), target.style.borderLeftWidth = source.BorderLeftWidth }, { nameof(target.style.borderRightWidth), target.style.borderRightWidth = source.BorderRightWidth }, { nameof(target.style.borderTopWidth), target.style.borderTopWidth = source.BorderTopWidth }, { nameof(target.style.borderBottomWidth), target.style.borderBottomWidth = source.BorderBottomWidth }, { nameof(target.style.borderTopLeftRadius), target.style.borderTopLeftRadius = source.BorderTopLeftRadius }, { nameof(target.style.borderTopRightRadius), target.style.borderTopRightRadius = source.BorderTopRightRadius }, { nameof(target.style.borderBottomLeftRadius), target.style.borderBottomLeftRadius = source.BorderBottomLeftRadius }, { nameof(target.style.borderBottomRightRadius), target.style.borderBottomRightRadius = source.BorderBottomRightRadius }, { nameof(target.style.opacity), target.style.opacity = source.Opacity.value }, { nameof(target.style.visibility), target.style.visibility = (Visibility)source.Visibility.value }, { nameof(target.style.display), target.style.display = (DisplayStyle)source.Display.value } }; //styleValues.Add(nameof(target.style. ),target.style.left = source.left); //styleValues.Add(nameof(target.style. ),target.style.top = source.top); //styleValues.Add(nameof(target.style. ),target.style.right = source.right); //styleValues.Add(nameof(target.style. ),target.style.bottom = source.bottom); //styleValues.Add(nameof(target.style. ),target.style.position = source.position); //styleValues.Add(nameof(target.style. ),target.style.unitySliceLeft = source.unitySliceLeft); //styleValues.Add(nameof(target.style. ),target.style.unitySliceTop = source.unitySliceTop); //styleValues.Add(nameof(target.style. ),target.style.unitySliceRight = source.unitySliceRight); //styleValues.Add(nameof(target.style. ),target.style.unitySliceBottom = source.unitySliceBottom); if (!buildTable) { return(target); } var table = new TableBuilder(); table.WithHeader("Target", "Name", "Type", "Value"); styleValues.ForEach(x => { table.WithRow(source.SourceName, x.Key, x.Value.GetType().Name, x.Value.ToString()); }); table.ToConsole(); return(target); }