예제 #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(UiSplitterView));

            SplitMode         = DefinitionResolver.Get <Mode>(Controller, Binding, file["Mode"], Mode.Vertical);
            _splitterPosition = DefinitionResolver.Get <Length>(Controller, Binding, file["Position"], new Length(0, 0.5));
            _splitterSize     = DefinitionResolver.Get <Length>(Controller, Binding, file["SplitterSize"], Length.Default).Compute(100);

            TryInitChildren(definition);

            return(true);
        }
예제 #2
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;
                }
            }
        }
예제 #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(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);
        }
예제 #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(UiImage));

            _image         = DefinitionResolver.GetShared <Texture2D>(Controller, Binding, file["Image"], null);
            _stretch       = DefinitionResolver.Get <Stretch>(Controller, Binding, file["Stretch"], Stretch.Uniform);
            _color         = DefinitionResolver.GetColorWrapper(Controller, Binding, file["Color"]) ?? new ColorWrapper();
            _rotationSpeed = (float)DefinitionResolver.Get <double>(Controller, Binding, file["RotationSpeed"], 0);
            _scaleByUnit   = DefinitionResolver.Get <bool>(Controller, Binding, file["ScaleByUnit"], true);
            _scale         = (float)DefinitionResolver.Get <double>(Controller, Binding, file["Scale"], 1);

            return(true);
        }
예제 #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(UiEditBoxBase));

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

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

            _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);
        }
예제 #6
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);
        }
예제 #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(UiRadioButton));

            SelectedValue = DefinitionResolver.GetShared <int>(Controller, Binding, file["SelectedValue"], -1);
            Value         = DefinitionResolver.Get <int>(Controller, Binding, file["Value"], 0);

            if (file["SubValue"] != null)
            {
                SubValue         = DefinitionResolver.Get <int>(Controller, Binding, file["SubValue"], 0);
                SelectedSubValue = DefinitionResolver.GetShared <int>(Controller, Binding, file["SelectedSubValue"], -1);
            }

            return(true);
        }
예제 #8
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(UiModalLayout));

            _touchOutsideToHide = DefinitionResolver.Get(Controller, Binding, file["TouchOutsideToHide"], false);

            _visiblityFlag = DefinitionResolver.GetShared(Controller, binding, file["Visible"], false);

            RegisterDelegate("ClickOutside", file["ClickOutside"]);

            if (!Visible)
            {
                DisplayVisibility = 0;
            }

            return(true);
        }
예제 #9
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"], 0);

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

            _textAlign = UiHelper.TextAlignFromContentAlignment(horzAlign, vertAlign);
            _text      = DefinitionResolver.GetSharedString(controller, binding, file["Text"]);
        }
예제 #10
0
        protected override bool Init(object controller, object binding, DefinitionFiles.DefinitionFile definition)
        {
            if (!base.Init(controller, binding, definition))
            {
                return(false);
            }

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

            _context = DefinitionResolver.GetValueFromMethodOrField(Controller, Binding, file["Context"]) as ISelectorContext;

            _elementHeight = DefinitionResolver.Get <Length>(Controller, Binding, file["ElementHeight"], Length.Zero);
            _spacing       = DefinitionResolver.Get <Length>(Controller, Binding, file["Spacing"], Length.Zero);

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

            _selectedPositionOffset = DefinitionResolver.Get <Length>(Controller, Binding, file["SelectedPositionOffset"], Length.Zero);

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

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

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

            EnabledGestures = GestureType.Tap | GestureType.Up | GestureType.Down | GestureType.VerticalDrag;

            return(true);
        }
예제 #11
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(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);
        }
예제 #12
0
        protected override void Init(UiController controller, object binding, DefinitionFile definition)
        {
            base.Init(controller, binding, definition);

            _power = DefinitionResolver.Get <double>(controller, binding, definition["Power"], 1);
        }
예제 #13
0
        protected override bool Init(object controller, object binding, DefinitionFile definition)
        {
            if (!base.Init(controller, binding, definition))
            {
                return(false);
            }

            TryInitChildren(definition);

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

            if (file["SelectedIndex"] is MethodName || file["SelectedIndex"] is FieldName)
            {
                object value = DefinitionResolver.GetValueFromMethodOrField(Controller, Binding, file["SelectedIndex"]);

                if (value is SharedValue <int> )
                {
                    _sharedSelectedIndex = value as SharedValue <int>;
                    _selectedIndex       = _sharedSelectedIndex.Value;
                }

                if (value is int)
                {
                    _selectedIndex = (int)value;
                }
            }
            else
            {
                _selectedIndex = DefinitionResolver.Get <int>(Controller, Binding, file["SelectedIndex"], 0);
            }

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

            double speed = DefinitionResolver.Get <double>(Controller, Binding, file["TransitionTime"], 500) / 1000.0;

            _transitionSpeed = (float)(speed > 0 ? 1 / speed : float.MaxValue);

            DefinitionFile transitionEffectFile = file["ShowTransitionEffectNext"] as DefinitionFile;

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

            transitionEffectFile = file["HideTransitionEffectNext"] as DefinitionFile;

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

            transitionEffectFile = file["ShowTransitionEffectPrev"] as DefinitionFile;

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

            transitionEffectFile = file["HideTransitionEffectPrev"] as DefinitionFile;

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

            transitionEffectFile = file["ShowTransitionEffect"] as DefinitionFile;

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

                if (_transitionEffectShowNext == null)
                {
                    _transitionEffectShowNext = transitionEffectFile.CreateInstance(Controller, Binding) as TransitionEffect;
                }
            }

            transitionEffectFile = file["HideTransitionEffect"] as DefinitionFile;

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

                if (_transitionEffectHideNext == null)
                {
                    _transitionEffectHideNext = transitionEffectFile.CreateInstance(Controller, Binding) as TransitionEffect;
                }
            }

            if (_transitionEffectHideNext == null)
            {
                if (_transitionEffectShowNext != null)
                {
                    _transitionEffectHideNext = _transitionEffectShowNext.Reverse();
                }
            }

            if (_transitionEffectHidePrev == null)
            {
                if (_transitionEffectShowPrev != null)
                {
                    _transitionEffectHidePrev = _transitionEffectShowPrev.Reverse();
                }
            }

            if (_children.Count > 0)
            {
                _current = _children[_selectedIndex];
            }

            _previous = null;

            return(true);
        }
예제 #14
0
파일: UiButton.cs 프로젝트: prepare/Sitana
        protected override bool Init(object controller, object binding, DefinitionFile definition)
        {
            if (!base.Init(controller, binding, definition))
            {
                return(false);
            }

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

            Icon = DefinitionResolver.GetShared <Texture2D>(Controller, Binding, file["Icon"], null);

            if (Icon == null)
            {
                Icon = new SharedValue <Texture2D>();
            }

            _gestureMargin = DefinitionResolver.Get <Margin>(Controller, Binding, file["GestureMargin"], Margin.None);

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

            if (_text == null)
            {
                _text = new SharedString();
            }

            if (file["Hold"] != null)
            {
                RegisterDelegate("Hold", file["Hold"]);
                _processHold = true;
            }

            RegisterDelegate("Release", file["Release"]);
            RegisterDelegate("Push", file["Push"]);

            RegisterDelegate("Click", file["Click"]);

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

            if (file["Disabled"] != null && file["Enabled"] == null)
            {
                _enabledFlag       = DefinitionResolver.GetShared <bool>(Controller, Binding, file["Disabled"], false);
                _enabledFlagInvert = true;
            }
            else
            {
                _enabledFlag       = DefinitionResolver.GetShared <bool>(Controller, Binding, file["Enabled"], true);
                _enabledFlagInvert = false;
            }

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

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

            _pushSound    = DefinitionResolver.Get <SoundEffect>(Controller, Binding, file["PushSound"], null);
            _releaseSound = DefinitionResolver.Get <SoundEffect>(Controller, Binding, file["ReleaseSound"], null);
            _actionSound  = DefinitionResolver.Get <SoundEffect>(Controller, Binding, file["ActionSound"], null);

            ButtonMode = DefinitionResolver.Get <UiButtonMode>(Controller, Binding, file["Mode"], UiButtonMode.Release);

            _repeatStart    = (float)DefinitionResolver.Get <int>(Controller, Binding, file["RepeatStart"], 0) / 1000f;
            _repeatInterval = (float)DefinitionResolver.Get <int>(Controller, Binding, file["RepeatInterval"], 0) / 1000f;

            return(true);
        }
예제 #15
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);
        }
예제 #16
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);
        }