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); }
public MarkSweepStyleSheet(IStyleSystem styleSystem) { this.StyleSystem = styleSystem; keys = new FlexibleList <IStyleKey>(); values = new FlexibleList <object>(); valuesTouched = new FlexibleList <bool>(); }
public object Parse(IStyleSystem styleSystem, XElement reader, IStylePropertyContext context) { if (reader == null) { return(new Insets()); } var element = reader.ElementLocal(elementName); if (element == null) { return(new Insets()); } var all = (int?)element.ElementLocal("all"); if (all != null) { return(new Insets(all.GetValueOrDefault())); } var top = (int?)element.ElementLocal("top"); var left = (int?)element.ElementLocal("left"); var bottom = (int?)element.ElementLocal("bottom"); var right = (int?)element.ElementLocal("right"); return(new Insets(top.GetValueOrDefault(), left.GetValueOrDefault(), bottom.GetValueOrDefault(), right.GetValueOrDefault())); }
public void SetUp() { // This test uses a 11x16 font. styleSystem = LayoutTestStyle.CreateStyleSystem(); textStyleDefinition = styleSystem.StylesFor <TextStyleDefinition>(); textStyle = LayoutTestStyle.CreateTextStyle(styleSystem); }
public void Write(IStyleSystem styleSystem, XContainer container, ICondition condition, IConditionWriter childWriter) { var idCond = (AttributeCondition)condition; var content = new XElement("attribute"); content.Add(new XElement("name", idCond.Property)); if (idCond.Value != null) { IStylePropertySerializer serializer; if (Find(idCond.Value, out serializer)) { var valueElement = new XElement("value"); serializer.Write(styleSystem, valueElement, idCond.Value); var id = serializer.TypeId ?? serializer.TargetType.FullName; content.Add(new XElement("type", id)); content.Add(valueElement); } else { throw new StyleParseException("There is no handle for attribute-condition value of " + idCond.Value.GetType(), container); } } container.Add(content); }
public void Write(IStyleSystem styleSystem, XContainer container, ICondition condition, IConditionWriter childWriter) { var a = (AndCondition)condition; childWriter.Write(styleSystem, container, a.First, childWriter); childWriter.Write(styleSystem, container, a.Second, childWriter); }
public static IStyleWriter CreateWriter(this IStyleSystem s) { var w = new StyleWriter(s); s.ConfigureStyleSerializer(w); return(w); }
public static IStyleParser CreateParser(this IStyleSystem s, GraphicsDevice graphicsDevice = null) { var parser = new StyleParser(s, graphicsDevice); s.ConfigureStyleSerializer(parser); return(parser); }
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); }
public void Write(IStyleSystem styleSystem, XContainer container, ICondition condition, IConditionWriter childWriter) { var n = (NotCondition)condition; var notElement = new XElement("not"); childWriter.Write(styleSystem, notElement, n.Condition, childWriter); container.Add(notElement); }
public virtual IEnumerable <IStyleRule> LoadRules(IStyleSystem style) { var b = new StyleBuilder(style); var rules = new List <IStyleRule>(); rules.AddRange(CreateStyleFor(b)); return(rules); }
public static IStyleSystem WithContext(this IStyleSystem s, string context) { if (string.IsNullOrEmpty(context)) { return(s); } return(new SubStyleSystem(s, context)); }
public SubStyleSystem(IStyleSystem parent, string context) { if (parent == null) { throw new ArgumentNullException(nameof(parent)); } this.parent = parent; this.ContentLoader = new SubContextContentLoader(parent.ContentLoader, context); }
public static IStyle CreateTextStyle(IStyleSystem styleSystem) { var textStyles = styleSystem.StylesFor <TextStyleDefinition>(); var style = new PresentationStyle(styleSystem); style.SetValue(textStyles.Font, CreateFont("CreateTextStyle[11,16]", 11, 16)); style.SetValue(textStyles.TextColor, Color.Black); return(style); }
public ResolvedStyle(IStyleSystem styleSystem, IWidget self) { this.self = self; StyleSystem = styleSystem; ResolvedStyles = new MarkSweepStyleSheet(styleSystem); elementStyle = styleSystem.CreatePresentationStyle(); elementStyle.ValueChanged += OnValueChanged; cachedValues = new FlexibleList <object>(); }
public StyleResolver(IStyleSystem styleSystem) { this.styleSystem = styleSystem; ruleFactory = new WidgetWatchRuleFactory(); registeredWidgets = new Dictionary <IWidget, WidgetChangeTracker>(); StyleRules = new ObservableCollection <IStyleRule>(); StyleRules.CollectionChanged += OnRuleCompositionChanged; onChildrenChangedHandler = OnChildrenChanged; affectedNodesSet = new HashSet <IWatchRule>(); styleRules = new List <IStyleRule>(); }
public void SetUp() { Count = 0; styleSystem = LayoutTestStyle.CreateStyleSystem(); var textStyle = LayoutTestStyle.CreateTextStyle(styleSystem); var documentView = Substitute.For <IDocumentView <ITextDocument> >(); documentView.Document.Returns((ITextDocument)null); documentView.Style.Returns(textStyle); this.doc = documentView; }
public void Write(IStyleSystem styleSystem, XContainer container, ICondition condition, IConditionWriter childWriter) { IConditionWriter w; if (writers.TryGetValue(condition.GetType(), out w)) { w.Write(styleSystem, container, condition, childWriter); } else { throw new StyleWriterException("There is no writer for condition " + condition.GetType().Name); } }
public StyleKey(IStyleSystem creator, int index, string name, Type valueType, bool inherit) : base(creator, index) { if (name == null) { throw new ArgumentNullException(nameof(name)); } if (valueType == null) { throw new ArgumentNullException(nameof(valueType)); } this.Name = name; this.ValueType = valueType; this.Inherit = inherit; }
public StyleWriter(IStyleSystem styleSystem) { StyleSystem = styleSystem; registeredKeys = new Dictionary <string, IStyleKey>(); propertyParsers = new Dictionary <Type, IStylePropertySerializer>(); conditionWriter = new ConditionWriter(); RegisterPropertyParsers(new BoolValueStylePropertySerializer()); RegisterPropertyParsers(new ColorValueStylePropertySerializer()); RegisterPropertyParsers(new FloatValueStylePropertySerializer()); RegisterPropertyParsers(new IntValueStylePropertySerializer()); RegisterPropertyParsers(new StringValueStylePropertySerializer()); RegisterPropertyParsers(new InsetsStylePropertySerializer()); }
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); }
public StyleParser(IStyleSystem styleSystem, [CanBeNull] GraphicsDevice graphicsDevice = null) { this.graphicsDevice = graphicsDevice; registeredKeys = new Dictionary <string, IStyleKey>(); propertyParsers = new Dictionary <Type, IStylePropertySerializer>(); typeParsers = new Dictionary <string, IStylePropertySerializer>(); StyleSystem = styleSystem; RegisterPropertyParsers(new BoolValueStylePropertySerializer()); RegisterPropertyParsers(new ColorValueStylePropertySerializer()); RegisterPropertyParsers(new FloatValueStylePropertySerializer()); RegisterPropertyParsers(new IntValueStylePropertySerializer()); RegisterPropertyParsers(new StringValueStylePropertySerializer()); RegisterPropertyParsers(new InsetsStylePropertySerializer()); }
public void Write(IStyleSystem styleSystem, XElement propertyElement, object value) { var texture = (IBoxTexture)value; var element = new XElement(StyleParser.StyleNamespace + "texture"); element.Add(new XElement(StyleParser.StyleNamespace + "name", texture.Name)); if (texture.CornerArea != Insets.Zero) { new InsetsStylePropertySerializer("corners").Write(styleSystem, element, texture.CornerArea); } if (texture.Margins != Insets.Zero) { new InsetsStylePropertySerializer("margins").Write(styleSystem, element, texture.Margins); } propertyElement.Add(element); }
public object Parse(IStyleSystem styleSystem, XElement property, IStylePropertyContext context) { var reader = property.ElementLocal("font"); if (reader == null) { throw new StyleParseException("Expected a valid font element.", property); } var texture = (string)reader.ElementLocal("name"); if (string.IsNullOrWhiteSpace(texture)) { throw new StyleParseException("Font name cannot be empty.", property); } return(styleSystem.ContentLoader.LoadFont(texture)); }
public object Parse(IStyleSystem styleSystem, XElement reader, IStylePropertyContext context) { string value = reader.Value; if (string.IsNullOrEmpty(value)) { throw new StyleParseException($"Missing value for enum {TargetType}", reader); } try { return(Enum.Parse(TargetType, value)); } catch { throw new StyleParseException($"Unable to parse enum value {value} for {TargetType}.", reader); } }
public object Parse(IStyleSystem styleSystem, XElement reader, IStylePropertyContext context) { var textureElement = reader.ElementLocal("texture"); var texture = (string)textureElement?.ElementLocal("name"); if (string.IsNullOrWhiteSpace(texture)) { texture = null; } var contentLoader = styleSystem.ContentLoader; var tp = (string)reader.ElementLocal("texture-packer") ?? "disabled"; if (tp == "auto") { return(context.ProcessTexture(contentLoader.LoadTexture(texture))); } return(contentLoader.LoadTexture(texture)); }
public void Write(IStyleSystem styleSystem, XElement propertyElement, object value) { var insets = (Insets)value; var insetsElement = new XElement(StyleParser.StyleNamespace + elementName); if (insets.Top == insets.Left && insets.Top == insets.Right && insets.Top == insets.Bottom) { insetsElement.Add(new XElement(StyleParser.StyleNamespace + "all", insets.Top.ToString(CultureInfo.InvariantCulture))); } else { insetsElement.Add(new XElement(StyleParser.StyleNamespace + "top", insets.Top.ToString(CultureInfo.InvariantCulture))); insetsElement.Add(new XElement(StyleParser.StyleNamespace + "left", insets.Left.ToString(CultureInfo.InvariantCulture))); insetsElement.Add(new XElement(StyleParser.StyleNamespace + "bottom", insets.Bottom.ToString(CultureInfo.InvariantCulture))); insetsElement.Add(new XElement(StyleParser.StyleNamespace + "right", insets.Right.ToString(CultureInfo.InvariantCulture))); } propertyElement.Add(insetsElement); }
public static ExposingTestChunk Create(string text, IStyleSystem styleSystem) { var length = text.Length; var node = Substitute.For <ITextNode>(); node.Document.TextAt(Arg.Any <int>(), Arg.Any <int>()).Returns(text); var startPos = Substitute.For <ITextPosition>(); startPos.Offset.Returns(0); var endPos = Substitute.For <ITextPosition>(); endPos.Offset.Returns(length); var chunk = new ExposingTestChunk(new TextProcessingRules(), node, LayoutTestStyle.CreateTextStyle(styleSystem), startPos, endPos); chunk.Initialize(); return(chunk); }
public void Write(IStyleSystem styleSystem, XContainer container, ICondition condition, IConditionWriter childWriter) { var a = (OrCondition)condition; if (container.NodeType == XmlNodeType.Element) { var e = (XElement)container; if (e.Name == "or") { childWriter.Write(styleSystem, e, a.First, childWriter); childWriter.Write(styleSystem, e, a.Second, childWriter); return; } } var orElement = new XElement("or"); childWriter.Write(styleSystem, orElement, a.First, childWriter); childWriter.Write(styleSystem, orElement, a.Second, childWriter); container.Add(orElement); }
public object Parse(IStyleSystem styleSystem, XElement reader, IStylePropertyContext context) { var textureElement = reader.ElementLocal("texture"); var texture = (string)textureElement?.ElementLocal("name"); if (string.IsNullOrWhiteSpace(texture)) { texture = null; } var insets = (Insets) new InsetsStylePropertySerializer("corners").Parse(styleSystem, textureElement, context); var margins = (Insets) new InsetsStylePropertySerializer("margins").Parse(styleSystem, textureElement, context); var contentLoader = styleSystem.ContentLoader; var tp = (string)reader.ElementLocal("texture-packer") ?? "disabled"; if (tp == "auto") { return(context.ProcessTexture(contentLoader.LoadTexture(texture, insets, margins))); } return(contentLoader.LoadTexture(texture, insets, margins)); }