示例#1
0
 protected AxisDirection getDirection(BuildContext context)
 {
     return(LayoutUtils.getAxisDirectionFromAxisReverseAndDirectionality(
                context, this.scrollDirection, this.reverse));
 }
示例#2
0
        protected override SizeF ArrangeOverride(SizeF arrangeSize)
        {
            RadCommandBarBaseItemCollection items = this.items;
            int   count = items.Count;
            SizeF empty = SizeF.Empty;
            bool  flag1 = false;
            bool  flag2 = false;

            if (flag1 || flag2)
            {
                for (int index = 0; index < count; ++index)
                {
                    RadElement radElement = (RadElement)items[index];
                    if (flag1)
                    {
                        empty.Height = Math.Max(radElement.DesiredSize.Height, empty.Height);
                    }
                    if (flag2)
                    {
                        empty.Width = Math.Max(radElement.DesiredSize.Width, empty.Width);
                    }
                }
            }
            bool       flag3       = this.Orientation == Orientation.Horizontal;
            bool       rightToLeft = this.RightToLeft;
            float      num         = 0.0f;
            RectangleF finalRect   = new RectangleF(PointF.Empty, arrangeSize);

            if (flag3 && rightToLeft)
            {
                finalRect.X = arrangeSize.Width;
            }
            float f = this.ArrangeStretchedItems(arrangeSize);

            for (int index = 0; index < count; ++index)
            {
                RadElement radElement  = (RadElement)items[index];
                SizeF      desiredSize = radElement.DesiredSize;
                if (radElement.Visibility == ElementVisibility.Collapsed)
                {
                    radElement.Arrange(new RectangleF(PointF.Empty, desiredSize));
                }
                else
                {
                    if (flag1)
                    {
                        desiredSize.Height = !flag3 ? empty.Height : Math.Max(arrangeSize.Height, empty.Height);
                    }
                    if (flag2)
                    {
                        desiredSize.Width = !flag3?Math.Max(arrangeSize.Width, empty.Width) : empty.Width;
                    }
                    if (radElement.StretchHorizontally && flag3 && !float.IsInfinity(f))
                    {
                        desiredSize.Width = f;
                    }
                    if (radElement.StretchVertically && !flag3 && !float.IsInfinity(f))
                    {
                        desiredSize.Height = f;
                    }
                    if (flag3)
                    {
                        if (rightToLeft)
                        {
                            num          = desiredSize.Width;
                            finalRect.X -= num;
                        }
                        else
                        {
                            finalRect.X += num;
                            num          = desiredSize.Width;
                        }
                        finalRect.Width = num;
                        if (flag1)
                        {
                            SizeF size = finalRect.Size;
                            finalRect.Height = desiredSize.Height;
                            RectangleF rectangleF = LayoutUtils.Align(finalRect.Size, new RectangleF(PointF.Empty, size), this.Alignment);
                            finalRect.Y += rectangleF.Y;
                        }
                        else
                        {
                            finalRect.Height = arrangeSize.Height;
                        }
                    }
                    else
                    {
                        finalRect.Y     += num;
                        num              = desiredSize.Height;
                        finalRect.Height = num;
                        if (flag2)
                        {
                            SizeF size = finalRect.Size;
                            finalRect.Width = desiredSize.Width;
                            ContentAlignment align      = rightToLeft ? TelerikAlignHelper.RtlTranslateContent(this.Alignment) : this.Alignment;
                            RectangleF       rectangleF = LayoutUtils.Align(finalRect.Size, new RectangleF(PointF.Empty, size), align);
                            finalRect.X += rectangleF.X;
                        }
                        else
                        {
                            finalRect.Width = arrangeSize.Width;
                        }
                    }
                    if (radElement.StretchVertically && flag3)
                    {
                        finalRect.Height = arrangeSize.Height;
                    }
                    else if (radElement.StretchHorizontally && !flag3)
                    {
                        finalRect.Width = arrangeSize.Width;
                    }
                    radElement.Arrange(finalRect);
                }
            }
            return(arrangeSize);
        }
        /// <inheritdoc />
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values is null)
            {
                return(new PathFigureCollection(0));
            }

            if (values.Length != 9)
            {
                throw new ArgumentException(
                          $"{nameof(EdgeRouteToPathConverter)} must have 9 parameters: pos (1,2), size (3,4) of source; pos (5,6), size (7,8) of target; routeInformation (9).",
                          nameof(values));
            }

            ExtractInputs(
                values,
                out Point sourcePos,
                out Point targetPos,
                out Size sourceSize,
                out Size targetSize,
                out System.Windows.Point[] routeInformation);

            bool hasRouteInfo = routeInformation != null && routeInformation.Length > 0;

            // Create the path
            System.Windows.Point p1 = LayoutUtils.GetClippingPoint(
                sourceSize,
                sourcePos,
                hasRouteInfo ? routeInformation[0].ToGraphShapePoint() : targetPos).ToPoint();

            System.Windows.Point p2 = LayoutUtils.GetClippingPoint(
                targetSize,
                targetPos,
                hasRouteInfo ? routeInformation[routeInformation.Length - 1].ToGraphShapePoint() : sourcePos).ToPoint();


            var segments = new PathSegment[1 + (hasRouteInfo ? routeInformation.Length : 0)];

            if (hasRouteInfo)
            {
                // Append route points
                for (int i = 0; i < routeInformation.Length; ++i)
                {
                    segments[i] = new LineSegment(routeInformation[i], true);
                }
            }

            System.Windows.Point  pLast = hasRouteInfo ? routeInformation[routeInformation.Length - 1] : p1;
            System.Windows.Vector v     = pLast - p2;
            v = v / v.Length * 5;
            var n = new System.Windows.Vector(-v.Y, v.X) * 0.3;

            segments[segments.Length - 1] = new LineSegment(p2 + v, true);

            var pathCollection = new PathFigureCollection(2)
            {
                new PathFigure(p1, segments, false),
                new PathFigure(
                    p2,
                    new PathSegment[]
                {
                    new LineSegment(p2 + v - n, true),
                    new LineSegment(p2 + v + n, true)
                },
                    true)
            };

            return(pathCollection);
        }
示例#4
0
        /// <summary>
        /// Draw whole FormattedTextBlock
        /// </summary>
        /// <param name="graphics"></param>
        /// <param name="paintingRectangleParam"></param>
        /// <param name="useCompatibleTextRendering"></param>
        /// <param name="format"></param>
        /// <param name="flags"></param>
        /// <param name="textWrap"></param>
        /// <param name="clipText"></param>
        public void PaintFormatTextBlock(
            IGraphics graphics,
            RectangleF paintingRectangleParam,
            bool useCompatibleTextRendering,
            StringFormat format,
            TextFormatFlags flags,
            bool textWrap,
            bool clipText)
        {
            if (this.lines.Count == 0)
            {
                return;
            }

            SizeF textDesiredSize = this.GetTextSize(paintingRectangleParam.Size, useCompatibleTextRendering, format, flags, textWrap);

            if (textDesiredSize.Height > paintingRectangleParam.Height)
            {
                textDesiredSize.Height = paintingRectangleParam.Height;
            }

            if (textDesiredSize.Width > paintingRectangleParam.Width)
            {
                textDesiredSize.Width = paintingRectangleParam.Width;
            }

            RectangleF paintingRectangle = LayoutUtils.VAlign(textDesiredSize, paintingRectangleParam, lines[0].GetLineAligment());

            paintingRectangle.X += lines[0].GetLineOffset();
            foreach (TextLine line in lines)
            {
                RectangleF currentLineRect = LayoutUtils.HAlign(line.LineSize, paintingRectangle, line.GetLineAligment());
                currentLineRect.Height = line.LineSize.Height;

                if (currentLineRect.X < paintingRectangle.X)
                {
                    currentLineRect.X = paintingRectangle.X;
                }

                if (currentLineRect.Width > paintingRectangle.Width)
                {
                    currentLineRect.Width = paintingRectangle.Width;
                }

                if (currentLineRect.Y < paintingRectangle.Y)
                {
                    currentLineRect.Y = paintingRectangle.Y;
                }

                if (currentLineRect.Height > paintingRectangle.Height)
                {
                    currentLineRect.Height = paintingRectangle.Height;
                }

                float lineHeight = defaultLineHeight;
                // bool emptyLine = true;
                foreach (FormattedText formatedText in line.List)
                {
                    //emptyLine = !formatedText.StartNewLine;
                    if (string.IsNullOrEmpty(formatedText.Text) && formatedText.Image == null)
                    {
                        continue;
                    }

                    PointF currentLineBeginPoint = new PointF(currentLineRect.Location.X + line.GetLineOffset(), currentLineRect.Y);

                    //fix to draw text only into painting rectangle
                    if (currentLineRect.Location.Y > paintingRectangleParam.Height)
                    {
                        return;
                    }

                    formatedText.PaintFormatText(graphics,
                                                 paintingRectangle,
                                                 useCompatibleTextRendering,
                                                 flags,
                                                 currentLineBeginPoint,
                                                 line.LineSize.Height,
                                                 line.BaseLine,
                                                 clipText);

                    currentLineRect.Location = new PointF(currentLineRect.Location.X + formatedText.BlockSize.Width, currentLineRect.Location.Y);

                    lineHeight = line.LineSize.Height;
                    //emptyLine = false;
                }

                paintingRectangle.Location = new PointF(paintingRectangle.X, paintingRectangle.Y + lineHeight);//(!emptyLine ? lineHeight : 0));
            }
        }
        private bool LayoutVertical()
        {
#if DEBUG
            if (DebugLayoutTraceSwitch.TraceVerbose)
            {
                Debug.WriteLine("_________________________\r\nVertical Layout" + displayRectangle.ToString());
            }
#endif

            ToolStrip toolStrip         = ToolStrip;
            Rectangle clientRectangle   = toolStrip.ClientRectangle;
            int       lastBottom        = displayRectangle.Bottom;
            int       lastTop           = displayRectangle.Top;
            bool      needsMoreSpace    = false;
            Size      itemSize          = Size.Empty;
            Rectangle alignedLeftItems  = Rectangle.Empty;
            Rectangle alignedRightItems = Rectangle.Empty;

            Size      toolStripPreferredSize = displayRectangle.Size;
            DockStyle dock = toolStrip.Dock;
#pragma warning disable SA1408 // Conditional expressions should declare precedence
            if (toolStrip.AutoSize && (!toolStrip.IsInToolStripPanel && (dock == DockStyle.Left) || (dock == DockStyle.Right)))
#pragma warning restore SA1408 // Conditional expressions should declare precedence
            {
                // if we're autosizing, make sure we pad out items to the preferred width, not the
                // width of the display rectangle.
                toolStripPreferredSize = ToolStrip.GetPreferredSizeVertical(toolStrip, Size.Empty) - toolStrip.Padding.Size;
            }

            CalculatePlacementsVertical();

            bool needOverflow = toolStrip.CanOverflow && ((OverflowRequired) || (OverflowSpace >= OverflowButtonSize.Height));

            toolStrip.OverflowButton.Visible = needOverflow;

            for (int j = -1; j < ToolStrip.Items.Count; j++)
            {
                ToolStripItem item = null;

                if (j == -1)
                {
                    // the first time through place the overflow button if its required.
                    if (needOverflow)
                    {
                        item = toolStrip.OverflowButton;
                        item.SetPlacement(ToolStripItemPlacement.Main);
                    }
                    else
                    {
                        item = toolStrip.OverflowButton;
                        item.SetPlacement(ToolStripItemPlacement.None);
                        continue;
                    }

                    itemSize = OverflowButtonSize;
                }
                else
                {
                    item = toolStrip.Items[j];
                    if (!((IArrangedElement)item).ParticipatesInLayout)
                    {
                        // skip over items not participating in layout.  E.G. not visible items
                        continue;
                    }

                    // since we havent parented the item yet - the auto size wont have reset the size yet.
                    itemSize = item.AutoSize ? item.GetPreferredSize(Size.Empty) : item.Size;
                }

                // if it turns out we dont need the overflow (because there are no Overflow.Always items and the height of everything
                // in the overflow is less than the width of the overflow button then reset the placement of the as needed items to
                // main.
                if (!needOverflow && (item.Overflow == ToolStripItemOverflow.AsNeeded && item.Placement == ToolStripItemPlacement.Overflow))
                {
#if DEBUG
                    if (DebugLayoutTraceSwitch.TraceVerbose)
                    {
                        Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Resetting {0} to Main - we dont need it to overflow", item));
                    }
#endif
                    item.SetPlacement(ToolStripItemPlacement.Main);
                }

                // Now do the guts of setting X, Y and parenting.
                // Vertical split stack management ignores left to right.
                //      Items aligned to the Head are placed from Top to Bottom
                //      Items aligned to the Tail are placed from Bottom to Top
                if ((item != null) && (item.Placement == ToolStripItemPlacement.Main))
                {
                    Padding itemMargin = item.Margin;
                    int     x          = displayRectangle.Left + itemMargin.Left;
                    int     y          = displayRectangle.Top;

                    switch (item.Alignment)
                    {
                    case ToolStripItemAlignment.Right:
                        y                 = lastBottom - (itemMargin.Bottom + itemSize.Height);
                        lastBottom        = y - itemMargin.Top;
                        alignedRightItems = (alignedRightItems == Rectangle.Empty) ? new Rectangle(x, y, itemSize.Width, itemSize.Height)
                                                : Rectangle.Union(alignedRightItems, new Rectangle(x, y, itemSize.Width, itemSize.Height));
                        break;

                    case ToolStripItemAlignment.Left:
                    default:
                        y                = lastTop + itemMargin.Top;
                        lastTop          = y + itemSize.Height + itemMargin.Bottom;
                        alignedLeftItems = (alignedLeftItems == Rectangle.Empty) ? new Rectangle(x, y, itemSize.Width, itemSize.Height)
                                                    : Rectangle.Union(alignedLeftItems, new Rectangle(x, y, itemSize.Width, itemSize.Height));
                        break;
                    }
                    item.ParentInternal = ToolStrip;
                    Point itemLocation = new Point(x, y);

                    if (!clientRectangle.Contains(x, y))
                    {
                        item.SetPlacement(ToolStripItemPlacement.None);
                    }
                    else if (alignedRightItems.Width > 0 && alignedLeftItems.Width > 0 && alignedRightItems.IntersectsWith(alignedLeftItems))
                    {
                        itemLocation = noMansLand;
                        item.SetPlacement(ToolStripItemPlacement.None);
                    }

                    if (item.AutoSize)
                    {
                        // autosized items stretch from edge-edge
                        itemSize.Width = Math.Max(toolStripPreferredSize.Width - itemMargin.Horizontal - 1, 0);
                    }
                    else
                    {
                        // non autosized items are horizontally centered
                        Rectangle bounds = LayoutUtils.HAlign(item.Size, displayRectangle, AnchorStyles.None);
                        itemLocation.X = bounds.X;
                    }

                    SetItemLocation(item, itemLocation, itemSize);
                }
                else
                {
                    item.ParentInternal = (item.Placement == ToolStripItemPlacement.Overflow) ? toolStrip.OverflowButton.DropDown : null;
                }
#if DEBUG
                if (DebugLayoutTraceSwitch.TraceVerbose)
                {
                    Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Item {0} Placement {1} Bounds {2} Parent {3}", item.ToString(), item.Placement.ToString(), item.Bounds.ToString(), (item.ParentInternal == null) ? "null" : item.ParentInternal.ToString()));
                }
#endif
            }

            return(needsMoreSpace);
        }
示例#6
0
 public static TextImageRelation ImageAlignToRelation(ContentAlignment alignment)
 {
     return(TelerikAlignHelper.imageAlignToRelation[LayoutUtils.ContentAlignmentToIndex(alignment)]);
 }
        private void Init()
        {
            ImageButton backButton = FindViewById <ImageButton>(Resource.Id.arrow_back_general);

            backButton.ContentDescription = BACK_BUTTON_ACCESSIBILITY_TEXT;

            TextView titleField       = FindViewById <TextView>(Resource.Id.settings_general_title);
            TextView explanationOne   = FindViewById <TextView>(Resource.Id.settings_general_explanation);
            TextView explanationTwo   = FindViewById <TextView>(Resource.Id.settings_general_explanation_two);
            TextView mobileDataHeader = FindViewById <TextView>(Resource.Id.settings_general_mobile_data_header);
            TextView mobileDataDesc   = FindViewById <TextView>(Resource.Id.settings_general_mobile_data_desc);
            TextView languageHeader   = FindViewById <TextView>(Resource.Id.settings_general_select_lang_header);
            TextView languageDesc     = FindViewById <TextView>(Resource.Id.settings_general_select_lang_desc_one);
            TextView languageLink     = FindViewById <TextView>(Resource.Id.settings_general_link);
            TextView linkLayout       = FindViewById <TextView>(Resource.Id.settings_general_link);

            titleField.Text                 = SETTINGS_GENERAL_TITLE;
            explanationOne.Text             = SETTINGS_GENERAL_EXPLANATION_ONE;
            explanationTwo.Text             = SETTINGS_GENERAL_EXPLANATION_TWO;
            mobileDataHeader.Text           = SETTINGS_GENERAL_MOBILE_DATA_HEADER;
            mobileDataDesc.Text             = SETTINGS_GENERAL_MOBILE_DATA_DESC;
            languageHeader.Text             = SETTINGS_GENERAL_CHOOSE_LANGUAGE_HEADER;
            languageDesc.Text               = SETTINGS_GENERAL_RESTART_REQUIRED_TEXT;
            languageLink.TextAlignment      = TextAlignment.ViewStart;
            languageLink.ContentDescription = SETTINGS_GENERAL_ACCESSIBILITY_MORE_INFO_BUTTON_TEXT;

            titleField.SetAccessibilityDelegate(AccessibilityUtils.GetHeadingAccessibilityDelegate());
            mobileDataHeader.SetAccessibilityDelegate(AccessibilityUtils.GetHeadingAccessibilityDelegate());
            languageHeader.SetAccessibilityDelegate(AccessibilityUtils.GetHeadingAccessibilityDelegate());

            languageLink.TextFormatted  = HtmlCompat.FromHtml($"<a href=\"{SETTINGS_GENERAL_MORE_INFO_LINK}\">{SETTINGS_GENERAL_MORE_INFO_BUTTON_TEXT}</a>", HtmlCompat.FromHtmlModeLegacy);
            languageLink.MovementMethod = new Android.Text.Method.LinkMovementMethod();

            RadioGroup  radioGroup            = FindViewById <RadioGroup>(Resource.Id.settings_general_select_lang_radio_group);
            RadioButton englishRadioButton    = FindViewById <RadioButton>(Resource.Id.settings_general_english);
            RadioButton bokmalRadioButton     = FindViewById <RadioButton>(Resource.Id.settings_general_bokmal);
            RadioButton nynorskRadioButton    = FindViewById <RadioButton>(Resource.Id.settings_general_nynorsk);
            RadioButton polishRadioButton     = FindViewById <RadioButton>(Resource.Id.settings_general_polish);
            RadioButton somaliRadioButton     = FindViewById <RadioButton>(Resource.Id.settings_general_somali);
            RadioButton tigrinyaRadioButton   = FindViewById <RadioButton>(Resource.Id.settings_general_tigrinya);
            RadioButton arabicRadioButton     = FindViewById <RadioButton>(Resource.Id.settings_general_arabic);
            RadioButton urduRadioButton       = FindViewById <RadioButton>(Resource.Id.settings_general_urdu);
            RadioButton lithuanianRadioButton = FindViewById <RadioButton>(Resource.Id.settings_general_lithuanian);



            englishRadioButton.Text    = SETTINGS_GENERAL_EN;
            bokmalRadioButton.Text     = SETTINGS_GENERAL_NB;
            nynorskRadioButton.Text    = SETTINGS_GENERAL_NN;
            polishRadioButton.Text     = SETTINGS_GENERAL_PL;
            somaliRadioButton.Text     = SETTINGS_GENERAL_SO;
            tigrinyaRadioButton.Text   = SETTINGS_GENERAL_TI;
            arabicRadioButton.Text     = SETTINGS_GENERAL_AR;
            urduRadioButton.Text       = SETTINGS_GENERAL_UR;
            lithuanianRadioButton.Text = SETTINGS_GENERAL_LT;

            string appLanguage = LocalesService.GetLanguage();

            switch (appLanguage)
            {
            case "en":
                englishRadioButton.Checked = true;
                break;

            case "nn":
                nynorskRadioButton.Checked = true;
                break;

            case "pl":
                polishRadioButton.Checked = true;
                break;

            case "so":
                somaliRadioButton.Checked = true;
                break;

            case "ti":
                tigrinyaRadioButton.Checked = true;
                break;

            case "ar":
                arabicRadioButton.Checked = true;
                break;

            case "ur":
                urduRadioButton.Checked = true;
                break;

            case "lt":
                lithuanianRadioButton.Checked = true;
                break;

            default:
                bokmalRadioButton.Checked = true;
                break;
            }

            radioGroup.SetOnCheckedChangeListener(new OnCheckedChangeListener(this));

            SwitchCompat switchButton = FindViewById <SwitchCompat>(Resource.Id.settings_general_switch);

            switchButton.Checked        = _viewModel.GetStoredCheckedState();
            switchButton.CheckedChange += OnCheckedChange;

            backButton.Click += new StressUtils.SingleClick((sender, args) => Finish()).Run;

            // Layout direction logic
            View rootView = Window.DecorView.RootView;

            rootView.LayoutDirection = LayoutUtils.GetLayoutDirection();
            backButton.SetBackgroundResource(LayoutUtils.GetBackArrow());
            languageLink.SetCompoundDrawablesRelativeWithIntrinsicBounds(null, null, ContextCompat.GetDrawable(this, LayoutUtils.GetForwardArrow()), null);
        }
示例#8
0
        protected override SizeF ArrangeOverride(SizeF arrangeSize)
        {
            RadCommandBarBaseItemCollection children = this.items;
            int count = children.Count;

            // Get desired children size if EqualChildrenHeight or EqualChildrenWidth is used
            // ********************************************************* //
            SizeF maxDesiredChildrenSize = SizeF.Empty;
            bool  equalChildrenHeight    = false; // this.EqualChildrenHeight;
            bool  equalChildrenWidth     = false; // this.EqualChildrenWidth;

            if (equalChildrenHeight || equalChildrenWidth)
            {
                for (int i = 0; i < count; i++)
                {
                    RadElement element = children[i];
                    if (equalChildrenHeight)
                    {
                        maxDesiredChildrenSize.Height = Math.Max(element.DesiredSize.Height, maxDesiredChildrenSize.Height);
                    }
                    if (equalChildrenWidth)
                    {
                        maxDesiredChildrenSize.Width = Math.Max(element.DesiredSize.Width, maxDesiredChildrenSize.Width);
                    }
                }
            }

            // Parameters
            // ********************************************************* //
            bool isHorizontal  = this.Orientation == Orientation.Horizontal;
            bool isRightToLeft = this.RightToLeft;

            float      length    = 0;
            RectangleF finalRect = new RectangleF(PointF.Empty, arrangeSize);

            if (isHorizontal && isRightToLeft)
            {
                finalRect.X = arrangeSize.Width;
            }

            float stretchedItemArrangedSpace = ArrangeStretchedItems(arrangeSize);

            // Main loop that does the actual arrangement of the children
            // ********************************************************* //
            for (int i = 0; i < count; i++)
            {
                RadElement element = children[i];

                SizeF childArea = element.DesiredSize;
                if (element.Visibility == ElementVisibility.Collapsed)
                {
                    element.Arrange(new RectangleF(PointF.Empty, childArea));
                    continue;
                }

                // ** 1. Calculate the ChildArea
                if (equalChildrenHeight)
                {
                    if (isHorizontal)
                    {
                        childArea.Height = Math.Max(arrangeSize.Height, maxDesiredChildrenSize.Height);
                    }
                    else
                    {
                        childArea.Height = maxDesiredChildrenSize.Height;
                    }
                }
                if (equalChildrenWidth)
                {
                    if (isHorizontal)
                    {
                        childArea.Width = maxDesiredChildrenSize.Width;
                    }
                    else
                    {
                        childArea.Width = Math.Max(arrangeSize.Width, maxDesiredChildrenSize.Width);
                    }
                }
                if (element.StretchHorizontally && isHorizontal && !float.IsInfinity(stretchedItemArrangedSpace))
                {
                    childArea.Width = stretchedItemArrangedSpace;
                }
                if (element.StretchVertically && !isHorizontal && !float.IsInfinity(stretchedItemArrangedSpace))
                {
                    childArea.Height = stretchedItemArrangedSpace;
                }
                // ** 2. Calculate the location and size (finalRect) that will be passed to the child's Arrange
                if (isHorizontal)
                {
                    if (isRightToLeft)
                    {
                        length       = childArea.Width;
                        finalRect.X -= length;
                    }
                    else
                    {
                        finalRect.X += length;
                        length       = childArea.Width;
                    }

                    finalRect.Width = length;

                    if (equalChildrenHeight)
                    {
                        SizeF arrangeArea = finalRect.Size;
                        finalRect.Height = childArea.Height;

                        // Compensate the alignment for EqualChildrenHeight because the basic logic will be bypassed
                        // by the size forcing
                        // Note that the vertical alignment is not affected by RightToLeft...
                        RectangleF alignedRect = LayoutUtils.Align(finalRect.Size, new RectangleF(PointF.Empty, arrangeArea), this.Alignment);
                        finalRect.Y += alignedRect.Y;
                    }
                    else
                    {
                        finalRect.Height = arrangeSize.Height;// Math.Max(arrangeSize.Height, childArea.Height);
                    }
                }
                else
                {
                    finalRect.Y     += length;
                    length           = childArea.Height;
                    finalRect.Height = length;
                    if (equalChildrenWidth)
                    {
                        SizeF arrangeArea = finalRect.Size;
                        finalRect.Width = childArea.Width;

                        // Compensate the alignment for EqualChildrenHeight because the basic logic will be bypassed
                        // by the size forcing
                        // Note that the horizontal alignment is translated if RightToLeft is true.
                        ContentAlignment alignment   = isRightToLeft ? TelerikAlignHelper.RtlTranslateContent(this.Alignment) : this.Alignment;
                        RectangleF       alignedRect = LayoutUtils.Align(finalRect.Size, new RectangleF(PointF.Empty, arrangeArea), alignment);
                        finalRect.X += alignedRect.X;
                    }
                    else
                    {
                        finalRect.Width = arrangeSize.Width;// Math.Max(arrangeSize.Width, childArea.Width);
                    }
                }

                // ** 3. Arrange the child
                if (element.StretchVertically && isHorizontal)
                {
                    finalRect.Height = arrangeSize.Height;
                }
                else if (element.StretchHorizontally && !isHorizontal)
                {
                    finalRect.Width = arrangeSize.Width;
                }
                element.Arrange(finalRect);
            }

            return(arrangeSize);
        }
示例#9
0
        private Rectangle GetClientRect()
        {
            Rectangle client = this.ClientRectangle;

            return(LayoutUtils.DeflateRect(client, this.Padding));
        }
示例#10
0
        public override SizeF Arrange(RectangleF bounds)
        {
            SizeF size = bounds.Size;

            if (this.lastFinalSize != size || this.isDirty)
            {
                this.lastFinalSize = size;
                this.Measure(size);
            }
            SizeF             sizeF1           = size;
            RectangleF        rectangleF1      = new RectangleF(bounds.Location, size);
            RectangleF        empty1           = RectangleF.Empty;
            RectangleF        region2          = RectangleF.Empty;
            SizeF             empty2           = SizeF.Empty;
            SizeF             empty3           = SizeF.Empty;
            ContentAlignment  contentAlignment = this.Owner.ImageAlignment;
            TextImageRelation relation         = this.Owner.TextImageRelation;

            if (this.Owner.RightToLeft)
            {
                contentAlignment = TelerikAlignHelper.RtlTranslateContent(contentAlignment);
                relation         = TelerikAlignHelper.RtlTranslateRelation(relation);
            }
            if (this.left != null && this.Owner.Image == null)
            {
                this.left.Arrange(rectangleF1);
                if (this.right != null)
                {
                    this.right.Arrange(rectangleF1);
                }
                return(size);
            }
            if (this.right != null && (string.IsNullOrEmpty(this.Owner.Text) || !this.Owner.DrawText))
            {
                this.right.Arrange(rectangleF1);
                if (this.left != null)
                {
                    this.left.Arrange(rectangleF1);
                }
                return(size);
            }
            SizeF invariantLength1 = (SizeF)this.GetInvariantLength(Size.Ceiling(this.left.DesiredSize), this.left.Margin);
            SizeF invariantLength2 = (SizeF)this.GetInvariantLength(Size.Ceiling(this.right.DesiredSize), this.right.Margin);

            LayoutUtils.SubAlignedRegion(sizeF1, invariantLength1, relation);
            SizeF      sizeF2 = LayoutUtils.AddAlignedRegion(invariantLength2, invariantLength1, relation);
            RectangleF empty4 = (RectangleF)Rectangle.Empty;

            empty4.Size = LayoutUtils.UnionSizes(sizeF1, sizeF2);
            empty4.X   += rectangleF1.X;
            empty4.Y   += rectangleF1.Y;
            bool flag1 = (TelerikAlignHelper.ImageAlignToRelation(contentAlignment) & relation) != TextImageRelation.Overlay;
            bool flag2 = (TelerikAlignHelper.TextAlignToRelation(this.Owner.TextAlignment) & relation) != TextImageRelation.Overlay;

            if (flag1)
            {
                LayoutUtils.SplitRegion(empty4, invariantLength1, (AnchorStyles)relation, out empty1, out region2);
            }
            else if (flag2)
            {
                LayoutUtils.SplitRegion(empty4, invariantLength2, (AnchorStyles)LayoutUtils.GetOppositeTextImageRelation(relation), out region2, out empty1);
            }
            else if (relation == TextImageRelation.Overlay)
            {
                LayoutUtils.SplitRegion(empty4, invariantLength1, (AnchorStyles)relation, out empty1, out region2);
            }
            else
            {
                LayoutUtils.SplitRegion(LayoutUtils.Align(sizeF2, empty4, ContentAlignment.MiddleCenter), invariantLength1, (AnchorStyles)relation, out empty1, out region2);
                LayoutUtils.ExpandRegionsToFillBounds(empty4, (AnchorStyles)relation, ref empty1, ref region2);
            }
            if (relation == TextImageRelation.TextBeforeImage || relation == TextImageRelation.ImageBeforeText)
            {
                float num = Math.Min(region2.Bottom, rectangleF1.Bottom);
                region2.Y      = Math.Max(Math.Min(region2.Y, rectangleF1.Y + (float)(((double)rectangleF1.Height - (double)region2.Height) / 2.0)), rectangleF1.Y);
                region2.Height = num - region2.Y;
            }
            if (relation == TextImageRelation.TextAboveImage || relation == TextImageRelation.ImageAboveText)
            {
                float num = Math.Min(region2.Right, rectangleF1.Right);
                region2.X     = Math.Max(Math.Min(region2.X, rectangleF1.X + (float)(((double)rectangleF1.Width - (double)region2.Width) / 2.0)), rectangleF1.X);
                region2.Width = num - region2.X;
            }
            if (relation == TextImageRelation.ImageBeforeText && (double)empty1.Size.Width != 0.0)
            {
                empty1.Width = Math.Max(0.0f, Math.Min(sizeF1.Width - region2.Width, empty1.Width));
                region2.X    = empty1.X + empty1.Width;
            }
            if (relation == TextImageRelation.ImageAboveText && (double)empty1.Size.Height != 0.0)
            {
                empty1.Height = Math.Max(0.0f, Math.Min(sizeF1.Height - region2.Height, empty1.Height));
                region2.Y     = empty1.Y + empty1.Height;
            }
            region2 = RectangleF.Intersect(region2, rectangleF1);
            RectangleF rectangleF2 = LayoutUtils.Align(invariantLength1, empty1, contentAlignment);

            if ((double)rectangleF2.Width > (double)empty1.Width)
            {
                rectangleF2.X = empty1.Width - invariantLength1.Width;
            }
            if ((double)rectangleF2.Height > (double)empty1.Height)
            {
                rectangleF2.Y = empty1.Height - invariantLength1.Height;
            }
            region2.Size = SizeF.Subtract(region2.Size, (SizeF)this.left.Margin.Size);
            empty1.Size  = SizeF.Subtract(empty1.Size, (SizeF)this.right.Margin.Size);
            this.left.Arrange(empty1);
            this.right.Arrange(region2);
            return(size);
        }
示例#11
0
        private void CalculateInternalLayoutMetrics()
        {
            Size empty            = Size.Empty;
            Size alignThis        = Size.Empty;
            Size defaultImageSize = ToolStripDropDownMenu.defaultImageSize;
            Size size             = Size.Empty;
            Size size5            = Size.Empty;

            for (int i = 0; i < this.Items.Count; i++)
            {
                ToolStripItem     item  = this.Items[i];
                ToolStripMenuItem item2 = item as ToolStripMenuItem;
                if (item2 != null)
                {
                    Size textSize = item2.GetTextSize();
                    if (item2.ShowShortcutKeys)
                    {
                        Size shortcutTextSize = item2.GetShortcutTextSize();
                        if (this.tabWidth == -1)
                        {
                            this.tabWidth = TextRenderer.MeasureText("\t", this.Font).Width;
                        }
                        textSize.Width += this.tabWidth + shortcutTextSize.Width;
                        textSize.Height = Math.Max(textSize.Height, shortcutTextSize.Height);
                    }
                    empty.Width  = Math.Max(empty.Width, textSize.Width);
                    empty.Height = Math.Max(empty.Height, textSize.Height);
                    Size size8 = Size.Empty;
                    if (item2.Image != null)
                    {
                        size8 = (item2.ImageScaling == ToolStripItemImageScaling.SizeToFit) ? base.ImageScalingSize : item2.Image.Size;
                    }
                    alignThis.Width  = Math.Max(alignThis.Width, size8.Width);
                    alignThis.Height = Math.Max(alignThis.Height, size8.Height);
                    if (item2.CheckedImage != null)
                    {
                        Size size9 = item2.CheckedImage.Size;
                        defaultImageSize.Width  = Math.Max(size9.Width, defaultImageSize.Width);
                        defaultImageSize.Height = Math.Max(size9.Height, defaultImageSize.Height);
                    }
                }
                else if (!(item is ToolStripSeparator))
                {
                    size5.Height = Math.Max(item.Bounds.Height, size5.Height);
                    size5.Width  = Math.Max(item.Bounds.Width, size5.Width);
                }
            }
            this.maxItemSize.Height = Math.Max(empty.Height + TextPadding.Vertical, Math.Max((int)(defaultImageSize.Height + CheckPadding.Vertical), (int)(size.Height + ArrowPadding.Vertical)));
            if (this.ShowImageMargin)
            {
                this.maxItemSize.Height = Math.Max(alignThis.Height + ImagePadding.Vertical, this.maxItemSize.Height);
            }
            if (this.ShowCheckMargin)
            {
                int num1 = defaultImageSize.Width;
            }
            if (this.ShowImageMargin)
            {
                int num6 = alignThis.Width;
            }
            size                    = new Size(10, this.maxItemSize.Height);
            empty.Height            = this.maxItemSize.Height - TextPadding.Vertical;
            alignThis.Height        = this.maxItemSize.Height - ImagePadding.Vertical;
            defaultImageSize.Height = this.maxItemSize.Height - CheckPadding.Vertical;
            empty.Width             = Math.Max(empty.Width, size5.Width);
            Point location = Point.Empty;
            int   width    = 0;
            int   num3     = Math.Max(0, alignThis.Width - ToolStripDropDownMenu.defaultImageSize.Width);

            if (this.ShowCheckMargin && this.ShowImageMargin)
            {
                width               = DefaultImageAndCheckMarginWidth + num3;
                location            = new Point(CheckPadding.Left, CheckPadding.Top);
                this.checkRectangle = LayoutUtils.Align(defaultImageSize, new Rectangle(location.X, location.Y, defaultImageSize.Width, this.maxItemSize.Height), ContentAlignment.MiddleCenter);
                location.X          = (this.checkRectangle.Right + CheckPadding.Right) + ImagePadding.Left;
                location.Y          = ImagePadding.Top;
                this.imageRectangle = LayoutUtils.Align(alignThis, new Rectangle(location.X, location.Y, alignThis.Width, this.maxItemSize.Height), ContentAlignment.MiddleCenter);
            }
            else if (this.ShowCheckMargin)
            {
                width               = DefaultImageMarginWidth;
                location            = new Point(1, CheckPadding.Top);
                this.checkRectangle = LayoutUtils.Align(defaultImageSize, new Rectangle(location.X, location.Y, width, this.maxItemSize.Height), ContentAlignment.MiddleCenter);
                this.imageRectangle = Rectangle.Empty;
            }
            else if (this.ShowImageMargin)
            {
                width               = DefaultImageMarginWidth + num3;
                location            = new Point(1, CheckPadding.Top);
                this.checkRectangle = LayoutUtils.Align(LayoutUtils.UnionSizes(defaultImageSize, alignThis), new Rectangle(location.X, location.Y, width - 1, this.maxItemSize.Height), ContentAlignment.MiddleCenter);
                this.imageRectangle = this.checkRectangle;
            }
            else
            {
                width = 0;
            }
            location.X             = width + 1;
            this.imageMarginBounds = new Rectangle(0, 0, width, base.Height);
            location.X             = this.imageMarginBounds.Right + TextPadding.Left;
            location.Y             = TextPadding.Top;
            this.textRectangle     = new Rectangle(location, empty);
            location.X             = (this.textRectangle.Right + TextPadding.Right) + ArrowPadding.Left;
            location.Y             = ArrowPadding.Top;
            this.arrowRectangle    = new Rectangle(location, size);
            this.maxItemSize.Width = (this.arrowRectangle.Right + ArrowPadding.Right) - this.imageMarginBounds.Left;
            base.Padding           = this.DefaultPadding;
            int num4 = this.imageMarginBounds.Width;

            if (this.RightToLeft == RightToLeft.Yes)
            {
                num4 += TextPadding.Right;
                int num5 = this.maxItemSize.Width;
                this.checkRectangle.X    = num5 - this.checkRectangle.Right;
                this.imageRectangle.X    = num5 - this.imageRectangle.Right;
                this.textRectangle.X     = num5 - this.textRectangle.Right;
                this.arrowRectangle.X    = num5 - this.arrowRectangle.Right;
                this.imageMarginBounds.X = num5 - this.imageMarginBounds.Right;
            }
            else
            {
                num4 += TextPadding.Left;
            }
            this.maxItemSize.Height          += this.maxItemSize.Height % 2;
            this.textRectangle.Y              = LayoutUtils.VAlign(this.textRectangle.Size, new Rectangle(Point.Empty, this.maxItemSize), ContentAlignment.MiddleCenter).Y;
            this.textRectangle.Y             += this.textRectangle.Height % 2;
            this.state[stateMaxItemSizeValid] = true;
            this.PaddingToTrim = num4;
        }
示例#12
0
        static void TestRenderResponsive()
        {
            Func <BaseWidget> build = () => W.Row(
                W.FillWidth(
                    W.FillHeight(
                        W.Border(null))),
                W.FixedWidth(
                    20,
                    W.Column(
                        W.Row(
                            W.Text("Blacksmith"),
                            W.FillWidth(null),
                            W.Text("friendly")
                            ),
                        W.Row(
                            W.Text("Mouse"),
                            W.FillWidth(null),
                            W.Text("neutral")
                            ),
                        W.Row(
                            W.Text("Fire Imp"),
                            W.FillWidth(null),
                            W.Text("hostile")
                            )
                        )
                    )
                );

            using (var t = new Rendering.Terminal(50, 50, "layout test")) {
                var c = new Constraint {
                    xMin = 0,
                    xMax = -1,
                    yMin = 0,
                    yMax = -1,
                };
                var prev = default(BaseWidget);
                var next = build();
                while (!t.ShouldClose)
                {
                    var(newWidth, newHeight) = t.Size;
                    if (c.xMax != newWidth || c.yMax != newHeight)
                    {
                        c = c with {
                            xMax = newWidth,
                            yMax = newHeight,
                        };
                        next.Layout(c);
                        if (prev == null)
                        {
                            LayoutUtils.PrintTree(next);
                            RenderLayout.Tree(t, next);
                        }
                        else
                        {
                            RenderLayout.Diff(t, prev, next);
                        }
                        t.Render();
                        prev = next;
                        next = build();
                    }
                    t.Poll();
                }
            }
        }
        private async void Init()
        {
            MessagesViewModel.SubscribeMessages(this, ClearAndAddNewMessages);

            _messagesList        = FindViewById <ListView>(Resource.Id.messages_list);
            _noItemsTextView     = FindViewById <TextView>(Resource.Id.no_items_description);
            _lastUpdatedTextView = FindViewById <TextView>(Resource.Id.last_updated);

            _messagesList.Divider       = null;
            _messagesList.DividerHeight = 0;


            TextView title = FindViewById <TextView>(Resource.Id.messages_page_title);

            title.Text = MessagesViewModel.MESSAGES_HEADER;
            title.SetAccessibilityDelegate(AccessibilityUtils.GetHeadingAccessibilityDelegate());

            string headerText     = MessagesViewModel.MESSAGES_NO_ITEMS_TITLE;
            int    unreadMessages = (await MessageUtils.GetAllUnreadMessages()).Count;
            int    messages       = (await MessageUtils.GetMessages()).Count;

            if (unreadMessages > 0)
            {
                headerText = MessagesViewModel.MESSAGES_NEW_MESSAGES_HEADER;
            }
            else if (messages > 0)
            {
                headerText = MessagesViewModel.MESSAGES_NO_NEW_MESSAGES_HEADER;
            }

            TextView subheader = FindViewById <TextView>(Resource.Id.messages_page_sub_header);

            subheader.Text = headerText;
            subheader.SetAccessibilityDelegate(AccessibilityUtils.GetHeadingAccessibilityDelegate());

            string lastUpdatedString = MessagesViewModel.LastUpdateString;

            if (lastUpdatedString == "")
            {
                _lastUpdatedTextView.Visibility = ViewStates.Gone;
            }
            else
            {
                _lastUpdatedTextView.Visibility = ViewStates.Visible;
                _lastUpdatedTextView.Text       = MessagesViewModel.LastUpdateString;
            }

            _noItemsTextView.Text = MessagesViewModel.MESSAGES_NO_ITEMS_DESCRIPTION;

            _closeButton        = FindViewById <ImageView>(Resource.Id.arrow_back);
            _closeButton.Click += new StressUtils.SingleClick(OnCloseBtnClicked).Run;
            _closeButton.ContentDescription = MessagesViewModel.MESSAGES_ACCESSIBILITY_CLOSE_BUTTON;

            _adapterMessages                  = new MessagesAdapter(this, new MessageItemViewModel[0]);
            _messagesList.Adapter             = _adapterMessages;
            _messagesList.OnItemClickListener = new ItemClickListener(_adapterMessages);
            ShowList(false);

            View rootView = Window.DecorView.RootView;

            rootView.LayoutDirection = LayoutUtils.GetLayoutDirection();

            _closeButton.SetBackgroundResource(LayoutUtils.GetBackArrow());
        }
示例#14
0
        public override SizeF Arrange(RectangleF bounds)
        {
            SizeF finalSize = bounds.Size;

            if (this.lastFinalSize != finalSize || this.isDirty)
            {
                this.lastFinalSize = finalSize;
                this.Measure(finalSize);
            }

            SizeF      fieldSize   = finalSize;
            RectangleF layoutField = new RectangleF(bounds.Location, finalSize);

            RectangleF imageBounds = RectangleF.Empty;
            RectangleF textBounds  = RectangleF.Empty;
            SizeF      textSize    = SizeF.Empty;
            SizeF      imageSize   = SizeF.Empty;

            ContentAlignment  imageAlign        = this.owner.ImageAlignment;
            ContentAlignment  textAlign         = this.owner.TextAlignment;
            TextImageRelation textImageRelation = this.owner.TextImageRelation;

            if (this.owner.RightToLeft)
            {
                imageAlign        = TelerikAlignHelper.RtlTranslateContent(imageAlign);
                textAlign         = TelerikAlignHelper.RtlTranslateContent(textAlign);
                textImageRelation = TelerikAlignHelper.RtlTranslateRelation(textImageRelation);
            }

            if ((this.left != null) && (this.owner.Image == null))
            {
                this.left.Arrange(layoutField);
                if (this.right != null)
                {
                    this.right.Arrange(layoutField);
                }
                return(finalSize);
            }
            if (this.right != null && (string.IsNullOrEmpty(this.owner.Text) || !this.owner.DrawText))
            {
                this.right.Arrange(layoutField);
                if (this.left != null)
                {
                    this.left.Arrange(layoutField);
                }
                return(finalSize);
            }

            imageSize = this.GetInvariantLength(Size.Ceiling(this.left.DesiredSize), this.left.Margin);
            textSize  = this.GetInvariantLength(Size.Ceiling(this.right.DesiredSize), this.right.Margin);

            // Subtract the image size from the whole field size
            SizeF textSizeLeft = LayoutUtils.SubAlignedRegion(fieldSize, imageSize, textImageRelation);
            // Create a new size based on the text size and the image size
            SizeF newSize = LayoutUtils.AddAlignedRegion(textSize, imageSize, textImageRelation);

            // The new field which is a union of the new sizes
            RectangleF maxFieldRectangle = Rectangle.Empty;

            maxFieldRectangle.Size = LayoutUtils.UnionSizes(fieldSize, newSize);
            maxFieldRectangle.X   += layoutField.X;
            maxFieldRectangle.Y   += layoutField.Y;
            // Image doesn't overlay text
            bool imageAlignNoOverlay = (TelerikAlignHelper.ImageAlignToRelation(imageAlign) & textImageRelation) != TextImageRelation.Overlay;
            // Text doesn't overlay image
            bool textAlignNoOverlay = (TelerikAlignHelper.TextAlignToRelation(textAlign) & textImageRelation) != TextImageRelation.Overlay;

            if (imageAlignNoOverlay)
            {
                LayoutUtils.SplitRegion(maxFieldRectangle, imageSize, (AnchorStyles)textImageRelation, out imageBounds, out textBounds);
            }
            else if (textAlignNoOverlay)
            {
                LayoutUtils.SplitRegion(maxFieldRectangle, textSize, (AnchorStyles)LayoutUtils.GetOppositeTextImageRelation(textImageRelation), out textBounds, out imageBounds);
            }
            else
            {
                // Both image overlays text and text overlays image
                if (textImageRelation == TextImageRelation.Overlay)
                {
                    LayoutUtils.SplitRegion(maxFieldRectangle, imageSize, (AnchorStyles)textImageRelation, out imageBounds, out textBounds);
                }
                else
                {
                    RectangleF alignedField = LayoutUtils.Align(newSize, maxFieldRectangle, ContentAlignment.MiddleCenter);
                    LayoutUtils.SplitRegion(alignedField, imageSize, (AnchorStyles)textImageRelation, out imageBounds, out textBounds);
                    LayoutUtils.ExpandRegionsToFillBounds(maxFieldRectangle, (AnchorStyles)textImageRelation, ref imageBounds, ref textBounds);
                }
            }
            ///////////////////////////////////////////////////////////////////////////

            //set image and text bounds according the size of the field
            if ((textImageRelation == TextImageRelation.TextBeforeImage) || (textImageRelation == TextImageRelation.ImageBeforeText))
            {
                float num1 = Math.Min(textBounds.Bottom, layoutField.Bottom);
                textBounds.Y      = Math.Max(Math.Min(textBounds.Y, layoutField.Y + ((layoutField.Height - textBounds.Height) / 2)), layoutField.Y);
                textBounds.Height = num1 - textBounds.Y;
            }
            if ((textImageRelation == TextImageRelation.TextAboveImage) || (textImageRelation == TextImageRelation.ImageAboveText))
            {
                float num2 = Math.Min(textBounds.Right, layoutField.Right);
                textBounds.X     = Math.Max(Math.Min(textBounds.X, layoutField.X + ((layoutField.Width - textBounds.Width) / 2)), layoutField.X);
                textBounds.Width = num2 - textBounds.X;
            }
            if ((textImageRelation == TextImageRelation.ImageBeforeText) && (imageBounds.Size.Width != 0))
            {
                imageBounds.Width = Math.Max(0, Math.Min(fieldSize.Width - textBounds.Width, imageBounds.Width));
                textBounds.X      = imageBounds.X + imageBounds.Width;
            }
            if ((textImageRelation == TextImageRelation.ImageAboveText) && (imageBounds.Size.Height != 0))
            {
                imageBounds.Height = Math.Max(0, Math.Min(fieldSize.Height - textBounds.Height, imageBounds.Height));
                textBounds.Y       = imageBounds.Y + imageBounds.Height;
            }
            textBounds = RectangleF.Intersect(textBounds, layoutField);

            //align image and if its size is greater than the field's size it is become offseted as much as the difference
            RectangleF newImageBounds = LayoutUtils.Align(imageSize, imageBounds, imageAlign);

            if (newImageBounds.Width > imageBounds.Width)
            {
                newImageBounds.X = imageBounds.Width - imageSize.Width;
            }
            if (newImageBounds.Height > imageBounds.Height)
            {
                newImageBounds.Y = imageBounds.Height - imageSize.Height;
            }

            textBounds = LayoutUtils.Align(textSize, textBounds, textAlign);
            //textBounds.Offset(layoutField.Location);
            //imageBounds.Offset(layoutField.Location);

            /////////////////////////////////////////////////////////////////////////
            textBounds.Size  = SizeF.Subtract(textBounds.Size, this.left.Margin.Size);
            imageBounds.Size = SizeF.Subtract(imageBounds.Size, this.right.Margin.Size);

            this.left.Arrange(imageBounds);
            this.right.Arrange(textBounds);

            return(finalSize);
        }
示例#15
0
        protected override void OnPaint(PaintEventArgs e)
        {
            if (bsState == FlatButtonState.Down)
            {
                e.Graphics.Clear(_BackColorDown.Lerp(_BackShadeColor, _BackShadeRatio));
            }
            else if (bsState == FlatButtonState.Over)
            {
                e.Graphics.Clear(_BackColorOver.Lerp(_BackShadeColor, _BackShadeRatio));
            }
            else
            {
                e.Graphics.Clear(this.BackColor.Lerp(_BackShadeColor, _BackShadeRatio));
            }

            Rectangle rect   = new Rectangle(0, 0, this.Width, this.Height);
            Size      szText = e.Graphics.MeasureString(_Text, this.Font).ToSize();

            if (_Image != null)
            {
                Rectangle rectImage = LayoutUtils.Align(_Image.Size + new Size(_ImagePadding * 2, _ImagePadding * 2), rect, _ImageAlign);
                rectImage.X += _ImagePadding;
                rectImage.Y += _ImagePadding;
                e.Graphics.DrawImage(_Image, new Rectangle(rectImage.Location, _Image.Size));
                if (_TextImageRelation == FlatTextImageRelation.After)
                {
                    using (SolidBrush brush = new SolidBrush(this.ForeColor)) {
                        e.Graphics.DrawString(_Text, this.Font, brush, new Point(
                                                  rectImage.X + _Image.Width + _ImagePadding,
                                                  rectImage.Y + _Image.Height / 2 - szText.Height / 2
                                                  ));
                    }
                }
                else if (_TextImageRelation == FlatTextImageRelation.Before)
                {
                    using (SolidBrush brush = new SolidBrush(this.ForeColor)) {
                        e.Graphics.DrawString(_Text, this.Font, brush, new Point(
                                                  rectImage.X - szText.Width - _ImagePadding,
                                                  rectImage.Y + _Image.Height / 2 - szText.Height / 2
                                                  ));
                    }
                }
                else
                {
                    DrawTextNormal(szText, rect, e);
                }
            }
            else
            {
                DrawTextNormal(szText, rect, e);
            }

            if (_HasBorder)
            {
                using (Pen pen = new Pen(_BorderColor)) {
                    e.Graphics.DrawRectangle(pen, new Rectangle(0, 0, this.Width - 1, this.Height - 1));
                }
            }

            base.OnPaint(e);
        }
示例#16
0
        protected virtual SizeF ArrangeGroupedHorizontal(SizeF finalSize)
        {
            float x      = this.clientRect.X + this.ScrollOffset.Width;
            float y      = this.clientRect.Y;
            float val1_1 = 0.0f;
            float val1_2 = 0.0f;
            int   num    = 0;
            BaseListViewGroupVisualItem viewGroupVisualItem = (BaseListViewGroupVisualItem)null;

            foreach (RadElement child in this.Children)
            {
                BaseListViewVisualItem listViewVisualItem = child as BaseListViewVisualItem;
                ++num;
                if (listViewVisualItem != null && listViewVisualItem.Data != null)
                {
                    Size size = this.ElementProvider.GetElementSize(listViewVisualItem.Data).ToSize();
                    if (child is BaseListViewGroupVisualItem)
                    {
                        if ((double)y != (double)this.clientRect.Y)
                        {
                            y      = this.clientRect.Y;
                            x     += val1_2;
                            val1_2 = 0.0f;
                        }
                        if (num == 1)
                        {
                            viewGroupVisualItem = child as BaseListViewGroupVisualItem;
                        }
                        else if (viewGroupVisualItem != null)
                        {
                            SizeF      elementSize = this.ElementProvider.GetElementSize(viewGroupVisualItem.Data);
                            RectangleF finalRect   = new RectangleF(new PointF(x - elementSize.Width, (float)this.Padding.Top), elementSize);
                            viewGroupVisualItem.Arrange(finalRect);
                            viewGroupVisualItem = (BaseListViewGroupVisualItem)null;
                        }
                        if (((BaseListViewVisualItem)child).Data != this.owner.Scroller.Traverser.Current && (this.owner.Scroller.Traverser.Current == null || this.owner.Scroller.Traverser.Current.Group != ((BaseListViewVisualItem)child).Data))
                        {
                            x += (float)this.owner.GroupIndent;
                        }
                        RectangleF rectangleF = new RectangleF(new PointF(x, (float)this.Padding.Top), (SizeF)size);
                        if (this.RightToLeft)
                        {
                            rectangleF = LayoutUtils.RTLTranslateNonRelative(rectangleF, this.clientRect);
                        }
                        child.Arrange(rectangleF);
                        if (!(child as BaseListViewGroupVisualItem).HasVisibleItems())
                        {
                            x += (float)size.Width;
                        }
                    }
                    else
                    {
                        if ((double)y + (double)size.Height > (double)this.clientRect.Bottom)
                        {
                            y      = this.clientRect.Y;
                            x     += val1_2 + (float)this.ItemSpacing;
                            val1_2 = (float)size.Width;
                        }
                        val1_1 = Math.Max(val1_1, (float)size.Height);
                        val1_2 = Math.Max(val1_2, (float)size.Width);
                        RectangleF rectangleF = new RectangleF(new PointF(x, y), (SizeF)size);
                        if (this.RightToLeft)
                        {
                            rectangleF = LayoutUtils.RTLTranslateNonRelative(rectangleF, this.clientRect);
                        }
                        child.Arrange(rectangleF);
                        y += (float)(size.Height + this.ItemSpacing);
                    }
                }
            }
            return(finalSize);
        }
示例#17
0
        [SuppressMessage("Microsoft.Globalization", "CA1303:DoNotPassLiteralsAsLocalizedParameters")]     // using "\t" to figure out the width of tab
        private void  CalculateInternalLayoutMetrics()
        {
            Size maxTextSize        = Size.Empty;
            Size maxImageSize       = Size.Empty;
            Size maxCheckSize       = scaledDefaultImageSize;
            Size maxArrowSize       = Size.Empty;
            Size maxNonMenuItemSize = Size.Empty;

            // determine Text Metrics
            for (int i = 0; i < Items.Count; i++)
            {
                ToolStripItem     item     = Items[i];
                ToolStripMenuItem menuItem = item as ToolStripMenuItem;

                if (menuItem != null)
                {
                    Size menuItemTextSize = menuItem.GetTextSize();

                    if (menuItem.ShowShortcutKeys)
                    {
                        Size shortcutTextSize = menuItem.GetShortcutTextSize();
                        if (tabWidth == -1)
                        {
                            tabWidth = TextRenderer.MeasureText("\t", this.Font).Width;
                        }
                        menuItemTextSize.Width += tabWidth + shortcutTextSize.Width;
                        menuItemTextSize.Height = Math.Max(menuItemTextSize.Height, shortcutTextSize.Height);
                    }

                    // we truly only care about the maximum size we find.
                    maxTextSize.Width  = Math.Max(maxTextSize.Width, menuItemTextSize.Width);
                    maxTextSize.Height = Math.Max(maxTextSize.Height, menuItemTextSize.Height);

                    // determine Image Metrics
                    Size imageSize = Size.Empty;
                    if (menuItem.Image != null)
                    {
                        imageSize = (menuItem.ImageScaling == ToolStripItemImageScaling.SizeToFit) ? ImageScalingSize : menuItem.Image.Size;
                    }

                    maxImageSize.Width  = Math.Max(maxImageSize.Width, imageSize.Width);
                    maxImageSize.Height = Math.Max(maxImageSize.Height, imageSize.Height);

                    if (menuItem.CheckedImage != null)
                    {
                        Size checkedImageSize = menuItem.CheckedImage.Size;
                        maxCheckSize.Width  = Math.Max(checkedImageSize.Width, maxCheckSize.Width);
                        maxCheckSize.Height = Math.Max(checkedImageSize.Height, maxCheckSize.Height);
                    }
                }
                else if (!(item is ToolStripSeparator))
                {
                    maxNonMenuItemSize.Height = Math.Max(item.Bounds.Height, maxNonMenuItemSize.Height);
                    maxNonMenuItemSize.Width  = Math.Max(item.Bounds.Width, maxNonMenuItemSize.Width);
                }
            }

            this.maxItemSize.Height = Math.Max(maxTextSize.Height + scaledTextPadding.Vertical, Math.Max(maxCheckSize.Height + scaledCheckPadding.Vertical, maxArrowSize.Height + scaledArrowPadding.Vertical));

            if (ShowImageMargin)
            {
                // only add in the image into the calculation if we're going to render it.
                this.maxItemSize.Height = Math.Max(maxImageSize.Height + scaledImagePadding.Vertical, maxItemSize.Height);
            }

            bool useDefaultCheckMarginWidth = (ShowCheckMargin && (maxCheckSize.Width == 0));
            bool useDefaultImageMarginWidth = (ShowImageMargin && (maxImageSize.Width == 0));

            // Always save space for an arrow
            maxArrowSize = new Size(scaledArrowSize, maxItemSize.Height);

            maxTextSize.Height  = maxItemSize.Height - scaledTextPadding.Vertical;
            maxImageSize.Height = maxItemSize.Height - scaledImagePadding.Vertical;
            maxCheckSize.Height = maxItemSize.Height - scaledCheckPadding.Vertical;

            // fixup if there are non-menu items that are larger than our normal menu items
            maxTextSize.Width = Math.Max(maxTextSize.Width, maxNonMenuItemSize.Width);

            Point nextPoint = Point.Empty;
            int   checkAndImageMarginWidth = 0;

            int extraImageWidth = Math.Max(0, maxImageSize.Width - scaledDefaultImageSize.Width);

            if (ShowCheckMargin && ShowImageMargin)
            {
                // double column - check margin then image margin
                // default to 46px - grow if necessary.
                checkAndImageMarginWidth = scaledDefaultImageAndCheckMarginWidth;

                // add in the extra space for the image... since the check size is locked down to 16x16.
                checkAndImageMarginWidth += extraImageWidth;

                // align the checkmark
                nextPoint      = new Point(scaledCheckPadding.Left, scaledCheckPadding.Top);
                checkRectangle = LayoutUtils.Align(maxCheckSize, new Rectangle(nextPoint.X, nextPoint.Y, maxCheckSize.Width, maxItemSize.Height), ContentAlignment.MiddleCenter);

                // align the image rectangle
                nextPoint.X    = checkRectangle.Right + scaledCheckPadding.Right + scaledImagePadding.Left;
                nextPoint.Y    = scaledImagePadding.Top;
                imageRectangle = LayoutUtils.Align(maxImageSize, new Rectangle(nextPoint.X, nextPoint.Y, maxImageSize.Width, maxItemSize.Height), ContentAlignment.MiddleCenter);
            }
            else if (ShowCheckMargin)
            {
                // no images should be shown in a ShowCheckMargin only scenario.
                // default to 24px - grow if necessary.
                checkAndImageMarginWidth = scaledDefaultImageMarginWidth;

                // align the checkmark
                nextPoint = new Point(1, scaledCheckPadding.Top);
                //    nextPoint = new Point(scaledCheckPadding.Left, scaledCheckPadding.Top);
                checkRectangle = LayoutUtils.Align(maxCheckSize, new Rectangle(nextPoint.X, nextPoint.Y, checkAndImageMarginWidth, maxItemSize.Height), ContentAlignment.MiddleCenter);

                imageRectangle = Rectangle.Empty;
            }
            else if (ShowImageMargin)
            {
                // checks and images render in the same area.

                // default to 24px - grow if necessary.
                checkAndImageMarginWidth = scaledDefaultImageMarginWidth;

                // add in the extra space for the image... since the check size is locked down to 16x16.
                checkAndImageMarginWidth += extraImageWidth;

                // NOTE due to the Padding property, we're going to have to recalc the vertical alignment in ToolStripMenuItemInternalLayout.
                // Dont fuss here over the Y, X is what's critical.

                // check and image rect are the same - take the max of the image size and the check size and align
                nextPoint      = new Point(1, scaledCheckPadding.Top);
                checkRectangle = LayoutUtils.Align(LayoutUtils.UnionSizes(maxCheckSize, maxImageSize), new Rectangle(nextPoint.X, nextPoint.Y, checkAndImageMarginWidth - 1, maxItemSize.Height), ContentAlignment.MiddleCenter);

                // align the image
                imageRectangle = checkRectangle;
            }
            else
            {
                checkAndImageMarginWidth = 0;
            }
            nextPoint.X = checkAndImageMarginWidth + 1;


            // calculate space for image
            // if we didnt have a check - make sure to ignore check padding

            // consider: should we constrain to a reasonable width?
            //imageMarginBounds = new Rectangle(0, 0, Math.Max(imageMarginWidth,DefaultImageMarginWidth), this.Height);
            imageMarginBounds = new Rectangle(0, 0, checkAndImageMarginWidth, this.Height);

            // calculate space for shortcut and text
            nextPoint.X   = imageMarginBounds.Right + scaledTextPadding.Left;
            nextPoint.Y   = scaledTextPadding.Top;
            textRectangle = new Rectangle(nextPoint, maxTextSize);

            // calculate space for arrow
            nextPoint.X    = textRectangle.Right + scaledTextPadding.Right + scaledArrowPadding.Left;
            nextPoint.Y    = scaledArrowPadding.Top;
            arrowRectangle = new Rectangle(nextPoint, maxArrowSize);

            // calculate space required for all of these pieces
            this.maxItemSize.Width = (arrowRectangle.Right + scaledArrowPadding.Right) - imageMarginBounds.Left;

            this.Padding = DefaultPadding;
            int trimPadding = imageMarginBounds.Width;

            if (RightToLeft == RightToLeft.Yes)
            {
                // reverse the rectangle alignment in RightToLeft.Yes
                trimPadding += scaledTextPadding.Right;
                int width = maxItemSize.Width;
                checkRectangle.X    = width - checkRectangle.Right;
                imageRectangle.X    = width - imageRectangle.Right;
                textRectangle.X     = width - textRectangle.Right;
                arrowRectangle.X    = width - arrowRectangle.Right;
                imageMarginBounds.X = width - imageMarginBounds.Right;
            }
            else
            {
                trimPadding += scaledTextPadding.Left;
            }



            // VSWhidbey 339274 - we need to make sure that the text really appears vertically centered - this can be a problem in
            // systems which force the text rectangle to be odd.

            // force this to be an even height.
            this.maxItemSize.Height += this.maxItemSize.Height % 2;

            textRectangle.Y  = LayoutUtils.VAlign(textRectangle.Size, new Rectangle(Point.Empty, maxItemSize), ContentAlignment.MiddleCenter).Y;
            textRectangle.Y += (textRectangle.Height % 2);    // if the height is odd, push down by one px, see 339274 for picture
            state[stateMaxItemSizeValid] = true;
            this.PaddingToTrim           = trimPadding;
        }
示例#18
0
 public IDictionary <int, Point> NormalizePositions([NotNull] IDictionary <int, Point> verticesPositions)
 {
     LayoutUtils.NormalizePositions(verticesPositions);
     return(verticesPositions);
 }
示例#19
0
 public static TextImageRelation TextAlignToRelation(ContentAlignment alignment)
 {
     return(LayoutUtils.GetOppositeTextImageRelation(TelerikAlignHelper.ImageAlignToRelation(alignment)));
 }
示例#20
0
 public bool IsSameDirection(Vector a, Vector b)
 {
     return(LayoutUtils.IsSameDirection(a, b));
 }
示例#21
0
 protected override void ProcessLassoSelection(Rectangle selectionRect)
 {
     if (!this.Owner.MultiSelect)
     {
         base.ProcessLassoSelection(selectionRect);
     }
     else
     {
         Rectangle rectangle1 = new Rectangle(this.ViewElement.Padding.Left, this.ViewElement.Padding.Top, this.ViewElement.Size.Width - this.ViewElement.Padding.Horizontal, this.ViewElement.Size.Height - this.ViewElement.Padding.Vertical);
         if (this.RightToLeft)
         {
             rectangle1 = LayoutUtils.RTLTranslateNonRelative(rectangle1, this.ControlBoundingRectangle);
         }
         selectionRect.Offset(-rectangle1.Location.X, -rectangle1.Location.Y);
         ListViewTraverser enumerator = this.Scroller.Traverser.GetEnumerator() as ListViewTraverser;
         int x1 = rectangle1.X;
         int y  = rectangle1.Y;
         enumerator.Reset();
         int val1_1 = 0;
         int val1_2 = 0;
         while (enumerator.MoveNext())
         {
             if (enumerator.Current.Owner == this.Owner)
             {
                 Size actualSize = enumerator.Current.ActualSize;
                 val1_1 = Math.Max(val1_1, actualSize.Height);
                 val1_2 = Math.Max(val1_2, actualSize.Width);
                 if (enumerator.Current is ListViewDataItemGroup)
                 {
                     if (x1 != rectangle1.X)
                     {
                         int x2 = rectangle1.X;
                         y     += val1_1;
                         val1_1 = actualSize.Height;
                     }
                     x1 = rectangle1.X;
                     y += actualSize.Height + this.ItemSpacing;
                 }
                 else
                 {
                     if (x1 + actualSize.Width > rectangle1.Right && this.Orientation == Orientation.Vertical)
                     {
                         x1     = rectangle1.X;
                         y     += val1_1 + this.ItemSpacing;
                         val1_1 = actualSize.Height;
                     }
                     else if (y + actualSize.Height > rectangle1.Bottom && this.Orientation == Orientation.Horizontal)
                     {
                         y      = rectangle1.Y;
                         x1    += val1_2 + this.ItemSpacing;
                         val1_2 = actualSize.Width;
                     }
                     if (x1 == rectangle1.X && this.Owner.ShowGroups && (this.Owner.EnableCustomGrouping || this.Owner.EnableGrouping) && (this.Owner.Groups.Count > 0 && !this.Owner.FullRowSelect))
                     {
                         x1 += this.Owner.GroupIndent;
                     }
                     Rectangle rectangle2 = new Rectangle(new Point(x1, y), actualSize);
                     if (this.RightToLeft)
                     {
                         rectangle2 = LayoutUtils.RTLTranslateNonRelative(rectangle2, rectangle1);
                     }
                     this.ProcessItemLassoSelection(enumerator.Current, selectionRect.IntersectsWith(rectangle2));
                     if (this.Orientation == Orientation.Vertical)
                     {
                         x1 += actualSize.Width + this.ItemSpacing;
                     }
                     else
                     {
                         y += actualSize.Height + this.ItemSpacing;
                     }
                 }
             }
         }
     }
 }
示例#22
0
        protected override SizeF ArrangeOverride(SizeF finalSize)
        {
            float num1 = 0.0f;
            float num2 = 0.0f;
            int   num3 = 0;

            for (int index = 0; index < this.Children.Count; ++index)
            {
                RadElement child       = this.Children[index];
                SizeF      defaultSize = (SizeF)((VisualElement)child).DefaultSize;
                if (!(bool)child.GetValue(StatusBarBoxLayout.SpringProperty))
                {
                    num1 += Math.Max(child.DesiredSize.Width, defaultSize.Width);
                    num2 += Math.Max(child.DesiredSize.Height, defaultSize.Height);
                }
                else
                {
                    ++num3;
                }
            }
            float num4 = this.Orientation != Orientation.Horizontal ? finalSize.Height - num2 : finalSize.Width - num1;
            float num5 = 0.0f;

            if (num3 != 0)
            {
                num5 = num4 / (float)num3;
            }
            PointF empty1 = PointF.Empty;
            SizeF  empty2 = SizeF.Empty;
            bool   flag   = false;

            if (this.Orientation == Orientation.Horizontal)
            {
                empty2.Height = finalSize.Height;
                for (int index = 0; index < this.Children.Count; ++index)
                {
                    RadElement child = this.Children[index];
                    if ((bool)child.GetValue(StatusBarBoxLayout.SpringProperty) && (double)num5 <= (double)child.DesiredSize.Width)
                    {
                        flag = true;
                        break;
                    }
                }
                for (int index = 0; index < this.Children.Count; ++index)
                {
                    RadElement child       = this.Children[index];
                    SizeF      defaultSize = (SizeF)((VisualElement)child).DefaultSize;
                    empty2.Width = (bool)child.GetValue(StatusBarBoxLayout.SpringProperty) ? num5 - 1f : Math.Max(child.DesiredSize.Width, defaultSize.Width);
                    RectangleF rectangleF = new RectangleF(empty1, empty2);
                    if (this.RightToLeft)
                    {
                        rectangleF = LayoutUtils.RTLTranslateNonRelative(rectangleF, new RectangleF(PointF.Empty, finalSize));
                    }
                    child.Arrange(rectangleF);
                    if (num3 == 0 && (double)empty1.X + (double)empty2.Width + (double)num3 >= (double)finalSize.Width && (double)finalSize.Width != 0.0 || num3 != 0 && flag && (double)empty1.X + (double)empty2.Width + (double)num3 >= (double)finalSize.Width || (double)empty2.Width < 0.0)
                    {
                        int num6 = (int)child.SetDefaultValueOverride(RadElement.VisibilityProperty, (object)ElementVisibility.Hidden);
                    }
                    else
                    {
                        int num7 = (int)child.SetDefaultValueOverride(RadElement.VisibilityProperty, (object)ElementVisibility.Visible);
                    }
                    empty1.X += empty2.Width;
                }
            }
            else
            {
                empty2.Width = finalSize.Width;
                for (int index = 0; index < this.Children.Count; ++index)
                {
                    RadElement child       = this.Children[index];
                    SizeF      defaultSize = (SizeF)((VisualElement)child).DefaultSize;
                    empty2.Height = (bool)child.GetValue(StatusBarBoxLayout.SpringProperty) ? num5 : Math.Max(child.DesiredSize.Height, defaultSize.Height);
                    child.Arrange(new RectangleF(empty1, empty2));
                    empty1.Y += empty2.Height;
                }
            }
            return(finalSize);
        }
            public virtual void DrawFlatCombo(ComboBox comboBox, Graphics g)
            {
                if (comboBox.DropDownStyle == ComboBoxStyle.Simple)
                {
                    return;
                }

                Color outerBorderColor = GetOuterBorderColor(comboBox);
                Color innerBorderColor = GetInnerBorderColor(comboBox);
                bool  rightToLeft      = comboBox.RightToLeft == RightToLeft.Yes;

                // Draw the drop down
                DrawFlatComboDropDown(comboBox, g, _dropDownRect);

                // When we are disabled there is one line of color that seems to eek through if backcolor is set
                // so lets erase it.
                if (!LayoutUtils.IsZeroWidthOrHeight(_whiteFillRect))
                {
                    // Fill in two more pixels with white so it looks smaller.
                    using var b = innerBorderColor.GetCachedSolidBrushScope();
                    g.FillRectangle(b, _whiteFillRect);
                }

                // Draw the outer border

                using var outerBorderPen = outerBorderColor.GetCachedPenScope();
                g.DrawRectangle(outerBorderPen, _outerBorder);
                if (rightToLeft)
                {
                    g.DrawRectangle(
                        outerBorderPen,
                        new Rectangle(_outerBorder.X, _outerBorder.Y, _dropDownRect.Width + 1, _outerBorder.Height));
                }
                else
                {
                    g.DrawRectangle(
                        outerBorderPen,
                        new Rectangle(_dropDownRect.X, _outerBorder.Y, _outerBorder.Right - _dropDownRect.X, _outerBorder.Height));
                }

                // Draw the inner border
                using var innerBorderPen = innerBorderColor.GetCachedPenScope();
                g.DrawRectangle(innerBorderPen, _innerBorder);
                g.DrawRectangle(innerBorderPen, _innerInnerBorder);

                // Draw a dark border around everything if we're in popup mode
                if ((!comboBox.Enabled) || (comboBox.FlatStyle == FlatStyle.Popup))
                {
                    bool  focused        = comboBox.ContainsFocus || comboBox.MouseIsOver;
                    Color borderPenColor = GetPopupOuterBorderColor(comboBox, focused);

                    using var borderPen = borderPenColor.GetCachedPenScope();
                    Pen innerPen = comboBox.Enabled ? borderPen : SystemPens.Control;

                    // Around the dropdown
                    if (rightToLeft)
                    {
                        g.DrawRectangle(
                            innerPen,
                            new Rectangle(_outerBorder.X, _outerBorder.Y, _dropDownRect.Width + 1, _outerBorder.Height));
                    }
                    else
                    {
                        g.DrawRectangle(
                            innerPen,
                            new Rectangle(_dropDownRect.X, _outerBorder.Y, _outerBorder.Right - _dropDownRect.X, _outerBorder.Height));
                    }

                    // Around the whole combobox.
                    g.DrawRectangle(borderPen, _outerBorder);
                }
            }
示例#24
0
        /// <summary>
        /// arranges the children by a given criteria
        /// </summary>
        /// <param name="finalSize"></param>
        /// <returns></returns>
        protected override SizeF ArrangeOverride(SizeF finalSize)
        {
            float      strechOffWidth  = 0f;
            float      strechOffHeight = 0f;
            int        strechOnCount   = 0;
            RadElement item            = null;

            for (int i = 0; i < this.Children.Count; ++i)
            {
                item = this.Children[i];


                SizeF defaultSize = ((VisualElement)item).DefaultSize;

                if ((bool)item.GetValue(StatusBarBoxLayout.SpringProperty) == false)
                {
                    strechOffWidth  += Math.Max(item.DesiredSize.Width, defaultSize.Width);
                    strechOffHeight += Math.Max(item.DesiredSize.Height, defaultSize.Height);;
                }
                else
                {
                    strechOnCount++;
                }
            }

            float spaceForAllStrechOn = 0f;

            if (this.Orientation == Orientation.Horizontal)
            {
                spaceForAllStrechOn = finalSize.Width - strechOffWidth;
            }
            else
            {
                spaceForAllStrechOn = finalSize.Height - strechOffHeight;
            }

            float spaceForSingleSpringElement = 0f;

            if (strechOnCount != 0)
            {
                spaceForSingleSpringElement = spaceForAllStrechOn / strechOnCount;
            }

            PointF firstPosition = PointF.Empty;
            SizeF  incrementSize = SizeF.Empty;

            bool springElementInMinSize = false;

            if (this.Orientation == Orientation.Horizontal)
            {
                incrementSize.Height = finalSize.Height;

                for (int i = 0; i < this.Children.Count; ++i)
                {
                    item = this.Children[i];
                    if ((bool)item.GetValue(StatusBarBoxLayout.SpringProperty))
                    {
                        if (spaceForSingleSpringElement <= item.DesiredSize.Width)
                        {
                            springElementInMinSize = true;
                            break;
                        }
                    }
                }

                for (int i = 0; i < this.Children.Count; ++i)
                {
                    item = this.Children[i];

                    SizeF defaultSize = ((VisualElement)item).DefaultSize;

                    if ((bool)item.GetValue(StatusBarBoxLayout.SpringProperty) == false)
                    {
                        incrementSize.Width = Math.Max(item.DesiredSize.Width, defaultSize.Width);
                    }
                    else
                    {
                        incrementSize.Width = spaceForSingleSpringElement - 1;
                    }
                    RectangleF arrangeRectangle = new RectangleF(firstPosition, incrementSize);
                    if (this.RightToLeft)
                    {
                        arrangeRectangle = LayoutUtils.RTLTranslateNonRelative(arrangeRectangle, new RectangleF(PointF.Empty, finalSize));
                    }
                    item.Arrange(arrangeRectangle);

                    if (
                        (
                            strechOnCount == 0 &&
                            firstPosition.X + incrementSize.Width + strechOnCount >= finalSize.Width &&
                            finalSize.Width != 0) ||
                        (
                            strechOnCount != 0 &&
                            springElementInMinSize == true &&
                            firstPosition.X + incrementSize.Width + strechOnCount >= finalSize.Width) ||
                        (
                            incrementSize.Width < 0)
                        )
                    {
                        item.SetDefaultValueOverride(RadElement.VisibilityProperty, ElementVisibility.Hidden);
                    }
                    else
                    {
                        item.SetDefaultValueOverride(RadElement.VisibilityProperty, ElementVisibility.Visible);
                    }

                    firstPosition.X += incrementSize.Width;
                }
            }
            else//vertical
            {
                incrementSize.Width = finalSize.Width;

                for (int i = 0; i < this.Children.Count; ++i)
                {
                    item = this.Children[i];
                    SizeF defaultSize = ((VisualElement)item).DefaultSize;

                    if ((bool)item.GetValue(StatusBarBoxLayout.SpringProperty) == false)
                    {
                        incrementSize.Height = Math.Max(item.DesiredSize.Height, defaultSize.Height);
                    }
                    else
                    {
                        incrementSize.Height = spaceForSingleSpringElement;
                    }

                    item.Arrange(new RectangleF(firstPosition, incrementSize));
                    firstPosition.Y += incrementSize.Height;
                }
            }
            return(finalSize);
        }
        private bool LayoutHorizontal()
        {
            ToolStrip toolStrip       = ToolStrip;
            Rectangle clientRectangle = toolStrip.ClientRectangle;

#if DEBUG
            if (DebugLayoutTraceSwitch.TraceVerbose)
            {
                Debug.WriteLine("_________________________\r\nHorizontal Layout:" + toolStrip.ToString() + displayRectangle.ToString());
            }
#endif

            int       lastRight         = displayRectangle.Right;
            int       lastLeft          = displayRectangle.Left;
            bool      needsMoreSpace    = false;
            Size      itemSize          = Size.Empty;
            Rectangle alignedLeftItems  = Rectangle.Empty;
            Rectangle alignedRightItems = Rectangle.Empty;

            // this will determine where the item should be placed.
            CalculatePlacementsHorizontal();

            bool needOverflow = toolStrip.CanOverflow && ((OverflowRequired) || (OverflowSpace >= OverflowButtonSize.Width));
            toolStrip.OverflowButton.Visible = needOverflow;

            // if we require the overflow, it should stick up against the edge of the toolstrip.
            if (needOverflow)
            {
                if (toolStrip.RightToLeft == RightToLeft.No)
                {
                    lastRight = clientRectangle.Right;
                }
                else
                {
                    lastLeft = clientRectangle.Left;
                }
            }

            for (int j = -1; j < toolStrip.Items.Count; j++)
            {
                ToolStripItem item = null;

                if (j == -1)
                {
                    // the first time through place the overflow button if its required.
                    if (needOverflow)
                    {
                        item = toolStrip.OverflowButton;
                        item.SetPlacement(ToolStripItemPlacement.Main);
                        itemSize = OverflowButtonSize;
                    }
                    else
                    {
                        item = toolStrip.OverflowButton;
                        item.SetPlacement(ToolStripItemPlacement.None);
                        continue;
                    }
                }
                else
                {
                    item = toolStrip.Items[j];

                    if (!((IArrangedElement)item).ParticipatesInLayout)
                    {
                        // skip over items not participating in layout.  E.G. not visible items
                        continue;
                    }

                    // since we havent parented the item yet - the auto size wont have reset the size yet.
                    itemSize = item.AutoSize ? item.GetPreferredSize(Size.Empty) : item.Size;
                }

                // if it turns out we dont need the overflow (because there are no Overflow.Always items and the width of everything
                // in the overflow is less than the width of the overflow button then reset the placement of the as needed items to
                // main.
                if (!needOverflow && (item.Overflow == ToolStripItemOverflow.AsNeeded && item.Placement == ToolStripItemPlacement.Overflow))
                {
#if DEBUG
                    if (DebugLayoutTraceSwitch.TraceVerbose)
                    {
                        Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Resetting {0} to Main - we dont need it to overflow", item));
                    }
#endif
                    item.SetPlacement(ToolStripItemPlacement.Main);
                }

                // Now do the guts of setting X, Y and parenting.
                // We need to honor left to right and head and tail.
                //      In RTL.Yes, Head is to the Right, Tail is to the Left
                //      In RTL.No,  Head is to the Left,  Tail is to the Right
                if ((item != null) && (item.Placement == ToolStripItemPlacement.Main))
                {
                    int     x          = displayRectangle.Left;
                    int     y          = displayRectangle.Top;
                    Padding itemMargin = item.Margin;

                    if (((item.Alignment == ToolStripItemAlignment.Right) && (toolStrip.RightToLeft == RightToLeft.No)) || ((item.Alignment == ToolStripItemAlignment.Left) && (toolStrip.RightToLeft == RightToLeft.Yes)))
                    {
                        //                  lastRight   x     Margin.Right
                        //             [Item]<----------[Item]----------->|
                        //                   Margin.Left
                        // this item should be placed to the right
                        // we work backwards from the right edge - that is place items from right to left.
                        x                 = lastRight - (itemMargin.Right + itemSize.Width);
                        y                += itemMargin.Top;
                        lastRight         = x - itemMargin.Left;
                        alignedRightItems = (alignedRightItems == Rectangle.Empty) ? new Rectangle(x, y, itemSize.Width, itemSize.Height)
                                                : Rectangle.Union(alignedRightItems, new Rectangle(x, y, itemSize.Width, itemSize.Height));
                    }
                    else
                    {
                        //             x     Margin.Right lastLeft
                        // |<----------[Item]------------>|
                        //  Margin.Left
                        // this item should be placed to the left
                        // we work forwards from the left - that is place items from left to right
                        x                = lastLeft + itemMargin.Left;
                        y               += itemMargin.Top;
                        lastLeft         = x + itemSize.Width + itemMargin.Right;
                        alignedLeftItems = (alignedLeftItems == Rectangle.Empty) ? new Rectangle(x, y, itemSize.Width, itemSize.Height)
                                                : Rectangle.Union(alignedLeftItems, new Rectangle(x, y, itemSize.Width, itemSize.Height));
                    }

                    item.ParentInternal = ToolStrip;

                    Point itemLocation = new Point(x, y);
                    if (!clientRectangle.Contains(x, y))
                    {
                        item.SetPlacement(ToolStripItemPlacement.None);
                    }
                    else if (alignedRightItems.Width > 0 && alignedLeftItems.Width > 0 && alignedRightItems.IntersectsWith(alignedLeftItems))
                    {
                        itemLocation = noMansLand;
                        item.SetPlacement(ToolStripItemPlacement.None);
                    }

                    if (item.AutoSize)
                    {
                        // autosized items stretch from edge-edge
                        itemSize.Height = Math.Max(displayRectangle.Height - itemMargin.Vertical, 0);
                    }
                    else
                    {
                        // non autosized items are vertically centered
                        Rectangle bounds = LayoutUtils.VAlign(item.Size, displayRectangle, AnchorStyles.None);
                        itemLocation.Y = bounds.Y;
                    }

                    SetItemLocation(item, itemLocation, itemSize);
                }
                else
                {
                    item.ParentInternal = (item.Placement == ToolStripItemPlacement.Overflow) ? toolStrip.OverflowButton.DropDown : null;
                }
#if DEBUG
                if (DebugLayoutTraceSwitch.TraceVerbose)
                {
                    Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Item {0} Placement {1} Bounds {2} Parent {3}", item.ToString(), item.Placement.ToString(), item.Bounds.ToString(), (item.ParentInternal is null) ? "null" : item.ParentInternal.ToString()));
                }
#endif
            }

            return(needsMoreSpace);
        }
示例#26
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Color nearestColor;

            this.Animate();
            Rectangle r = LayoutUtils.DeflateRect(base.ClientRectangle, base.Padding);

            ImageAnimator.UpdateFrames();
            System.Drawing.Image image = this.Image;
            if (image != null)
            {
                this.DrawImage(e.Graphics, image, r, base.RtlTranslateAlignment(this.ImageAlign));
            }
            IntPtr hdc = e.Graphics.GetHdc();

            try
            {
                using (WindowsGraphics graphics = WindowsGraphics.FromHdc(hdc))
                {
                    nearestColor = graphics.GetNearestColor(base.Enabled ? this.ForeColor : base.DisabledColor);
                }
            }
            finally
            {
                e.Graphics.ReleaseHdc();
            }
            if (this.AutoEllipsis)
            {
                Rectangle clientRectangle = base.ClientRectangle;
                Size      preferredSize   = this.GetPreferredSize(new Size(clientRectangle.Width, clientRectangle.Height));
                this.showToolTip = (clientRectangle.Width < preferredSize.Width) || (clientRectangle.Height < preferredSize.Height);
            }
            else
            {
                this.showToolTip = false;
            }
            if (this.UseCompatibleTextRendering)
            {
                using (StringFormat format = this.CreateStringFormat())
                {
                    if (base.Enabled)
                    {
                        using (Brush brush = new SolidBrush(nearestColor))
                        {
                            e.Graphics.DrawString(this.Text, this.Font, brush, r, format);
                            goto Label_01BF;
                        }
                    }
                    ControlPaint.DrawStringDisabled(e.Graphics, this.Text, this.Font, nearestColor, r, format);
                    goto Label_01BF;
                }
            }
            TextFormatFlags flags = this.CreateTextFormatFlags();

            if (base.Enabled)
            {
                TextRenderer.DrawText(e.Graphics, this.Text, this.Font, r, nearestColor, flags);
            }
            else
            {
                Color foreColor = TextRenderer.DisabledTextColor(this.BackColor);
                TextRenderer.DrawText(e.Graphics, this.Text, this.Font, r, foreColor, flags);
            }
Label_01BF:
            base.OnPaint(e);
        }