Example #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:NewWidgets.Widgets.Widget"/> class for internal use
 /// </summary>
 /// <param name="styles">Styles.</param>
 internal protected Widget(WidgetStyleSheet[] styles)
     : base(null)
 {
     Size        = new Vector2(0, 0);
     m_styleType = WidgetStyleType.Normal;
     m_styles    = styles; // use the same styles as parent
 }
Example #2
0
 protected void DelayedSwitchStyle(WidgetStyleType styleType)
 {
     Animator.StartCustomAnimation(this, AnimationKind.Custom, null, 1, null,
                                   delegate {
         SwitchStyle(styleType);
     });
 }
Example #3
0
 public override bool SwitchStyle(WidgetStyleType styleType)
 {
     if (base.SwitchStyle(styleType))
     {
         InvalidateLayout();
         return(true);
     }
     return(false);
 }
Example #4
0
        internal void SetProperty <T>(WidgetStyleType style, WidgetParameterIndex index, T value)
        {
            if (!HasStyle(style))
            {
                throw new ArgumentException("Widget doesn't have style " + style + " assigned!");
            }

            m_styles[(int)style].Set(m_styles, index, value);
        }
Example #5
0
        internal T GetProperty <T>(WidgetStyleType style, WidgetParameterIndex index, T defaultValue)
        {
            if (!HasStyle(style))
            {
                style = m_styleType;
            }

            return(m_styles[(int)style].Get(index, defaultValue));
        }
Example #6
0
        public override bool SwitchStyle(WidgetStyleType styleType)
        {
            if (base.SwitchStyle(styleType))
            {
                m_label.SwitchStyle(styleType);
                m_image.SwitchStyle(styleType);

                return(true);
            }
            return(false);
        }
Example #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:NewWidgets.Widgets.Widget"/> class.
        /// </summary>
        /// <param name="style">Style.</param>
        protected Widget(WidgetStyleSheet style = default(WidgetStyleSheet))
            : base(null)
        {
            if (style.IsEmpty)
            {
                style = DefaultStyle;
            }
            Size = style.Get(WidgetParameterIndex.Size, new Vector2(0, 0));

            m_styleType = WidgetStyleType.Normal;

            m_styles = new WidgetStyleSheet[(int)WidgetStyleType.Max];

            LoadStyle(WidgetStyleType.Normal, style);
        }
Example #8
0
        /// <summary>
        /// Switches the style.
        /// </summary>
        /// <param name="styleType">Style type.</param>
        public virtual bool SwitchStyle(WidgetStyleType styleType)
        {
            if (!HasStyle(styleType))
            {
                return(false);
            }

            if (m_styleType == styleType)
            {
                return(false);
            }

            m_styleType = styleType;

            return(true);
        }
Example #9
0
        public void UpdateStyle()
        {
            WidgetStyleType type = WidgetStyleType.Normal;

            if (Selected)
            {
                type |= WidgetStyleType.Selected;
            }

            if (!Enabled)
            {
                type |= WidgetStyleType.Disabled;
            }

            if (Hovered)
            {
                type |= WidgetStyleType.Hovered;
            }

            if (!HasStyle(type)) // try to fall back
            {
                if (HasStyle(type & ~WidgetStyleType.Selected))
                {
                    type &= ~WidgetStyleType.Selected;
                }

                if (HasStyle(type & ~WidgetStyleType.Disabled))
                {
                    type &= ~WidgetStyleType.Disabled;
                }

                if (HasStyle(type & ~WidgetStyleType.Hovered))
                {
                    type &= ~WidgetStyleType.Hovered;
                }
            }

            if (HasStyle(type)) // only perform switch if we have where to switch
            {
                if (type == m_styleType)
                {
                    return;
                }

                DelayedSwitchStyle(type);
            }
        }
Example #10
0
        public override bool SwitchStyle(WidgetStyleType styleType)
        {
            if (base.SwitchStyle(styleType))
            {
                if (m_image != null)
                {
                    m_image.SwitchStyle(styleType);
                }

                if (m_linkedLabel != null)
                {
                    m_linkedLabel.SwitchStyle(styleType);
                }

                return(true);
            }
            return(false);
        }
Example #11
0
        /// <summary>
        /// Loads the style and possible sub-styles
        /// </summary>
        /// <param name="styleType">Style type.</param>
        /// <param name="style">Style.</param>
        public void LoadStyle(WidgetStyleType styleType, WidgetStyleSheet style)
        {
            if (style.IsEmpty)
            {
                return;
            }

            m_styles[(int)styleType] = style;

            // Hovered can be only subset of Normal, Disabled, Selected or SelectedDisabled
            if (styleType == WidgetStyleType.Normal || styleType == WidgetStyleType.Disabled || styleType == WidgetStyleType.Selected || styleType == WidgetStyleType.SelectedDisabled)
            {
                var hoveredStyleReference = style.Get(WidgetParameterIndex.HoveredStyle, default(WidgetStyleSheet));

                if (!hoveredStyleReference.IsEmpty)
                {
                    WidgetStyleType targetStyleType = 0;
                    switch (styleType)
                    {
                    case WidgetStyleType.Normal:
                        targetStyleType = WidgetStyleType.Hovered;
                        break;

                    case WidgetStyleType.Selected:
                        targetStyleType = WidgetStyleType.SelectedHovered;
                        break;

                    case WidgetStyleType.Disabled:
                        if (style.Name == m_styles[(int)WidgetStyleType.Normal].Name)
                        {
                            targetStyleType = 0;     // workaround to prevent using hovered style when disabled is set to same style as normal
                        }
                        else
                        {
                            targetStyleType = WidgetStyleType.DisabledHovered;
                        }
                        break;

                    case WidgetStyleType.SelectedDisabled:
                        targetStyleType = WidgetStyleType.SelectedDisabledHovered;
                        break;
                    }

                    if (targetStyleType != 0)
                    {
                        LoadStyle(targetStyleType, hoveredStyleReference);
                    }
                }
            }

            // Disabled can be only subset of Normal or Selected
            if (styleType == WidgetStyleType.Normal || styleType == WidgetStyleType.Selected)
            {
                var disabledStyleReference = style.Get(WidgetParameterIndex.DisabledStyle, default(WidgetStyleSheet));

                if (!disabledStyleReference.IsEmpty)
                {
                    WidgetStyleType targetStyleType = 0;
                    switch (styleType)
                    {
                    case WidgetStyleType.Normal:
                        targetStyleType = WidgetStyleType.Disabled;
                        break;

                    case WidgetStyleType.Selected:
                        targetStyleType = WidgetStyleType.SelectedDisabled;
                        break;
                    }

                    if (targetStyleType != 0)
                    {
                        LoadStyle(targetStyleType, disabledStyleReference);
                    }
                }
            }

            // Selected can be only subset of Normal
            if (styleType == WidgetStyleType.Normal)
            {
                var selectedStyleReference = style.Get(WidgetParameterIndex.SelectedStyle, default(WidgetStyleSheet));

                if (!selectedStyleReference.IsEmpty)
                {
                    LoadStyle(WidgetStyleType.Selected, selectedStyleReference);
                }

                var selectedHoveredStyleReference = style.Get(WidgetParameterIndex.SelectedHoveredStyle, default(WidgetStyleSheet));

                if (!selectedHoveredStyleReference.IsEmpty)
                {
                    LoadStyle(WidgetStyleType.SelectedHovered, selectedHoveredStyleReference);
                }
            }
        }
Example #12
0
 protected bool HasStyle(WidgetStyleType styleType)
 {
     return(!m_styles[(int)styleType].IsEmpty);
 }