Example #1
0
        public void Apply(IRenderElement rootElement, string defaultTheme)
        {
            RenderElementStack parentStack = new RenderElementStack();

            void ApplyRecurse(IRenderElement element, ITheme theme)
            {
                theme = ThemeOf(element, theme);

                theme.Apply(element, parentStack);

                if (element.Children == null)
                {
                    return;
                }

                try
                {
                    parentStack.PushParent(element);

                    foreach (var child in element.Children)
                    {
                        ApplyRecurse(child, theme);
                    }
                }
                finally
                {
                    parentStack.PopParent();
                }
            }

            var initialTheme = ThemeOf(rootElement, themes[defaultTheme]);

            ApplyRecurse(rootElement, initialTheme);
        }
Example #2
0
        public IEnumerable <IRenderElementStyleProperties> MatchElementStyle(
            IRenderElement element, RenderElementStack stack)
        {
            var match = MatchExecutor.FindMatch(element, stack);

            if (match != null)
            {
                yield return(new ThemeRenderElementStyle(this, match));
            }
        }
Example #3
0
        private RenderElementStack GetStack(IRenderElement tree, IRenderElement renderElement)
        {
            RenderElementStack temp = new RenderElementStack();

            bool Search(IRenderElement node)
            {
                if (node == renderElement)
                {
                    return(true);
                }

                if (node.Children == null)
                {
                    return(false);
                }

                foreach (var item in node.Children)
                {
                    if (Search(item))
                    {
                        temp.PushParent(node);
                        return(true);
                    }
                }

                return(false);
            }

            Search(tree).Should().BeTrue("Could not find element in tree.");

            // We need to reverse the stack
            RenderElementStack result = new RenderElementStack();

            while (temp.Count > 0)
            {
                result.PushParent(temp.PopParent());
            }

            return(result);
        }