コード例 #1
0
ファイル: UiScrollView.cs プロジェクト: jacekwicherek/Sitana
        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);
        }
コード例 #2
0
ファイル: UiBorder.cs プロジェクト: jacekwicherek/Sitana
        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);
        }
コード例 #3
0
        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));
                }
            }
        }
コード例 #4
0
        protected override Rectangle CalculateChildBounds(UiView view)
        {
            Rectangle childBounds = Bounds;

            int index = _tempChildren.IndexOf(view);

            if (index < 0)
            {
                return(new Rectangle(100000, 10000, 100, 100));
            }

            if (index == 0)
            {
                _currentWrapMax = 0;
                _currentWrapPos = Padding;

                _currentSize = 0;
            }

            PositionParameters parameters = _tempChildren[index].PositionParameters;

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

            if (_vertical)
            {
                Point size = view.ComputeSize(width, height);

                if (view.PositionParameters.Height.IsRest)
                {
                    int restParts = Math.Max(_restParts, 1);

                    size.Y = _rest * view.PositionParameters.Height.Rest / restParts;
                    size.Y = Math.Max(view.MinSize.Y, size.Y);
                }

                int posX = Padding + parameters.Margin.Left;

                if (!_wrap)
                {
                    switch (parameters.HorizontalAlignment)
                    {
                    case HorizontalAlignment.Center:
                        posX = (width - size.X) / 2;
                        break;

                    case HorizontalAlignment.Right:
                        posX = width - Padding - parameters.Margin.Right - size.X;
                        break;

                    case HorizontalAlignment.Stretch:
                        size.X = width - Padding * 2 - parameters.Margin.Width;
                        break;
                    }
                }

                int pos = Padding;

                if (index > 0)
                {
                    pos = _tempChildren[index - 1].Bounds.Bottom + _tempChildren[index - 1].PositionParameters.Margin.Bottom + Spacing;

                    if (_wrap)
                    {
                        posX = _currentWrapPos + view.Margin.Left;

                        _currentSize = Math.Max(pos, _currentSize);

                        if (pos + size.Y > Math.Ceiling(Bounds.Height + UiUnit.Unit))
                        {
                            pos = Padding;

                            _currentWrapPos = _currentWrapMax + Spacing;

                            int right = _currentWrapPos;
                            posX = right + parameters.Margin.Left;
                        }
                    }
                }

                childBounds.X     = posX;
                childBounds.Width = size.X;

                childBounds.Y      = pos + parameters.Margin.Top;
                childBounds.Height = size.Y;

                _currentWrapMax = Math.Max(_currentWrapMax, childBounds.Right + view.Margin.Right);
                _currentSize    = Math.Max(childBounds.Bottom + Padding, _currentSize);
            }
            else
            {
                Point size = view.ComputeSize(width, height);

                if (view.PositionParameters.Width.IsRest)
                {
                    int restParts = Math.Max(_restParts, 1);

                    size.X = _rest * view.PositionParameters.Width.Rest / restParts;
                    size.X = Math.Max(view.MinSize.X, size.X);
                }

                int posY = Padding + parameters.Margin.Top;

                if (!_wrap)
                {
                    switch (parameters.VerticalAlignment)
                    {
                    case VerticalAlignment.Center:
                        posY = (height - size.Y) / 2;
                        break;

                    case VerticalAlignment.Bottom:
                        posY = height - Padding - parameters.Margin.Bottom - size.Y;
                        break;

                    case VerticalAlignment.Stretch:
                        size.Y = height - Padding * 2 - parameters.Margin.Height;
                        break;
                    }
                }

                int pos = Padding;

                if (index > 0)
                {
                    pos = _tempChildren[index - 1].Bounds.Right + _tempChildren[index - 1].PositionParameters.Margin.Right + Spacing;

                    if (_wrap)
                    {
                        posY = _currentWrapPos + view.Margin.Top;

                        if (pos + size.X > Math.Ceiling(Bounds.Width + UiUnit.Unit))
                        {
                            pos = Padding;

                            _currentWrapPos = _currentWrapMax + Spacing;

                            int bottom = _currentWrapPos;
                            posY = bottom + parameters.Margin.Top;
                        }
                    }
                }

                childBounds.X     = pos + parameters.Margin.Left;
                childBounds.Width = size.X;

                childBounds.Y      = posY;
                childBounds.Height = size.Y;

                _currentWrapMax = Math.Max(_currentWrapMax, childBounds.Bottom + view.Margin.Bottom);
                _currentSize    = Math.Max(childBounds.Right + Padding, _currentSize);
            }

            _updateBounds |= view.Bounds != childBounds;

            return(childBounds);
        }
コード例 #5
0
ファイル: UiView.cs プロジェクト: jacekwicherek/Sitana
 void CreatePositionParameters(UiController controller, object binding, DefinitionFile file)
 {
     PositionParameters = new PositionParameters();
     PositionParameters.Init(controller, binding, file);
 }
コード例 #6
0
ファイル: UiView.cs プロジェクト: jacekwicherek/Sitana
        public static void Parse(XNode node, DefinitionFile file)
        {
            var parser = new DefinitionParser(node);

            file["Id"] = parser.ParseString("Id");

            string controller     = node.Attribute("Controller");
            Type   controllerType = null;

            if (!string.IsNullOrEmpty(controller))
            {
                controllerType = Type.GetType(controller);
                if (controllerType == null)
                {
                    throw new Exception(string.Format("Cannot find controller type: {0}.", controller));
                }
            }

            file["Controller"] = controllerType;

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

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

            file["Visible"] = parser.ParseBoolean("Visible");
            file["Hidden"]  = parser.ParseBoolean("Hidden");

            file["BackgroundColor"] = parser.ParseColor("BackgroundColor");

            file["Opacity"] = parser.ParseDouble("Opacity");

            file["ViewRemoved"] = parser.ParseDelegate("ViewRemoved");
            file["ViewAdded"]   = parser.ParseDelegate("ViewAdded");

            file["ViewActivated"]   = parser.ParseDelegate("ViewActivated");
            file["ViewDeactivated"] = parser.ParseDelegate("ViewDeactivated");

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

            file["MinWidth"]  = parser.ParseLength("MinWidth", false);
            file["MinHeight"] = parser.ParseLength("MinHeight", false);

            file["ShowHideTime"] = parser.ParseDouble("ShowHideTime");

            file["HideTime"] = parser.ParseDouble("HideTime");
            file["ShowTime"] = parser.ParseDouble("ShowTime");

            file["Tag"] = parser.ParseString("Tag");

            PositionParameters.Parse(node, file);

            foreach (var cn in node.Nodes)
            {
                if (cn.Tag == "UiView.BackgroundDrawable")
                {
                    if (cn.Nodes.Count != 1)
                    {
                        string error = node.NodeError("UiView.BackgroundDrawable must have exactly 1 child.");
                        if (DefinitionParser.EnableCheckMode)
                        {
                            ConsoleEx.WriteLine(error);
                        }
                        else
                        {
                            throw new Exception(error);
                        }
                    }

                    file["BackgroundDrawable"] = DefinitionFile.LoadFile(cn.Nodes[0]);
                }

                if (cn.Tag == "UiView.ShowTransitionEffect")
                {
                    if (cn.Nodes.Count != 1)
                    {
                        string error = node.NodeError("UiView.ShowTransitionEffect must have exactly 1 child.");
                        if (DefinitionParser.EnableCheckMode)
                        {
                            ConsoleEx.WriteLine(error);
                        }
                        else
                        {
                            throw new Exception(error);
                        }
                    }

                    file["ShowTransitionEffect"] = DefinitionFile.LoadFile(cn.Nodes[0]);
                }

                if (cn.Tag == "UiView.HideTransitionEffect")
                {
                    if (cn.Nodes.Count != 1)
                    {
                        string error = node.NodeError("UiView.HideTransitionEffect must have exactly 1 child.");
                        if (DefinitionParser.EnableCheckMode)
                        {
                            ConsoleEx.WriteLine(error);
                        }
                        else
                        {
                            throw new Exception(error);
                        }
                    }

                    file["HideTransitionEffect"] = DefinitionFile.LoadFile(cn.Nodes[0]);
                }

                if (cn.Tag == "UiView.ParentShowTransitionEffect")
                {
                    if (cn.Nodes.Count != 1)
                    {
                        string error = node.NodeError("UiView.NavigateToTransitionEffect must have exactly 1 child.");
                        if (DefinitionParser.EnableCheckMode)
                        {
                            ConsoleEx.WriteLine(error);
                        }
                        else
                        {
                            throw new Exception(error);
                        }
                    }

                    file["ParentShowTransitionEffect"] = DefinitionFile.LoadFile(cn.Nodes[0]);
                }

                if (cn.Tag == "UiView.ParentHideTransitionEffect")
                {
                    if (cn.Nodes.Count != 1)
                    {
                        string error = node.NodeError("UiView.NavigateFromTransitionEffect must have exactly 1 child.");
                        if (DefinitionParser.EnableCheckMode)
                        {
                            ConsoleEx.WriteLine(error);
                        }
                        else
                        {
                            throw new Exception(error);
                        }
                    }

                    file["ParentHideTransitionEffect"] = DefinitionFile.LoadFile(cn.Nodes[0]);
                }
            }
        }