public void TestMeasure(double availableWidth, double availableHeight)
        {
            var view     = new Mock <IButton>();
            var drawable = new ButtonDrawable(view.Object);
            var size     = drawable.Measure(availableWidth, availableHeight);

            Assert.Equal(new Size(DeviceInfo.ScalingFactor, DeviceInfo.ScalingFactor), size);
        }
        public void TestOnTouchUpDown()
        {
            var view      = new Mock <IButton>();
            var drawable  = new ButtonDrawable(view.Object);
            var exception = Record.Exception(() =>
            {
                var point = new GPoint(10, 10);
                drawable.OnTouchDown(point);
                drawable.OnTouchUp(point);
            });

            Assert.Null(exception);
        }
Ejemplo 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(UiSlider));

            _vertical = DefinitionResolver.Get <Mode>(Controller, Binding, file["Mode"], Mode.Horizontal) == Mode.Vertical;

            _maxValue = DefinitionResolver.GetShared <int>(Controller, Binding, file["MaxValue"], 100);
            _minValue = DefinitionResolver.GetShared <int>(Controller, Binding, file["MinValue"], 0);
            _value    = DefinitionResolver.GetShared <int>(Controller, Binding, file["Value"], 0);

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

            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);
        }
Ejemplo 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(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);
        }
        public void TestDraw(bool isEnabled, string text)
        {
            var view = new Mock <IButton>();

            view.Setup(x => x.Text).Returns(text);
            var canvas   = new Mock <ICanvas>();
            var drawable = new ButtonDrawable(view.Object);

            drawable.IsEnabled = isEnabled;
            Assert.Equal(isEnabled, drawable.IsEnabled);

            var exception = Record.Exception(() =>
            {
                drawable.Draw(canvas.Object, new RectF(0, 0, 100, 100));
            });

            Assert.Null(exception);
        }
Ejemplo n.º 6
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);
        }
Ejemplo 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(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);
        }