// ------------------------------------- @AnimateCharacterSequence
        // ---------------------------------------------------------------
        /// <summary>
        /// Animate the height of target element to desired value
        /// </summary>
        /// <param name="target">VisualElement to animate</param>
        /// <param name="startColor">Initial height of element</param>
        /// <param name="endColor">Desired ending height after animation</param>
        /// <param name="cascadeMs">The length of time in which each subsequent animation in the sequence will be offset (in milliseconds)</param>
        /// <param name="durationMS">The amount of time in which the animation will complete from start to finish (in milliseconds)</param>
        /// <param name="reverse">Animation will play in reverse, from right to left</param>
        /// <param name="callback">Function that can be called when the animation is completed</param>
        public static List <ValueAnimation <StyleValues> > AnimCharacterSequence(this VisualElement target, Color startColor, Color endColor, int cascadeMs, int durationMS,
                                                                                 bool reverse    = false,
                                                                                 Action callback = null,
                                                                                 float flexBasis = default)
        {
            var animatedValues = new List <ValueAnimation <StyleValues> >();
            IEnumerable <string>    originalStyle = new List <string>();
            IEnumerable <string>    resolvedStyle = new List <string>();
            VisualElementStyleStore styleData     = new VisualElementStyleStore();
            var textString = "";

            Label labelRef = new Label();

            if (target is AnimatedLabel label)
            {
                labelRef             = label.GetLabel();
                textString           = label.text;
                styleData            = label.CreateStyleData();
                styleData.SourceName = target.name;
            }

            if (doDebug)
            {
                var table = new TableBuilder();
                table.WithHeader("Name", "Value", "GetProperties - AnimSeq - l-54");
                var fields = styleData.GetType().GetProperties().ToList();
                fields.ForEach(x => { table.WithRow(x.Name, x.GetValue(styleData)); });
                table.ToConsole();
            }

            new VisualElement().Create(out var animatedContainer).ToUSS(nameof(animatedContainer), "animated-label-container");
            animatedContainer.style.height = new StyleLength(StyleKeyword.Auto);

            List <Label> labelList = new List <Label>();

            for (int i = 0; i < textString.Length; i++)
            {
                Label animLabel = new Label();

                if (!doDebug)
                {
                    animLabel = styleData.FromStyleData(new Label(textString[i].ToString()));
                }
                else if (i == 0)
                {
                    animLabel = styleData.FromStyleData(new Label(textString[i].ToString()), doDebug);
                }

                if (!flexBasis.Equals(default))
Exemple #2
0
        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());
        }
Exemple #3
0
        //--------------------------------------------------------------------------------------------
        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);
        }
Exemple #4
0
        // -- 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);
        }