Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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"]);
        }
Exemplo n.º 3
0
        protected override bool Init(object controller, object binding, DefinitionFile definition)
        {
            if (!base.Init(controller, binding, definition))
            {
                return(false);
            }

            DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(UiSpritePresenter));

            _spriteInstance          = DefinitionResolver.Get <Sprite>(Controller, Binding, file["Sprite"], null).CreateInstance();
            _spriteInstance.Sequence = DefinitionResolver.GetString(Controller, Binding, file["Sequence"]);

            return(true);
        }
Exemplo n.º 4
0
        protected override bool Init(object controller, object binding, DefinitionFile definition)
        {
            if (!base.Init(controller, binding, definition))
            {
                return(false);
            }

            DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(UiEditBoxBase));

            Hint = DefinitionResolver.GetSharedString(Controller, Binding, file["Hint"]) ?? new SharedString();

            _maxLength           = DefinitionResolver.Get(Controller, Binding, file["MaxLength"], int.MaxValue);
            _inputType           = DefinitionResolver.Get(Controller, Binding, file["InputType"], TextInputType.NormalText);
            _lostFocusCancels    = DefinitionResolver.Get(Controller, Binding, file["CancelOnLostFocus"], false);
            _focusedShared       = DefinitionResolver.GetShared(Controller, Binding, file["IsFocused"], false);
            _focusedShared.Value = false;

            string filter = DefinitionResolver.GetString(Controller, Binding, file["Filter"]);

            if (!filter.IsNullOrEmpty())
            {
                _filter = new List <char>(filter.ToCharArray());
            }

            _focusedShared.ValueChanged += (bool focused) =>
            {
                if (focused)
                {
                    CurrentlyFocused = this;
                }
                else if (CurrentlyFocused == this)
                {
                    CurrentlyFocused = null;
                }
            };

            if (_inputType == TextInputType.Password)
            {
                _password = new SharedString();
            }

            RegisterDelegate("TextApply", file["TextApply"]);
            RegisterDelegate("TextChanged", file["TextChanged"]);
            RegisterDelegate("TextCancel", file["TextCancel"]);

            RegisterDelegate("LostFocus", file["LostFocus"]);
            RegisterDelegate("Return", file["Return"]);

            return(true);
        }
Exemplo n.º 5
0
        protected override bool Init(object controller, object binding, DefinitionFile definition)
        {
            if (!base.Init(controller, binding, definition))
            {
                return(false);
            }

            DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(UiScrollBar));

            string id = DefinitionResolver.GetString(Controller, Binding, file["Context"]);

            _element       = Controller.Find(id) as IScrolledElement;
            _vertical      = DefinitionResolver.Get <Mode>(Controller, Binding, file["Mode"], Mode.Horizontal) == Mode.Vertical;
            _alwaysVisible = DefinitionResolver.Get <bool>(Controller, Binding, file["AlwaysVisible"], false);

            List <DefinitionFile> drawableFiles = file["ThumbDrawables"] as List <DefinitionFile>;

            if (drawableFiles != null)
            {
                foreach (var def in drawableFiles)
                {
                    ButtonDrawable drawable = def.CreateInstance(Controller, Binding) as ButtonDrawable;

                    if (drawable != null)
                    {
                        _thumbDrawables.Add(drawable);
                    }
                }
            }

            drawableFiles = file["TrackDrawables"] as List <DefinitionFile>;

            if (drawableFiles != null)
            {
                foreach (var def in drawableFiles)
                {
                    ButtonDrawable drawable = def.CreateInstance(Controller, Binding) as ButtonDrawable;

                    if (drawable != null)
                    {
                        _trackDrawables.Add(drawable);
                    }
                }
            }

            return(true);
        }
Exemplo n.º 6
0
        internal void Init(UiController controller, object binding, DefinitionFile definition)
        {
            DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(UiView));

            Width  = DefinitionResolver.Get <Length>(controller, binding, file["Width"], Length.Default);
            Height = DefinitionResolver.Get <Length>(controller, binding, file["Height"], Length.Default);
            Margin = DefinitionResolver.Get <Margin>(controller, binding, file["Margin"], Margin.None);

            HorizontalAlignment = DefinitionResolver.Get <HorizontalAlignment>(controller, binding, file["HorizontalAlignment"], HorizontalAlignment.Stretch);
            VerticalAlignment   = DefinitionResolver.Get <VerticalAlignment>(controller, binding, file["VerticalAlignment"], VerticalAlignment.Stretch);

            BindWidthId  = DefinitionResolver.GetString(controller, binding, file["BindWidth"]);
            BindHeightId = DefinitionResolver.GetString(controller, binding, file["BindHeight"]);

            X = DefinitionResolver.Get <Length>(controller, binding, file["X"], Length.Default);
            Y = DefinitionResolver.Get <Length>(controller, binding, file["Y"], Length.Default);

            if (X.IsAuto)
            {
                switch (HorizontalAlignment)
                {
                case Ui.HorizontalAlignment.Center:
                    X = new Length(0, 0.5);
                    break;

                case Ui.HorizontalAlignment.Right:
                    X = new Length(0, 1);
                    break;
                }
            }

            if (Y.IsAuto)
            {
                switch (VerticalAlignment)
                {
                case Ui.VerticalAlignment.Center:
                    Y = new Length(0, 0.5);
                    break;

                case Ui.VerticalAlignment.Bottom:
                    Y = new Length(0, 1);
                    break;
                }
            }
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        bool IDefinitionClass.Init(UiController controller, object binding, DefinitionFile definition)
        {
            DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(QuickColumnDefinition));

            Width = DefinitionResolver.Get <Length>(controller, binding, file["Width"], Length.Stretch);

            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);

            Font = new UiFont(font, fontSize, fontSpacing);

            LineHeight = DefinitionResolver.Get <int>(controller, binding, file["LineHeight"], 100);
            TextAlign  = DefinitionResolver.Get <TextAlign>(controller, binding, file["TextAlign"], TextAlign.Middle | TextAlign.Left);

            TextMargin = DefinitionResolver.Get <Margin>(controller, binding, file["TextMargin"], Margin.None);

            return(true);
        }
Exemplo n.º 9
0
        protected override bool Init(object controller, object binding, DefinitionFile definition)
        {
            if (!base.Init(controller, binding, definition))
            {
                return(false);
            }

            DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(UiNavigationView));

            string url = DefinitionResolver.GetString(Controller, binding, file["Page"]);

            if (!string.IsNullOrWhiteSpace(url))
            {
                DefinitionFile pageFile = ContentLoader.Current.Load <DefinitionFile>(url);

                NavigateTo(pageFile, new InvokeParameters());
                UiPage page = _children[0] as UiPage;
                page.InstantShow();
            }

            return(true);
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
        protected virtual bool Init(object controller, object binding, DefinitionFile definition)
        {
            DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(UiView));

            Type controllerType = file["Controller"] as Type;

            _controller = controller as UiController;

            if (controllerType != null)
            {
                var newController = Activator.CreateInstance(controllerType) as UiController;

                if (newController != null)
                {
                    newController.Parent = _controller;
                    Controller           = newController;
                }
            }

            Binding = binding;

            object bindParameter = file["Binding"];

            if (bindParameter != null)
            {
                Object bind = DefinitionResolver.GetValueFromMethodOrField(Controller, binding, bindParameter);

                if (bind != null)
                {
                    Binding = bind;
                }
            }

            Id = DefinitionResolver.GetString(Controller, Binding, file["Id"]);

            if (file["Hidden"] != null && file["Visible"] == null)
            {
                _visiblityFlag   = DefinitionResolver.GetShared <bool>(Controller, Binding, file["Hidden"], false);
                _visibleIsHidden = true;
            }
            else
            {
                _visiblityFlag = DefinitionResolver.GetShared <bool>(Controller, Binding, file["Visible"], true);
            }

            Tag = DefinitionResolver.GetSharedString(Controller, Binding, file["Tag"]);

            Opacity = DefinitionResolver.GetShared <double>(Controller, Binding, file["Opacity"], 1);

            DisplayVisibility = Visible ? 1 : 0;

            _modal = DefinitionResolver.Get <bool>(Controller, Binding, file["Modal"], false);

            RegisterDelegate("ViewRemoved", file["ViewRemoved"]);
            RegisterDelegate("ViewAdded", file["ViewAdded"]);
            RegisterDelegate("ViewActivated", file["ViewActivated"]);
            RegisterDelegate("ViewDeactivated", file["ViewDeactivated"]);
            RegisterDelegate("ViewResized", file["ViewResized"]);

            _minWidth  = DefinitionResolver.Get <Length>(Controller, Binding, file["MinWidth"], Length.Zero);
            _minHeight = DefinitionResolver.Get <Length>(Controller, Binding, file["MinHeight"], Length.Zero);

            _showSpeed = (float)Math.Max(
                DefinitionResolver.Get <double>(Controller, Binding, file["ShowHideTime"], -1),
                DefinitionResolver.Get <double>(Controller, Binding, file["ShowTime"], -1));

            if (_showSpeed < 0)
            {
                _showSpeed = DefaultShowTime;
            }

            _showSpeed /= 1000.0f;

            _showSpeed = _showSpeed > 0 ? 1 / _showSpeed : float.MaxValue;

            _hideSpeed = (float)Math.Max(
                DefinitionResolver.Get <double>(Controller, Binding, file["ShowHideTime"], -1),
                DefinitionResolver.Get <double>(Controller, Binding, file["HideTime"], -1));

            if (_hideSpeed < 0)
            {
                _hideSpeed = DefaultHideTime;
            }

            _hideSpeed /= 1000.0f;

            _hideSpeed = _hideSpeed > 0 ? 1 / _hideSpeed : float.MaxValue;

            CreatePositionParameters(Controller, Binding, definition);

            DefinitionFile backgroundDrawable = file["BackgroundDrawable"] as DefinitionFile;

            Color defaultBackgroundColor = Color.Transparent;

            if (backgroundDrawable != null)
            {
                BackgroundDrawable = backgroundDrawable.CreateInstance(Controller, Binding) as IBackgroundDrawable;

                if (BackgroundDrawable != null)
                {
                    defaultBackgroundColor = Color.White;
                }
            }

            _backgroundColor = DefinitionResolver.GetColorWrapper(Controller, Binding, file["BackgroundColor"]) ?? new ColorWrapper(defaultBackgroundColor);

            DefinitionFile showTransitionEffectFile       = file["ShowTransitionEffect"] as DefinitionFile;
            DefinitionFile hideTransitionEffectFile       = file["HideTransitionEffect"] as DefinitionFile;
            DefinitionFile parentShowTransitionEffectFile = file["ParentShowTransitionEffect"] as DefinitionFile;
            DefinitionFile parentHideTransitionEffectFile = file["ParentHideTransitionEffect"] as DefinitionFile;

            if (showTransitionEffectFile != null)
            {
                _showTransitionEffect = showTransitionEffectFile.CreateInstance(Controller, Binding) as TransitionEffect;
            }

            if (hideTransitionEffectFile != null)
            {
                _hideTransitionEffect = hideTransitionEffectFile.CreateInstance(Controller, Binding) as TransitionEffect;
            }

            if (parentShowTransitionEffectFile != null)
            {
                _parentShowTransitionEffect = parentShowTransitionEffectFile.CreateInstance(Controller, Binding) as TransitionEffect;
            }

            if (parentHideTransitionEffectFile != null)
            {
                _parentHideTransitionEffect = parentHideTransitionEffectFile.CreateInstance(Controller, Binding) as TransitionEffect;
            }

            return(true);
        }