예제 #1
0
 public void Init(IStyleSystem s)
 {
     MinHeight         = s.CreateKey <int>("min-height", false);
     MaxHeight         = s.CreateKey <int>("max-height", false);
     MaxLinesVisible   = s.CreateKey <int>("max-lines-visible", false);
     UniformItemHeight = s.CreateKey <bool>("uniform-item-height", false);
 }
예제 #2
0
        public void Init(IStyleSystem s)
        {
            TooltipDelay       = s.CreateKey <float>("tooltip-delay", true);
            TooltipDisplayTime = s.CreateKey <float>("tooltip-display-time", true);
            TooltipPosition    = s.CreateKey <TooltipPositionMode>("tooltip-position", true);
            Visibility         = s.CreateKey <Visibility>("visibility", false);

            FrameTexture = s.CreateKey <IBoxTexture>("frame-texture", false);

            FrameOverlayTexture = s.CreateKey <IBoxTexture>("frame-overlay-texture", false);
            FrameOverlayColor   = s.CreateKey <Color>("frame-overlay-color", false);

            HoverOverlayTexture = s.CreateKey <IBoxTexture>("hover-overlay-texture", false);
            HoverOverlayColor   = s.CreateKey <Color>("hover-overlay-color", false);

            FocusedOverlayTexture = s.CreateKey <IBoxTexture>("focused-overlay-texture", false);
            FocusedOverlayColor   = s.CreateKey <Color>("focused-overlay-color", false);

            WidgetStateOverlay      = s.CreateKey <IBoxTexture>("widget-state-overlay", false);
            WidgetStateOverlayScale = s.CreateKey <bool>("widget-state-overlay-scale", false);
            WidgetStateOverlayColor = s.CreateKey <Color>("widget-state-overlay-color", false);

            Padding = s.CreateKey <Insets>("padding", false);
            Margin  = s.CreateKey <Insets>("margin", false);
            Color   = s.CreateKey <Color>("color", false);
        }
예제 #3
0
        bool TryGetValue(IStyleKey key, out object value)
        {
            var idx = StyleSystem.LinearIndexFor(key);

            value = cachedValues[idx];
            return(value != null);
        }
예제 #4
0
        public int LinearIndexFor(IStyleKey key)
        {
            var sk = key as SecretStyleKey;

            if (sk == null)
            {
                throw new ArgumentException();
            }
            return(sk.LinearIndex);
        }
예제 #5
0
        public bool IsRegisteredKey(IStyleKey key)
        {
            var sk = key as SecretStyleKey;

            if (sk == null)
            {
                return(false);
            }
            return(ReferenceEquals(sk.Creator, this));
        }
예제 #6
0
        public static T GetValue <T>(this IStyle style, IStyleKey <T> key, T defaultValue = default(T))
        {
            T val;

            if (style.GetValue(key, out val))
            {
                return(val);
            }
            return(defaultValue);
        }
예제 #7
0
 public void SetResolvedValue(IStyleKey key, object value)
 {
     if (ResolvedStyles.SetValue(key, value))
     {
         if (key.Inherit)
         {
             inheritableValuesChanged = true;
         }
         valueChanged = true;
     }
 }
예제 #8
0
        public bool IsExplicitlyInherited(IStyleKey key)
        {
            if (!StyleSystem.IsRegisteredKey(key))
            {
                throw new ArgumentException($"StyleKey {key} is not registered here.");
            }

            var index = StyleSystem.LinearIndexFor(key);

            return(InheritMarker.IsInheritMarker(values[index]));
        }
예제 #9
0
 public void Init(IStyleSystem s)
 {
     Font           = s.CreateKey <IUIFont>("font", true);
     TextColor      = s.CreateKey <Color>("text-color", true);
     Alignment      = s.CreateKey <Alignment>("text-alignment", true);
     OutlineColor   = s.CreateKey <Color>("outline-color", true);
     OutlineSize    = s.CreateKey <int>("outline-size", true);
     WrapText       = s.CreateKey <WrapText>("wrap-text", true);
     Underline      = s.CreateKey <bool>("underline", true);
     StrikeThrough  = s.CreateKey <bool>("strike-through", true);
     CaretWidth     = s.CreateKey <int>("caret-width", true);
     CaretBlinkRate = s.CreateKey <float>("caret-blink-rate", true);
     CaretBlinking  = s.CreateKey <bool>("caret-blinking", true);
     SelectionColor = s.CreateKey <Color>("selection-color", true);
 }
예제 #10
0
 public bool IsExplicitlyInherited(IStyleKey key)
 {
     if (!StyleSystem.IsRegisteredKey(key))
     {
         throw new ArgumentException($"StyleKey {key} is not registered here.");
     }
     if (elementStyle.IsExplicitlyInherited(key))
     {
         return(true);
     }
     if (ResolvedStyles.IsExplicitlyInherited(key))
     {
         return(true);
     }
     return(false);
 }
예제 #11
0
        public bool SetValue(IStyleKey key, object value)
        {
            var idx = StyleSystem.LinearIndexFor(key);

            cachedValues[idx] = null;
            if (elementStyle.SetValue(key, value))
            {
                if (key.Inherit || InheritMarker.IsInheritMarker(value))
                {
                    // inherited styles are distributed to child elements, so we need to explicitly clear them all.
                    self.InvalidateStyle(false);
                }

                self.InvalidateLayout();
                return(true);
            }
            return(false);
        }
예제 #12
0
        public bool GetValue <T>(IStyleKey key, out T value)
        {
            if (!StyleSystem.IsRegisteredKey(key))
            {
                throw new ArgumentException();
            }

            var index = StyleSystem.LinearIndexFor(key);
            var o     = values[index];

            if (o is T)
            {
                value = (T)o;
                return(true);
            }
            value = default(T);
            return(false);
        }
예제 #13
0
        public bool GetValue <T>(IStyleKey key, out T value)
        {
            if (elementStyle.GetValue(key, out value))
            {
                return(true);
            }
            if (!elementStyle.IsExplicitlyInherited(key))
            {
                if (ResolvedStyles.GetValue(key, out value))
                {
                    return(true);
                }
                if (!ResolvedStyles.IsExplicitlyInherited(key) && !key.Inherit)
                {
                    value = default(T);
                    return(false);
                }
            }

            // inheritance is potentially expensive, as we may traverse multiple
            // layers to get to the bottom of the tree. Caching is mandatory.
            object cachedValue;

            if (TryGetValue(key, out cachedValue))
            {
                value = (T)cachedValue;
                return(true);
            }

            var parentStyle = Self.GetStyleParent()?.Style;

            if (parentStyle != null)
            {
                if (parentStyle.GetValue(key, out value))
                {
                    Store(key, value);
                    return(true);
                }
            }

            value = default(T);
            Store(key, value);
            return(false);
        }
예제 #14
0
        private static          IStyleKeyPart[] GetKey(ILayoutable control, out int hash)
        {
            hash = control.Name.GetHashCode();
            List <IStyleKeyPart> key;
            var parent = control.Parent as ILayoutable;

            if (parent != null)
            {
                int             parentHash;
                IStyleKeyPart[] parentParts;

                if (parent.StyleKey != null)
                {
                    IStyleKey parentKey = parent.StyleKey;
                    parentParts = parentKey.Parts;
                    parentHash  = parentKey.GetHashCode();
                }
                else
                {
                    parentParts = GetKey(parent, out parentHash);
                }
                key = new List <IStyleKeyPart>(parentParts.Length + 1);
                key.AddRange(parentParts);
                hash ^= parentHash;
            }
            else
            {
                key = new List <IStyleKeyPart>(1);
            }

            string cssClass = control.CssClass;

            if (!string.IsNullOrEmpty(cssClass))
            {
                cssClass = cssClass.ToLower();
                hash    ^= cssClass.GetHashCode();
            }

            key.Add(!string.IsNullOrEmpty(cssClass)
                ? new Part(control.Name.ToLower(), cssClass)
                : new Part(control.Name.ToLower()));

            return(key.ToArray());
        }
예제 #15
0
        public bool SetValue(IStyleKey key, object value)
        {
            if (!StyleSystem.IsRegisteredKey(key))
            {
                throw new ArgumentException();
            }

            if (!InheritMarker.IsInheritMarker(value) && value != null && !key.ValueType.IsInstanceOfType(value))
            {
                throw new ArgumentException();
            }

            var index   = StyleSystem.LinearIndexFor(key);
            var changed = !Equals(values[index], value);

            values[index] = value;

            if (changed)
            {
                ValueChanged?.Invoke(this, new StyleEventArgs(key));
            }
            return(changed);
        }
예제 #16
0
        public bool SetValue(IStyleKey key, object value)
        {
            if (!StyleSystem.IsRegisteredKey(key))
            {
                throw new ArgumentException();
            }

            if (!InheritMarker.IsInheritMarker(value) && value != null && !key.ValueType.IsInstanceOfType(value))
            {
                throw new ArgumentException();
            }

            var index   = StyleSystem.LinearIndexFor(key);
            var changed = !Equals(values[index], value);

            if (changed)
            {
                values[index] = value;
            }
            keys[index]          = key;
            valuesTouched[index] = true;
            return(changed);
        }
예제 #17
0
 public static IPredefinedStyleBuilder WithBox(this IPredefinedStyleBuilder style, IStyleKey <IBoxTexture> key, string value, Insets insets)
 {
     return(WithBox(style, key, value, insets, Insets.Zero));
 }
예제 #18
0
 public void Init(IStyleSystem s)
 {
     IconTextGap = s.CreateKey <int>("icon-text-gap", false);
 }
예제 #19
0
 public bool IsRegisteredKey(IStyleKey key)
 {
     return(this.parent.IsRegisteredKey(key));
 }
예제 #20
0
 public int LinearIndexFor(IStyleKey key)
 {
     return(this.parent.LinearIndexFor(key));
 }
예제 #21
0
        void Store(IStyleKey key, object value)
        {
            var idx = StyleSystem.LinearIndexFor(key);

            cachedValues[idx] = value;
        }
예제 #22
0
 public void Init(IStyleSystem s)
 {
     DownOverlay      = s.CreateKey <IBoxTexture>("down-overlay", false);
     DownOverlayColor = s.CreateKey <Color>("down-overlay-color", false);
 }
예제 #23
0
 public StyleEventArgs(IStyleKey key)
 {
     Key = key;
 }
 public void Init(IStyleSystem s)
 {
     NotebookTabOverlapX = s.CreateKey <int>("notebook-tab-overlap-x", false);
     NotebookTabOverlapY = s.CreateKey <int>("notebook-tab-overlap-y", false);
 }
예제 #25
0
 public static IPredefinedStyleBuilder WithValue <T>(this IPredefinedStyleBuilder style, IStyleKey <T> key, T value)
 {
     style.SetValue(key, value);
     return(style);
 }
예제 #26
0
 public static IPredefinedStyleBuilder WithTexture(this IPredefinedStyleBuilder style, IStyleKey <IUITexture> key, string value)
 {
     style.SetValue(key, style.ContentLoader.LoadTexture(value));
     return(style);
 }
예제 #27
0
 public void SetValue <T>(IStyleKey <T> key, T value)
 {
     Style.SetValue(key, value);
 }
예제 #28
0
 internal static void Add(IStyleKey key)
 {
     keys.Add(key.Name, key);
 }
예제 #29
0
 public static bool TryGetByName(string name, [MaybeNullWhen(false)] out IStyleKey styleKey)
 {
     return(keys.TryGetValue(name, out styleKey));
 }
예제 #30
0
 public static IPredefinedStyleBuilder WithBox(this IPredefinedStyleBuilder style, IStyleKey <IBoxTexture> key, string value, Insets insets, Insets margin)
 {
     style.SetValue(key, style.ContentLoader.LoadTexture(value, insets, margin));
     return(style);
 }