protected override void Init(UiController controller, object binding, DefinitionFile definition) { base.Init(controller, binding, definition); DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(Text)); string font = DefinitionResolver.GetString(controller, binding, file["Font"]); int fontSize = DefinitionResolver.Get <int>(controller, binding, file["FontSize"], 0); int fontSpacing = DefinitionResolver.Get <int>(controller, binding, file["FontSpacing"], 0); _lineHeight = DefinitionResolver.Get <int>(controller, binding, file["LineHeight"], 100); _font = new UiFont(font, fontSize, fontSpacing); _textRotation = DefinitionResolver.Get <TextRotation>(controller, binding, file["TextRotation"], TextRotation.None); HorizontalContentAlignment horzAlign = DefinitionResolver.Get <HorizontalContentAlignment>(controller, binding, file["HorizontalContentAlignment"], HorizontalContentAlignment.Center); VerticalContentAlignment vertAlign = DefinitionResolver.Get <VerticalContentAlignment>(controller, binding, file["VerticalContentAlignment"], VerticalContentAlignment.Center); _pathEllipsis = DefinitionResolver.Get <bool>(controller, binding, file["PathEllipsis"], false); _line = DefinitionResolver.Get <int>(controller, binding, file["Line"], -1); if (_pathEllipsis || _line >= 0) { _stringBuilder = new StringBuilder(); } _textAlign = UiHelper.TextAlignFromContentAlignment(horzAlign, vertAlign); _text = DefinitionResolver.GetSharedString(controller, binding, file["Text"]); }
protected override bool Init(object controller, object binding, DefinitionFile definition) { if (!base.Init(controller, binding, definition)) { return(false); } DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(UiText)); FontName = file["Font"] as string; FontSize = DefinitionResolver.Get <int>(Controller, Binding, file["FontSize"], 0); FontSpacing = DefinitionResolver.Get <int>(Controller, Binding, file["FontSpacing"], 0); LineHeight = DefinitionResolver.Get <int>(Controller, Binding, file["LineHeight"], 100); Justify = DefinitionResolver.Get <bool>(Controller, Binding, file["Justify"], false); _indent = DefinitionResolver.Get <Length>(Controller, Binding, file["Indent"], Length.Zero); _lineWidth = DefinitionResolver.Get <Length>(Controller, Binding, file["LineWidth"], Length.Stretch); Text = DefinitionResolver.GetString(Controller, Binding, file["Text"]) ?? string.Empty; TextColor = DefinitionResolver.GetColorWrapper(Controller, Binding, file["TextColor"]) ?? UiLabel.DefaultTextColor; HorizontalContentAlignment horzAlign = DefinitionResolver.Get <HorizontalContentAlignment>(Controller, Binding, file["HorizontalContentAlignment"], HorizontalContentAlignment.Left); VerticalContentAlignment vertAlign = DefinitionResolver.Get <VerticalContentAlignment>(Controller, Binding, file["VerticalContentAlignment"], VerticalContentAlignment.Top); TextAlign = UiHelper.TextAlignFromContentAlignment(horzAlign, vertAlign); return(true); }
protected override bool Init(object controller, object binding, DefinitionFile definition) { if (!base.Init(controller, binding, definition)) { return(false); } DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(UiStackPanel)); StackMode = DefinitionResolver.Get(Controller, Binding, file["Mode"], Mode.Vertical); _spacing = DefinitionResolver.Get(Controller, Binding, file["Spacing"], Length.Zero); _padding = DefinitionResolver.Get(Controller, Binding, file["Padding"], Length.Zero); _notifyParentOnResize = DefinitionResolver.Get(Controller, Binding, file["NotifyParentOnResize"], true); _wrap = DefinitionResolver.Get(Controller, Binding, file["Wrap"], false); _horizontalContentAlignment = DefinitionResolver.Get(Controller, Binding, file["HorizontalContentAlignment"], HorizontalContentAlignment.Left); _verticalContentAlignment = DefinitionResolver.Get(Controller, Binding, file["VerticalContentAlignment"], VerticalContentAlignment.Top); _expanded = DefinitionResolver.GetShared(Controller, Binding, file["Expanded"], true); _expandSpeed = DefinitionResolver.Get(Controller, Binding, file["ExpandTime"], 0); _collapseSpeed = DefinitionResolver.Get(Controller, Binding, file["CollapseTime"], (int)_expandSpeed); _expandedValue = _expanded.Value ? 1 : 0; if (_expandSpeed > 0) { _expandSpeed = 1000 / _expandSpeed; } else { _expandSpeed = 10000; } if (_collapseSpeed > 0) { _collapseSpeed = 1000 / _collapseSpeed; } else { _collapseSpeed = 10000; } RegisterDelegate("CollapseFinished", file["CollapseFinished"]); RegisterDelegate("ExpandFinished", file["ExpandFinished"]); RegisterDelegate("ExpandStarted", file["ExpandStarted"]); TryInitChildren(definition); _expanded.ValueChanged += _expanded_ValueChanged; return(true); }
protected override void Init(UiController controller, object binding, DefinitionFile definition) { base.Init(controller, binding, definition); DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(Icon)); _horzAlign = DefinitionResolver.Get <HorizontalContentAlignment>(controller, binding, file["HorizontalContentAlignment"], HorizontalContentAlignment.Center); _vertAlign = DefinitionResolver.Get <VerticalContentAlignment>(controller, binding, file["VerticalContentAlignment"], VerticalContentAlignment.Center); _stretch = DefinitionResolver.Get <Stretch>(controller, binding, file["Stretch"], Stretch.None); _scale = (float)DefinitionResolver.Get <double>(controller, binding, file["Scale"], 1); }
protected override void Init(UiController controller, object binding, DefinitionFile definition) { base.Init(controller, binding, definition); DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(Image)); _image = DefinitionResolver.Get <Texture2D>(controller, binding, file["Image"], null); _scale = DefinitionResolver.Get(controller, binding, file["Scale"], Scale.One); _horizontalAlignment = DefinitionResolver.Get <HorizontalContentAlignment>(controller, binding, file["HorizontalContentAlignment"], HorizontalContentAlignment.Center); _verticalAlignment = DefinitionResolver.Get <VerticalContentAlignment>(controller, binding, file["VerticalContentAlignment"], VerticalContentAlignment.Center); }
protected override bool Init(object controller, object binding, DefinitionFile definition) { if (!base.Init(controller, binding, definition)) { return(false); } DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(UiLabel)); string fontName = file["Font"] as string; int fontSize = DefinitionResolver.Get <int>(Controller, Binding, file["FontSize"], 0); int fontSpacing = DefinitionResolver.Get <int>(Controller, Binding, file["FontSpacing"], 0); _font = new UiFont(fontName, fontSize, fontSpacing); _lineHeight = DefinitionResolver.Get <int>(Controller, Binding, file["LineHeight"], 100); _textMargin = DefinitionResolver.Get <Margin>(Controller, Binding, file["TextMargin"], Margin.None); _rotation = DefinitionResolver.Get <TextRotation>(Controller, Binding, file["TextRotation"], TextRotation.None); _maxWidth = DefinitionResolver.Get <Length>(Controller, Binding, file["MaxWidth"], new Length(pixels: int.MaxValue)); Text = DefinitionResolver.GetSharedString(Controller, Binding, file["Text"]); if (Text == null) { return(false); } TextColor = DefinitionResolver.GetColorWrapper(Controller, Binding, file["TextColor"]) ?? DefaultTextColor; HorizontalContentAlignment horzAlign = DefinitionResolver.Get <HorizontalContentAlignment>(Controller, Binding, file["HorizontalContentAlignment"], HorizontalContentAlignment.Auto); VerticalContentAlignment vertAlign = DefinitionResolver.Get <VerticalContentAlignment>(Controller, Binding, file["VerticalContentAlignment"], VerticalContentAlignment.Auto); if (horzAlign == HorizontalContentAlignment.Auto) { horzAlign = UiHelper.ContentAlignFromAlignment(PositionParameters.HorizontalAlignment); } if (vertAlign == VerticalContentAlignment.Auto) { vertAlign = UiHelper.ContentAlignFromAlignment(PositionParameters.VerticalAlignment); } TextAlign = UiHelper.TextAlignFromContentAlignment(horzAlign, vertAlign); if (DefinitionResolver.Get <bool>(Controller, Binding, file["AutoSizeUpdate"], false)) { Text.ValueChanged += Text_ValueChanged; } return(true); }
protected override bool Init(object controller, object binding, DefinitionFile definition) { if (!base.Init(controller, binding, definition)) { return(false); } DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(UiIndexSelector)); var context = file["Context"]; if ((context is MethodName) || (context is FieldName)) { var obj = DefinitionResolver.GetValueFromMethodOrField(Controller, Binding, context); if (obj is IIndexedElement) { _element = obj as IIndexedElement; } else if (obj is string) { _context = obj as string; } } else { _context = DefinitionResolver.GetString(Controller, Binding, context); } if (_element == null) { _element = Controller.Find(_context) as IIndexedElement; } _spacing = DefinitionResolver.Get <Length>(Controller, Binding, file["Spacing"], Length.Zero); _vertical = DefinitionResolver.Get <Mode>(Controller, Binding, file["Mode"], Mode.Horizontal) == Mode.Vertical; _elementWidth = DefinitionResolver.Get <Length>(Controller, Binding, file["ElementWidth"], Length.Stretch); _elementHeight = DefinitionResolver.Get <Length>(Controller, Binding, file["ElementHeight"], Length.Stretch); _contentHorizontalAlignment = DefinitionResolver.Get <HorizontalContentAlignment>(Controller, Binding, file["HorizontalContentAlignment"], HorizontalContentAlignment.Center); _contentVerticalAlignment = DefinitionResolver.Get <VerticalContentAlignment>(Controller, Binding, file["VerticalContentAlignment"], VerticalContentAlignment.Center); return(true); }
public static TextAlign TextAlignFromContentAlignment(HorizontalContentAlignment horz, VerticalContentAlignment vert) { TextAlign align = TextAlign.None; switch (horz) { case HorizontalContentAlignment.Left: align |= TextAlign.Left; break; case HorizontalContentAlignment.Center: align |= TextAlign.Center; break; case HorizontalContentAlignment.Right: align |= TextAlign.Right; break; case HorizontalContentAlignment.Auto: align |= TextAlign.Center; break; } switch (vert) { case VerticalContentAlignment.Top: align |= TextAlign.Top; break; case VerticalContentAlignment.Center: align |= TextAlign.Middle; break; case VerticalContentAlignment.Bottom: align |= TextAlign.Bottom; break; case VerticalContentAlignment.Auto: align |= TextAlign.Middle; break; } return(align); }
protected override bool Init(object controller, object binding, DefinitionFile definition) { if (!base.Init(controller, binding, definition)) { return(false); } DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(UiStackPanel)); StackMode = DefinitionResolver.Get <Mode>(Controller, Binding, file["Mode"], Mode.Vertical); _spacing = DefinitionResolver.Get <Length>(Controller, Binding, file["Spacing"], Length.Zero); _padding = DefinitionResolver.Get <Length>(Controller, Binding, file["Padding"], Length.Zero); _notifyParentOnResize = DefinitionResolver.Get <bool>(Controller, Binding, file["NotifyParentOnResize"], true); _wrap = DefinitionResolver.Get <bool>(Controller, Binding, file["Wrap"], false); _horizontalContentAlignment = DefinitionResolver.Get <HorizontalContentAlignment>(Controller, Binding, file["HorizontalContentAlignment"], HorizontalContentAlignment.Left); _verticalContentAlignment = DefinitionResolver.Get <VerticalContentAlignment>(Controller, Binding, file["VerticalContentAlignment"], VerticalContentAlignment.Top); _expanded = DefinitionResolver.GetShared <bool>(Controller, Binding, file["Expanded"], true); _expandSpeed = DefinitionResolver.Get <int>(Controller, Binding, file["ExpandTime"], 0); _expandedValue = _expanded.Value ? 1 : 0; if (_expandSpeed > 0) { _expandSpeed = 1000 / _expandSpeed; } else { _expandSpeed = 10000; } InitChildren(Controller, Binding, definition); return(true); }
protected override bool Init(object controller, object binding, DefinitionFile definition) { if (!base.Init(controller, binding, definition)) { return(false); } DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(UiRichView)); string defaultFont = file["Font"] as string; int defaultFontSize = DefinitionResolver.Get <int>(Controller, Binding, file["FontSize"], 0); int defaultFontSpacing = DefinitionResolver.Get <int>(Controller, Binding, file["FontSpacing"], int.MaxValue); for (int idx = 0; idx < (int)FontType.Count; ++idx) { FontType type = (FontType)idx; string font = string.Format("{0}.Font", type); string spacing = string.Format("{0}.FontSpacing", type); string resize = string.Format("{0}.FontResize", type); string fontName = file[font] as string; int fontSpacing = DefinitionResolver.Get <int>(Controller, Binding, file[spacing], defaultFontSpacing == int.MaxValue ? 0 : defaultFontSpacing); int fontResize = DefinitionResolver.Get <int>(Controller, Binding, file[resize], 0); if (fontName == null) { fontName = defaultFont; } FontFace fontObj = FontManager.Instance.FindFont(fontName); if (defaultFont == null) { defaultFont = fontName; } if (defaultFontSpacing == int.MaxValue) { defaultFontSpacing = fontSpacing; } _fonts[idx] = new FontInfo() { Font = fontObj, FontSpacing = (float)fontSpacing / 1000.0f, FontResize = fontResize }; } for (int idx = 0; idx < (int)SizeType.Count; ++idx) { SizeType type = (SizeType)idx; string size = string.Format("{0}.FontSize", type); int fontSize = DefinitionResolver.Get <int>(Controller, Binding, file[size], defaultFontSize); if (defaultFontSize == 0) { defaultFontSize = fontSize; } _sizes[idx] = fontSize; } _bulletText = DefinitionResolver.GetString(Controller, Binding, file["BulletText"]) ?? "* "; //_bulletText = _bulletText.Replace(" ", ((char)0xa0).ToString()); _horizontalRulerHeight = DefinitionResolver.Get <Length>(Controller, Binding, file["HorizontalRulerHeight"], new Length(0, 0, 1)); _indentSize = DefinitionResolver.Get <Length>(Controller, Binding, file["Indent"], Length.Zero); _paragraphSpacing = DefinitionResolver.Get <Length>(Controller, Binding, file["ParagraphSpacing"], Length.Zero); _imageNotLoaded = DefinitionResolver.Get <Texture2D>(Controller, Binding, file["ImageNotLoaded"], AdvancedDrawBatch.OnePixelWhiteTexture); _lineHeight = (float)DefinitionResolver.Get <int>(Controller, Binding, file["LineHeight"], 100) / 100.0f; _justify = DefinitionResolver.Get <bool>(Controller, Binding, file["Justify"], false); _linkResolver = DefinitionResolver.Get <ILinkResolver>(Controller, Binding, file["LinkResolver"], this); _baseLineCorrection = DefinitionResolver.Get <bool>(Controller, Binding, file["EnableBaseLineCorrection"], false); Type processorType = file["Processor"] as Type; if (processorType != null) { _richProcessor = Activator.CreateInstance(processorType) as IRichProcessor; } Text = DefinitionResolver.GetString(Controller, Binding, file["Text"]); _colorNormal = DefinitionResolver.GetColorWrapper(Controller, Binding, file["TextColor"]) ?? UiLabel.DefaultTextColor; _colorClickable = DefinitionResolver.GetColorWrapper(Controller, Binding, file["LinkColor"]) ?? UiLabel.DefaultTextColor; _colorClickableActive = DefinitionResolver.GetColorWrapper(Controller, Binding, file["ActiveLinkColor"]) ?? _colorClickable; _colorRuler = DefinitionResolver.GetColorWrapper(Controller, Binding, file["HorizontalRulerColor"]) ?? UiLabel.DefaultTextColor; HorizontalContentAlignment horzAlign = DefinitionResolver.Get <HorizontalContentAlignment>(Controller, Binding, file["HorizontalContentAlignment"], HorizontalContentAlignment.Left); VerticalContentAlignment vertAlign = DefinitionResolver.Get <VerticalContentAlignment>(Controller, Binding, file["VerticalContentAlignment"], VerticalContentAlignment.Top); _textAlign = UiHelper.TextAlignFromContentAlignment(horzAlign, vertAlign); _clickMargin = DefinitionResolver.Get <Length>(Controller, Binding, file["ClickMargin"], Length.Zero); RegisterDelegate("UrlClick", file["UrlClick"]); EnabledGestures = (GestureType.Down | GestureType.Up | GestureType.Move | GestureType.Tap); return(true); }