예제 #1
0
        public override int GetListItemIndexByScreenPosition(UIList control, Vector2 position)
        {
            var renderer = control.ParentContainer.Viewport.CanvasRenderer;

            if (renderer != null)
            {
                var rect = control.GetScreenRectangle();

                var rect2 = rect;
                rect2.Expand(-control.GetScreenOffsetByValue(new UIMeasureValueVector2(UIMeasure.Units, 2, 2)));

                var font = control.Font.Value;
                if (font == null)
                {
                    font = renderer.DefaultFont;
                }
                var fontSize         = control.GetFontSizeScreen();
                var itemSize         = GetListItemSizeScreen(control, renderer);
                var totalItemsHeight = itemSize * control.Items.Count;
                var scrollBar        = control.GetScrollBar();

                //items
                if (control.Items.Count != 0 && rect2.Contains(position))
                {
                    var positionY = rect2.Top;
                    if (scrollBar != null && scrollBar.VisibleInHierarchy && scrollBar.EnabledInHierarchy)
                    {
                        positionY -= scrollBar.Value;
                    }

                    for (int n = 0; n < control.Items.Count; n++)
                    {
                        var item          = control.Items[n];
                        var itemRectangle = new Rectangle(rect2.Left, positionY, rect2.Right, positionY + itemSize);
                        if (scrollBar != null && scrollBar.EnabledInHierarchy && scrollBar.VisibleInHierarchy)
                        {
                            itemRectangle.Right -= scrollBar.GetScreenSize().X;
                        }

                        if (itemRectangle.Intersects(rect2) && itemRectangle.Contains(position))
                        {
                            return(n);
                        }

                        positionY += itemSize;
                    }
                }
            }

            return(-1);
        }
예제 #2
0
        private void List_SelectedIndexChanged(UIList sender)
        {
            if (disableListSelectedIndexChangedEvent)
            {
                return;
            }

            SelectedIndex = sender.SelectedIndex;
            if (remainingTimeToClose == 0)
            {
                remainingTimeToClose = 0.2;
            }
            //sender.Visible = false;
        }
예제 #3
0
        /////////////////////////////////////////

        //!!!!тут? так?
        double GetListItemSizeScreen(UIList control, CanvasRenderer renderer)
        {
            //var font = control.Font.Value;
            //if( font == null )
            //	font = renderer.DefaultFont;
            //var fontSize = control.GetFontSizeScreen();

            var itemSize = control.ConvertOffsetY(control.ItemSize.Value, UIMeasure.Screen);

            //snap by pixel size
            if (renderer.IsScreen)
            {
                itemSize *= (double)renderer.ViewportForScreenCanvasRenderer.SizeInPixels.Y;
                itemSize  = Math.Ceiling(itemSize);
                itemSize /= (double)renderer.ViewportForScreenCanvasRenderer.SizeInPixels.Y;
            }

            return(itemSize);
        }
예제 #4
0
 public override void ListEnsureVisible(UIList control, int index)
 {
     listEnsureVisible = index;
 }
예제 #5
0
        protected virtual void OnRenderList(UIList control, CanvasRenderer renderer)
        {
            var rect = control.GetScreenRectangle();

            renderer.AddQuad(rect, new ColorValue(0, 0, 0));
            //renderer.AddQuad( rect, new ColorValue( 0.2, 0.2, 0.2 ) );

            var rect2 = rect;

            rect2.Expand(-control.GetScreenOffsetByValue(new UIMeasureValueVector2(UIMeasure.Units, 2, 2)));

            //border
            var color = new ColorValue(0.75, 0.75, 0.75);

            renderer.AddQuad(new Rectangle(rect.Left, rect.Top, rect2.Left, rect.Bottom), color);
            renderer.AddQuad(new Rectangle(rect2.Left, rect.Top, rect2.Right, rect2.Top), color);
            renderer.AddQuad(new Rectangle(rect2.Right, rect.Top, rect.Right, rect.Bottom), color);
            renderer.AddQuad(new Rectangle(rect.Left, rect2.Bottom, rect2.Right, rect.Bottom), color);

            var font = control.Font.Value;

            if (font == null)
            {
                font = renderer.DefaultFont;
            }
            var fontSize         = control.GetFontSizeScreen();
            var itemSize         = GetListItemSizeScreen(control, renderer);
            var totalItemsHeight = itemSize * control.Items.Count;
            var scrollBar        = control.GetScrollBar();

            //!!!!тут?
            //update scroll bar properties
            if (scrollBar != null)
            {
                double screenSizeY       = rect2.Size.Y;
                double scrollScreenSizeY = totalItemsHeight - screenSizeY;

                scrollBar.Visible = control.AlwaysShowScrollBar || totalItemsHeight > screenSizeY;
                if (scrollBar.Visible)
                {
                    scrollBar.ValueRange = new Range(0, scrollScreenSizeY);
                }

                //ensure visible
                if (listEnsureVisible != -1)
                {
                    if ((float)listEnsureVisible * itemSize > screenSizeY / 2)
                    {
                        var factor = (float)listEnsureVisible / (float)(control.Items.Count - 1);
                        var v      = scrollScreenSizeY * factor;
                        scrollBar.Value = MathEx.Clamp(v, 0, scrollBar.ValueRange.Value.Maximum);
                    }
                    else
                    {
                        scrollBar.Value = 0;
                    }

                    listEnsureVisible = -1;
                }

                //if( scrollBar.Visible )
                //{
                //	if( scrollScreenSizeY > 0 )
                //	{
                //		double currentScrollScreenPosY = scrollBar.Value * scrollScreenSizeY;

                //		double itemScrollScreenPosY = itemSize * (double)control.SelectedIndex;
                //		Range itemScrollScreenRangeY = new Range( itemScrollScreenPosY, itemScrollScreenPosY + itemSize );

                //		if( itemScrollScreenRangeY.Minimum < currentScrollScreenPosY )
                //		{
                //			currentScrollScreenPosY = itemScrollScreenRangeY.Minimum;
                //		}
                //		else
                //		{
                //			if( itemScrollScreenRangeY.Maximum > currentScrollScreenPosY + screenSizeY )
                //				currentScrollScreenPosY = itemScrollScreenRangeY.Maximum + itemSize - screenSizeY;
                //		}

                //		scrollBar.Value = currentScrollScreenPosY / scrollScreenSizeY;
                //	}
                //	else
                //		scrollBar.Value = 0;
                //}
                //else
                //	scrollBar.Value = 0;
            }

            //items
            if (control.Items.Count != 0)
            {
                renderer.PushClipRectangle(rect2);

                var positionY = rect2.Top;
                if (scrollBar != null && scrollBar.VisibleInHierarchy && scrollBar.EnabledInHierarchy)
                {
                    positionY -= scrollBar.Value;
                }

                for (int n = 0; n < control.Items.Count; n++)
                {
                    var item          = control.Items[n];
                    var itemRectangle = new Rectangle(rect2.Left, positionY, rect2.Right, positionY + itemSize);
                    if (scrollBar != null && scrollBar.EnabledInHierarchy && scrollBar.VisibleInHierarchy)
                    {
                        itemRectangle.Right -= scrollBar.GetScreenSize().X;
                    }

                    if (itemRectangle.Intersects(rect2))
                    {
                        renderer.PushClipRectangle(itemRectangle);

                        if (n == control.SelectedIndex)
                        {
                            var color2 = control.ReadOnlyInHierarchy ? new ColorValue(0.5, 0.5, 0.5) : new ColorValue(0, 0, 0.8);
                            renderer.AddQuad(itemRectangle, color2);
                        }

                        var positionX = rect2.Left + control.GetScreenOffsetByValue(new UIMeasureValueVector2(UIMeasure.Units, 2, 0)).X;
                        renderer.AddText(font, fontSize, item, new Vector2(positionX, itemRectangle.GetCenter().Y), EHorizontalAlignment.Left, EVerticalAlignment.Center, new ColorValue(1, 1, 1));

                        renderer.PopClipRectangle();
                    }

                    positionY += itemSize;
                }

                renderer.PopClipRectangle();
            }
        }
예제 #6
0
 public virtual void ListEnsureVisible(UIList control, int index)
 {
 }
예제 #7
0
        ////////////////

        public virtual int GetListItemIndexByScreenPosition(UIList control, Vector2 position)
        {
            return(-1);
        }