Exemple #1
0
        public virtual void Remove(UiView view)
        {
            _children.Remove(view);

            view.ViewRemoved();
            OnChildrenModified();
        }
Exemple #2
0
 public override void Add(UiView view)
 {
     if (!_children.Contains(view))
     {
         throw new InvalidOperationException("Cannot add views to UiNavigationPage. Use NavigateTo instead.");
     }
 }
Exemple #3
0
        public new static void Parse(XNode node, DefinitionFile file)
        {
            UiView.Parse(node, file);

            var parser = new DefinitionParser(node);

            file["Text"]     = parser.ParseString("Text");
            file["Icon"]     = parser.ParseResource <Texture2D>("Icon");
            file["Click"]    = parser.ParseDelegate("Click");
            file["Hold"]     = parser.ParseDelegate("Hold");
            file["Enabled"]  = parser.ParseBoolean("Enabled");
            file["Disabled"] = parser.ParseBoolean("Disabled");

            file["RepeatStart"]    = parser.ParseInt("RepeatStart");
            file["RepeatInterval"] = parser.ParseInt("RepeatInterval");

            file["PushSound"]    = parser.ParseResource <SoundEffect>("PushSound");
            file["ReleaseSound"] = parser.ParseResource <SoundEffect>("ReleaseSound");
            file["ActionSound"]  = parser.ParseResource <SoundEffect>("ActionSound");

            file["GestureMargin"] = parser.ParseLength("GestureMargin");

            file["Mode"] = parser.ParseEnum <UiButtonMode>("Mode");

            foreach (var cn in node.Nodes)
            {
                switch (cn.Tag)
                {
                case "UiButton.Drawables":
                    ParseDrawables(cn, file, typeof(ButtonDrawable));
                    break;
                }
            }
        }
Exemple #4
0
        void IItemsConsumer.Removed(object item)
        {
            lock (_recalcLock)
            {
                _recalculate = true;
            }

            UiView view = null;

            lock (_childrenLock)
            {
                if (_bindingToElement.TryGetValue(item, out view))
                {
                    _bindingToElement.Remove(item);
                }
            }

            if (view != null)
            {
                UiTask.BeginInvoke(() =>
                {
                    view.ViewRemoved();
                    _children.Remove(view);
                });
            }
        }
Exemple #5
0
        public void ShowPrev()
        {
            int prev = _selectedIndex;

            while (_cycle)
            {
                _selectedIndex = (_selectedIndex + _children.Count - 1) % _children.Count;

                if (_children[_selectedIndex].Visible || prev == _selectedIndex)
                {
                    break;
                }
            }

            if (!_cycle)
            {
                _selectedIndex = Math.Max(_selectedIndex - 1, 0);
            }

            if (prev != _selectedIndex)
            {
                _transition = 1;
                _next       = false;
                _previous   = _children[prev];
                _current    = _children[_selectedIndex];
            }

            if (_sharedSelectedIndex != null)
            {
                _sharedSelectedIndex.Value = _selectedIndex;
            }
        }
Exemple #6
0
        public Scroller(UiView view, Mode mode, ScrollingService scrollingService)
        {
            _mode    = mode;
            _view    = view;
            _service = scrollingService;

            if (mode.HasFlag(Mode.BothDrag))
            {
                view.EnabledGestures = (GestureType.FreeDrag | GestureType.Down | GestureType.Up);
            }
            else if (mode.HasFlag(Mode.VerticalDrag))
            {
                view.EnabledGestures = (GestureType.VerticalDrag | GestureType.Down | GestureType.Up);
            }
            else if (mode.HasFlag(Mode.HorizontalDrag))
            {
                view.EnabledGestures = (GestureType.HorizontalDrag | GestureType.Down | GestureType.Up);
            }

            if (mode.HasFlag(Mode.HorizontalWheel) || mode.HasFlag(Mode.VerticalWheel))
            {
                view.EnabledGestures   |= (GestureType.MouseWheel);
                _wheelScrollsHorizontal = mode.HasFlag(Mode.HorizontalWheel);
            }
        }
Exemple #7
0
        public new static void Parse(XNode node, DefinitionFile file)
        {
            UiView.Parse(node, file);

            var parser = new DefinitionParser(node);

            file["Mode"]         = parser.ParseEnum <Mode>("Mode");
            file["MaxValue"]     = parser.ParseInt("MaxValue");
            file["MinValue"]     = parser.ParseInt("MinValue");
            file["Value"]        = parser.ParseInt("Value");
            file["ValueChanged"] = parser.ParseDelegate("ValueChanged");

            foreach (var cn in node.Nodes)
            {
                switch (cn.Tag)
                {
                case "UiSlider.ThumbDrawables":
                    ParseDrawables(cn, file, typeof(ButtonDrawable), "ThumbDrawables");
                    break;

                case "UiSlider.TrackDrawables":
                    ParseDrawables(cn, file, typeof(ButtonDrawable), "TrackDrawables");
                    break;
                }
            }
        }
Exemple #8
0
        public new static void Parse(XNode node, DefinitionFile file)
        {
            UiView.Parse(node, file);

            var parser = new DefinitionParser(node);

            file["Processor"] = Type.GetType(node.Attribute("Processor"));

            file["LinkResolver"] = parser.ParseDelegate("LinkResolver");

            file["ImageNotLoaded"] = parser.ParseResource <Texture2D>("ImageNotLoaded");

            file["EnableBaseLineCorrection"] = parser.ParseBoolean("EnableBaseLineCorrection");

            file["Text"]        = parser.ParseString("Text");
            file["Font"]        = parser.ValueOrNull("Font");
            file["FontSize"]    = parser.ParseInt("FontSize");
            file["FontSpacing"] = parser.ParseInt("FontSpacing");

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

                file[font]    = parser.ValueOrNull(font);
                file[spacing] = parser.ParseInt(spacing);
                file[resize]  = parser.ParseInt(resize);
            }

            for (int idx = 0; idx < (int)SizeType.Count; ++idx)
            {
                SizeType type = (SizeType)idx;
                string   size = string.Format("{0}.FontSize", type);

                file[size] = parser.ParseInt(size);
            }

            file["LineHeight"]       = parser.ParseInt("LineHeight");
            file["Indent"]           = parser.ParseLength("Indent");
            file["ParagraphSpacing"] = parser.ParseLength("ParagraphSpacing");

            file["Justify"] = parser.ParseBoolean("Justify");

            file["TextColor"]            = parser.ParseColor("TextColor");
            file["LinkColor"]            = parser.ParseColor("LinkColor");
            file["ActiveLinkColor"]      = parser.ParseColor("ActiveLinkColor");
            file["HorizontalRulerColor"] = parser.ParseColor("HorizontalRulerColor");

            file["HorizontalContentAlignment"] = parser.ParseEnum <HorizontalContentAlignment>("HorizontalContentAlignment");
            file["VerticalContentAlignment"]   = parser.ParseEnum <VerticalContentAlignment>("VerticalContentAlignment");

            file["BulletText"]            = parser.ParseString("BulletText");
            file["HorizontalRulerHeight"] = parser.ParseLength("HorizontalRulerHeight");

            file["ClickMargin"] = parser.ParseLength("ClickMargin");
            file["UrlClick"]    = parser.ParseDelegate("UrlClick");
        }
Exemple #9
0
        protected override Rectangle CalculateChildBounds(UiView view)
        {
            Point size             = view.ComputeSize(Bounds.Width, Bounds.Height);
            PositionParameters pos = view.PositionParameters;

            Rectangle childRect = new Rectangle(0, 0, size.X, size.Y);

            int posX = pos.X.Compute(Bounds.Width);
            int posY = pos.Y.Compute(Bounds.Height);

            switch (pos.HorizontalAlignment)
            {
            case HorizontalAlignment.Center:
                childRect.X = posX - size.X / 2;
                break;

            case HorizontalAlignment.Left:
                childRect.X = posX;
                break;

            case HorizontalAlignment.Right:
                childRect.X = posX - size.X;
                break;

            case HorizontalAlignment.Stretch:
                childRect.X     = 0;
                childRect.Width = Bounds.Width;
                break;
            }

            switch (pos.VerticalAlignment)
            {
            case VerticalAlignment.Center:
                childRect.Y = posY - size.Y / 2;
                break;

            case VerticalAlignment.Top:
                childRect.Y = posY;
                break;

            case VerticalAlignment.Bottom:
                childRect.Y = posY - size.Y;
                break;

            case VerticalAlignment.Stretch:
                childRect.Y      = 0;
                childRect.Height = Bounds.Height;
                break;
            }

            Rectangle bounds = childRect;
            Point     offset = _scroller != null ? ScrollPosition : Point.Zero;

            bounds.X -= offset.X;
            bounds.Y -= offset.Y;

            return(bounds);
        }
Exemple #10
0
        public new static void Parse(XNode node, DefinitionFile file)
        {
            UiView.Parse(node, file);

            var parser = new DefinitionParser(node);

            file["TopColor"]    = parser.ParseColor("TopColor");
            file["BottomColor"] = parser.ParseColor("BottomColor");
        }
Exemple #11
0
        public new static void Parse(XNode node, DefinitionFile file)
        {
            UiView.Parse(node, file);

            var parser = new DefinitionParser(node);

            file["LeftColor"]  = parser.ParseColor("LeftColor");
            file["RightColor"] = parser.ParseColor("RightColor");
        }
Exemple #12
0
        protected override Rectangle CalculateChildBounds(UiView view)
        {
            lock (_recalcLock)
            {
                _recalculate = true;
            }

            return(view.Bounds);
        }
Exemple #13
0
        public new static void Parse(XNode node, DefinitionFile file)
        {
            UiView.Parse(node, file);

            var parser = new DefinitionParser(node);

            file["Sprite"]   = parser.ParseResource <Sprite>("Sprite");
            file["Sequence"] = parser.ParseString("Sequence");
        }
Exemple #14
0
        public new static void Parse(XNode node, DefinitionFile file)
        {
            UiView.Parse(node, file);

            var parser = new DefinitionParser(node);

            file["Image"]       = parser.ParseResource <NinePatchImage>("Image");
            file["ScaleByUnit"] = parser.ParseBoolean("ScaleByUnit");
            file["Scale"]       = parser.ParseDouble("Scale");
            file["Color"]       = parser.ParseColor("Color");
        }
Exemple #15
0
 public void Switch(UiView child)
 {
     for (int idx = 0; idx < _children.Count; ++idx)
     {
         if (_children[idx] == child)
         {
             Switch(idx);
             return;
         }
     }
 }
Exemple #16
0
        protected override Rectangle CalculateChildBounds(UiView view)
        {
            Point size             = view.ComputeSize(Bounds.Width, Bounds.Height);
            PositionParameters pos = view.PositionParameters;

            Rectangle childRect = new Rectangle(0, 0, size.X, size.Y);

            int posX = pos.X.Compute(Bounds.Width);
            int posY = pos.Y.Compute(Bounds.Height);

            switch (pos.HorizontalAlignment)
            {
            case HorizontalAlignment.Center:
                childRect.X = posX - size.X / 2;
                break;

            case HorizontalAlignment.Left:
                childRect.X = posX;
                break;

            case HorizontalAlignment.Right:
                childRect.X = posX - size.X;
                break;

            case HorizontalAlignment.Stretch:
                childRect.X     = 0;
                childRect.Width = Bounds.Width;
                break;
            }

            switch (pos.VerticalAlignment)
            {
            case VerticalAlignment.Center:
                childRect.Y = posY - size.Y / 2;
                break;

            case VerticalAlignment.Top:
                childRect.Y = posY;
                break;

            case VerticalAlignment.Bottom:
                childRect.Y = posY - size.Y;
                break;

            case VerticalAlignment.Stretch:
                childRect.Y      = 0;
                childRect.Height = Bounds.Height;
                break;
            }

            pos.Margin.RepairRect(ref childRect, Bounds.Width, Bounds.Height);
            return(childRect);
        }
Exemple #17
0
        public new static void Parse(XNode node, DefinitionFile file)
        {
            UiView.Parse(node, file);

            var parser = new DefinitionParser(node);

            file["Image"]         = parser.ParseResource <Texture2D>("Image");
            file["Stretch"]       = parser.ParseEnum <Stretch>("Stretch");
            file["Color"]         = parser.ParseColor("Color");
            file["RotationSpeed"] = parser.ParseDouble("RotationSpeed");
            file["ScaleByUnit"]   = parser.ParseBoolean("ScaleByUnit");
            file["Scale"]         = parser.ParseDouble("Scale");
        }
Exemple #18
0
        internal void OnNeighboursInited()
        {
            if (!PositionParameters.BindHeightId.IsNullOrWhiteSpace() && Parent != null)
            {
                UiView view = Parent.FindChild(PositionParameters.BindHeightId);
                view.ViewSizeChanged += BindHeight_ViewSizeChanged;
            }

            if (!PositionParameters.BindWidthId.IsNullOrWhiteSpace() && Parent != null)
            {
                UiView view = Parent.FindChild(PositionParameters.BindWidthId);
                view.ViewSizeChanged += BindWidth_ViewSizeChanged;
            }
        }
Exemple #19
0
        public void Switch(int index)
        {
            _previous   = null;
            _transition = 0;
            _next       = false;

            _current       = _children[index];
            _selectedIndex = index;

            if (_sharedSelectedIndex != null)
            {
                _sharedSelectedIndex.Value = _selectedIndex;
            }
        }
Exemple #20
0
        public new static void Parse(XNode node, DefinitionFile file)
        {
            UiView.Parse(node, file);
            var parser = new DefinitionParser(node);

            file["Items"]     = parser.ParseDelegate("Items");
            file["Reversed"]  = parser.ParseBoolean("Reversed");
            file["RowHeight"] = parser.ParseLength("RowHeight");

            file["ExceedRule"]       = parser.ParseEnum <ScrollingService.ExceedRule>("ExceedRule");
            file["WheelScrollSpeed"] = parser.ParseDouble("WheelScrollSpeed");

            file["SeparatorHeight"] = parser.ParseLength("SeparatorHeight");

            file["MaxScrollExceed"] = parser.ParseLength("MaxScrollExceed");

            foreach (var cn in node.Nodes)
            {
                switch (cn.Tag)
                {
                case "UiQuickList.Columns":
                    ParseColumns(cn, file);
                    break;

                case "UiQuickList.Separator":
                {
                    if (cn.Nodes.Count != 1)
                    {
                        string error = node.NodeError("UiQuickList.Separator must have exactly 1 child.");

                        if (DefinitionParser.EnableCheckMode)
                        {
                            ConsoleEx.WriteLine(error);
                        }
                        else
                        {
                            throw new Exception(error);
                        }
                    }


                    DefinitionFile separatorDef = DefinitionFile.LoadFile(cn.Nodes[0]);
                    file["Separator"] = separatorDef;
                }
                break;
                }
            }
        }
Exemple #21
0
        public override void Remove(UiView view)
        {
            base.Remove(view);

            if (view == _current)
            {
                if (_children.Count > 0)
                {
                    _current = _children[Math.Min(_children.Count - 1, _selectedIndex)];
                }
                else
                {
                    _current = null;
                }
            }
        }
Exemple #22
0
        protected override void Update(float time)
        {
            base.Update(time);

            if (_transition > 0)
            {
                _transition -= _transitionSpeed * time;
                if (_transition <= 0)
                {
                    _transition = 0;
                    _previous   = null;
                }

                AppMain.Redraw(this);
            }
        }
        protected override Rectangle CalculateChildBounds(UiView view)
        {
            if (_children.Count < 2)
            {
                return(Bounds);
            }

            int width  = Bounds.Width;
            int height = Bounds.Height;

            if (_verticalSplit)
            {
                height -= _splitterSize;
            }
            else
            {
                width -= _splitterSize;
            }

            int index  = _children.IndexOf(view);
            int divide = _verticalSplit ? _splitterPosition.Compute(height) : _splitterPosition.Compute(width);

            PositionParameters parameters = _children[index].PositionParameters;

            if (index == 0)
            {
                if (_verticalSplit)
                {
                    return(new Rectangle(parameters.Margin.Left, parameters.Margin.Top, width - parameters.Margin.Width, divide - parameters.Margin.Height));
                }
                else
                {
                    return(new Rectangle(parameters.Margin.Left, parameters.Margin.Top, divide - parameters.Margin.Width, height - parameters.Margin.Height));
                }
            }
            else
            {
                if (_verticalSplit)
                {
                    return(new Rectangle(parameters.Margin.Left, parameters.Margin.Top + divide + _splitterSize, width - parameters.Margin.Width, height - divide - parameters.Margin.Height));
                }
                else
                {
                    return(new Rectangle(parameters.Margin.Left + divide + _splitterSize, parameters.Margin.Top, width - divide - parameters.Margin.Width, height - parameters.Margin.Height));
                }
            }
        }
Exemple #24
0
        public virtual void Insert(int index, UiView view)
        {
            if (!_children.Contains(view))
            {
                _children.Insert(index, view);
                view.Bounds = CalculateChildBounds(view);
                view.Parent = this;
                view.RegisterView();

                if (_added)
                {
                    view.ViewAdded();
                }

                OnChildrenModified();
            }
        }
Exemple #25
0
        public override void Add(UiView view)
        {
            if (!_children.Contains(view))
            {
                _children.Add(view);
                view.Parent = this;
                view.RegisterView();

                if (_added)
                {
                    view.ViewAdded();
                }

                OnChildrenModified();
                ShouldRecalcLayout();
            }
        }
Exemple #26
0
        void RecalculatePositionsAndScroll()
        {
            _updateScrollPosition = new Point((int)_scrollingService.ScrollPositionX, (int)_scrollingService.ScrollPositionY);
            Point position = new Point(-_updateScrollPosition.X, -_updateScrollPosition.Y);

            for (int idx = 0; idx < _itemViews.Count; ++idx)
            {
                UiView view = _itemViews[idx];

                bool      shouldRecalc = view.ShouldRecalc(false, false);
                Rectangle bounds       = shouldRecalc ? CalculateItemBounds(view) : view.Bounds;

                Point size = bounds.Size;

                if (_vertical)
                {
                    bounds.Height = size.Y;
                    bounds.Y      = position.Y + view.PositionParameters.Margin.Top;

                    position.Y = bounds.Bottom + view.PositionParameters.Margin.Bottom;
                }
                else
                {
                    bounds.Width = size.X;
                    bounds.X     = position.X + view.PositionParameters.Margin.Left;

                    position.X = bounds.Right + view.PositionParameters.Margin.Right;
                }

                if (shouldRecalc)
                {
                    view.Bounds = bounds;
                    view.ViewUpdate(0);
                }
                else
                {
                    Point offset = bounds.Location - view.Bounds.Location;
                    view.Move(offset);
                }

                _maxScroll = new Point(_updateScrollPosition.X + position.X, _updateScrollPosition.Y + position.Y);
            }
        }
Exemple #27
0
        public new static void Parse(XNode node, DefinitionFile file)
        {
            UiView.Parse(node, file);

            var parser = new DefinitionParser(node);

            file["Text"]        = parser.ParseString("Text");
            file["Font"]        = parser.ValueOrNull("Font");
            file["FontSize"]    = parser.ParseInt("FontSize");
            file["FontSpacing"] = parser.ParseInt("FontSpacing");
            file["LineHeight"]  = parser.ParseInt("LineHeight");
            file["Indent"]      = parser.ParseLength("Indent");

            file["LineWidth"] = parser.ParseLength("LineWidth");

            file["Justify"] = parser.ParseBoolean("Justify");

            file["TextColor"] = parser.ParseColor("TextColor");
            file["HorizontalContentAlignment"] = parser.ParseEnum <HorizontalContentAlignment>("HorizontalContentAlignment");
            file["VerticalContentAlignment"]   = parser.ParseEnum <VerticalContentAlignment>("VerticalContentAlignment");
        }
Exemple #28
0
        public new static void Parse(XNode node, DefinitionFile file)
        {
            UiView.Parse(node, file);

            var parser = new DefinitionParser(node);

            file["Text"]        = parser.ParseString("Text");
            file["Font"]        = parser.ValueOrNull("Font");
            file["FontSize"]    = parser.ParseInt("FontSize");
            file["FontSpacing"] = parser.ParseInt("FontSpacing");
            file["LineHeight"]  = parser.ParseInt("LineHeight");

            file["TextColor"] = parser.ParseColor("TextColor");
            file["HorizontalContentAlignment"] = parser.ParseEnum <HorizontalContentAlignment>("HorizontalContentAlignment");
            file["VerticalContentAlignment"]   = parser.ParseEnum <VerticalContentAlignment>("VerticalContentAlignment");

            file["AutoSizeUpdate"] = parser.ParseBoolean("AutoSizeUpdate");
            file["TextRotation"]   = parser.ParseEnum <TextRotation>("TextRotation");

            file["TextMargin"] = parser.ParseMargin("TextMargin");
        }
Exemple #29
0
        internal UiView FindChild(string id)
        {
            UiView found = _children.Find((v) => v.Id == id);

            if (found == null)
            {
                foreach (var ch in _children)
                {
                    if (ch is UiContainer)
                    {
                        found = (ch as UiContainer).FindChild(id);

                        if (found != null)
                        {
                            break;
                        }
                    }
                }
            }

            return(found);
        }
Exemple #30
0
        public void ScrollToChild(UiView view, bool vertical)
        {
            Rectangle myBounds   = ScreenBounds;
            Rectangle viewBounds = view.ScreenBounds;

            if (vertical)
            {
                float scrollPosition = _scrollingService.ScrollPositionY;

                if (viewBounds.Bottom > myBounds.Bottom)
                {
                    scrollPosition += viewBounds.Bottom - myBounds.Bottom;
                }

                if (viewBounds.Top < myBounds.Top)
                {
                    scrollPosition -= myBounds.Top - viewBounds.Top;
                }

                _scrollingService.ScrollPositionY = scrollPosition;
            }
            else
            {
                float scrollPosition = _scrollingService.ScrollPositionX;

                if (viewBounds.Right > myBounds.Right)
                {
                    scrollPosition += viewBounds.Right - myBounds.Right;
                }

                if (viewBounds.Left < myBounds.Left)
                {
                    scrollPosition -= myBounds.Left - viewBounds.Left;
                }

                _scrollingService.ScrollPositionX = scrollPosition;
            }
        }