示例#1
0
        protected virtual Size OnGetRequiredSize(SizeConstraint widthConstraint)
        {
                        #pragma warning disable 618
            return(OnGetRequiredSize());

                        #pragma warning restore 618
        }
示例#2
0
        protected override Size OnGetPreferredSize(SizeConstraint widthConstraint, SizeConstraint heightConstraint)
        {
            if (child != null)
            {
                var s = new Size(child.Margin.HorizontalSpacing + Padding.HorizontalSpacing, child.Margin.VerticalSpacing + Padding.VerticalSpacing);

                if (widthConstraint.IsConstrained)
                {
                    widthConstraint = widthConstraint.AvailableSize - s.Width;
                    if (widthConstraint.AvailableSize <= 0)
                    {
                        return(s);
                    }
                }
                if (heightConstraint.IsConstrained)
                {
                    heightConstraint = heightConstraint.AvailableSize - child.Margin.VerticalSpacing - Padding.VerticalSpacing;
                    if (heightConstraint.AvailableSize <= 0)
                    {
                        return(s);
                    }
                }
                return(s + child.Surface.GetPreferredSize(widthConstraint, heightConstraint));
            }
            else
            {
                return(new Size(Padding.HorizontalSpacing, Padding.VerticalSpacing));
            }
        }
示例#3
0
        // Get the preferred size of each child widget, including the margins
        Size[] GetPreferredChildrenSizes(TablePlacement[] visibleChildren, bool useWidthConstraint, bool useHeightConstraint)
        {
            var sizes = new Size [visibleChildren.Length];

            for (int n = 0; n < visibleChildren.Length; n++)
            {
                var  bp = visibleChildren[n];
                Size s;
                if (useWidthConstraint)
                {
                    s = bp.Child.Surface.GetPreferredSize(SizeConstraint.WithSize(bp.NextWidth - bp.Child.Margin.HorizontalSpacing), SizeConstraint.Unconstrained);
                }
                else if (useHeightConstraint)
                {
                    s = bp.Child.Surface.GetPreferredSize(SizeConstraint.Unconstrained, SizeConstraint.WithSize(bp.NextHeight - bp.Child.Margin.VerticalSpacing));
                }
                else
                {
                    s = bp.Child.Surface.GetPreferredSize(SizeConstraint.Unconstrained, SizeConstraint.Unconstrained);
                }
                s.Width  += bp.Child.Margin.HorizontalSpacing;
                s.Height += bp.Child.Margin.VerticalSpacing;
                sizes [n] = s;
            }
            return(sizes);
        }
示例#4
0
        protected override Size OnGetPreferredSize(SizeConstraint widthConstraint, SizeConstraint heightConstraint)
        {
            var wc = widthConstraint.IsConstrained ? widthConstraint.AvailableSize : double.PositiveInfinity;
            var hc = heightConstraint.IsConstrained ? heightConstraint.AvailableSize : double.PositiveInfinity;

            return(GetPreferredSize(wc, hc));
        }
示例#5
0
文件: FrameBox.cs 项目: m13253/xwt
			protected override Size OnGetPreferredSize (SizeConstraint widthConstraint, SizeConstraint heightConstraint)
			{
				FrameBox parent = (FrameBox)Parent;
				Size s = new Size (parent.Padding.HorizontalSpacing + parent.BorderWidth.HorizontalSpacing, parent.Padding.VerticalSpacing + parent.BorderWidth.VerticalSpacing);
				if (child != null)
					s += child.Surface.GetPreferredSize (widthConstraint - s.Width, heightConstraint - s.Height, true);
				return s;
			}
示例#6
0
			protected override Size OnGetPreferredSize (SizeConstraint widthConstraint, SizeConstraint heightConstraint)
			{
				var parent = (RoundedFrameBox)Parent;
				var s = new Size (Math.Max (parent.Padding.HorizontalSpacing, Math.Max (parent.BorderSpacing.HorizontalSpacing, parent.CornerRadius.Spacing.HorizontalSpacing)),
				                  Math.Max (parent.Padding.VerticalSpacing, Math.Max (parent.BorderSpacing.VerticalSpacing, parent.CornerRadius.Spacing.VerticalSpacing)));
				if (child != null)
					s += child.Surface.GetPreferredSize (widthConstraint - s.Width, heightConstraint - s.Height, true);
				return s;
			}
示例#7
0
文件: Box.cs 项目: wesreid/xwt
        void CalcDefaultSizes(double width, double height)
        {
            bool   vertical      = direction == Orientation.Vertical;
            int    nexpands      = 0;
            double requiredSize  = 0;
            double availableSize = vertical ? height : width;

            var widthConstraint  = vertical ? SizeConstraint.WithSize(width) : SizeConstraint.Unconstrained;
            var heightConstraint = vertical ? SizeConstraint.Unconstrained : SizeConstraint.WithSize(height);

            var visibleChildren = children.Where(b => b.Child.Visible).ToArray();
            var sizes           = new Dictionary <BoxPlacement, double> ();

            // Get the natural size of each child
            foreach (var bp in visibleChildren)
            {
                Size s;
                s             = bp.Child.Surface.GetPreferredSize(widthConstraint, heightConstraint, true);
                bp.NextSize   = vertical ? s.Height : s.Width;
                sizes [bp]    = bp.NextSize;
                requiredSize += bp.NextSize;
                if (bp.Child.ExpandsForOrientation(direction))
                {
                    nexpands++;
                }
            }

            double remaining = availableSize - requiredSize - (spacing * (double)(visibleChildren.Length - 1));

            if (remaining < 0)
            {
                // The box is not big enough to fit the widgets using its natural size.
                // We have to shrink the widgets.

                // The total amount we have to shrink
                double shrinkSize = -remaining;

                var sizePart = new SizeSplitter(shrinkSize, visibleChildren.Length);
                foreach (var bp in visibleChildren)
                {
                    bp.NextSize -= sizePart.NextSizePart();
                }
            }
            else
            {
                var expandRemaining = new SizeSplitter(remaining, nexpands);
                foreach (var bp in visibleChildren)
                {
                    if (bp.Child.ExpandsForOrientation(direction))
                    {
                        bp.NextSize += expandRemaining.NextSizePart();
                    }
                }
            }
        }
示例#8
0
文件: Box.cs 项目: wwwK/xwt
        protected override Size OnGetPreferredSize(SizeConstraint widthConstraint, SizeConstraint heightConstraint)
        {
            Size s     = new Size();
            int  count = 0;

            var visibleChildren = children.Where(b => b.Child.Visible).ToArray();

            if (direction == Orientation.Horizontal)
            {
                // If the width is constrained then we have a total width, and we can calculate the exact width assigned to each child.
                // We can then use that width as a width constraint for the child.

                if (widthConstraint.IsConstrained)
                {
                    CalcDefaultSizes(widthConstraint, heightConstraint, false);                      // Calculates the width assigned to each child
                }
                foreach (var cw in visibleChildren)
                {
                    // Use the calculated width if available
                    var wsize = cw.Child.Surface.GetPreferredSize(widthConstraint.IsConstrained ? cw.NextSize : SizeConstraint.Unconstrained, heightConstraint, true);
                    s.Width += wsize.Width;
                    if (wsize.Height > s.Height)
                    {
                        s.Height = wsize.Height;
                    }
                    count++;
                }
                if (count > 0)
                {
                    s.Width += spacing * (double)(count - 1);
                }
            }
            else
            {
                if (heightConstraint.IsConstrained)
                {
                    CalcDefaultSizes(widthConstraint, heightConstraint, false);
                }
                foreach (var cw in visibleChildren)
                {
                    var wsize = cw.Child.Surface.GetPreferredSize(widthConstraint, heightConstraint.IsConstrained ? cw.NextSize : SizeConstraint.Unconstrained, true);
                    s.Height += wsize.Height;
                    if (wsize.Width > s.Width)
                    {
                        s.Width = wsize.Width;
                    }
                    count++;
                }
                if (count > 0)
                {
                    s.Height += spacing * (double)(count - 1);
                }
            }
            return(s);
        }
示例#9
0
            protected override Size OnGetPreferredSize(SizeConstraint widthConstraint, SizeConstraint heightConstraint)
            {
                FrameBox parent = (FrameBox)Parent;
                Size     s      = new Size(parent.Padding.HorizontalSpacing + parent.BorderWidth.HorizontalSpacing, parent.Padding.VerticalSpacing + parent.BorderWidth.VerticalSpacing);

                if (child != null)
                {
                    s += child.Surface.GetPreferredSize(widthConstraint - s.Width, heightConstraint - s.Height, true);
                }
                return(s);
            }
示例#10
0
 public static SizeConstraint operator -(SizeConstraint c, double s)
 {
     if (!c.IsConstrained)
     {
         return(c);
     }
     else
     {
         return(SizeConstraint.WithSize(Math.Max(c.AvailableSize - s, 0)));
     }
 }
示例#11
0
 public static SizeConstraint operator +(SizeConstraint c, double s)
 {
     if (!c.IsConstrained)
     {
         return(c);
     }
     else
     {
         return(SizeConstraint.WithSize(c.AvailableSize + s));
     }
 }
示例#12
0
        protected override Size OnGetPreferredSize(SizeConstraint widthConstraint, SizeConstraint heightConstraint)
        {
            //GTK 3 has some trouble setting correct sizes... this fixes it
            if (Toolkit.CurrentEngine.Type == ToolkitType.Gtk3)
            {
                this.WidthRequest = ComputedWidth;
                this.HeightRequest = textViewMargin.LineHeight * (editor.Document.LineCount + 1);
            }

            return new Size(ComputedWidth, textViewMargin.LineHeight * editor.Document.LineCount);
        }
示例#13
0
 // The height of this widget is always half of the width
 protected override Size OnGetPreferredSize(SizeConstraint widthConstraint, SizeConstraint heightConstraint)
 {
     if (widthConstraint.IsConstrained)
     {
         var w = forceSize ? Math.Max(size, widthConstraint.AvailableSize) : widthConstraint.AvailableSize;
         return(new Size(w, w / 2));
     }
     else if (heightConstraint.IsConstrained)
     {
         var h = forceSize ? Math.Max(size / 2, widthConstraint.AvailableSize) : widthConstraint.AvailableSize;
         return(new Size(h * 2, h));
     }
     return(new Size(size, size / 2));
 }
示例#14
0
        protected override Size OnGetPreferredSize(SizeConstraint widthConstraint, SizeConstraint heightConstraint)
        {
            TablePlacement[] visibleChildren = VisibleChildren();

            if (!widthConstraint.IsConstrained && !heightConstraint.IsConstrained)
            {
                var childrenSizes = GetPreferredChildrenSizes(visibleChildren, false, false);
                var w             = CalcPreferredCellSizes(visibleChildren, childrenSizes, Orientation.Horizontal);
                var h             = CalcPreferredCellSizes(visibleChildren, childrenSizes, Orientation.Vertical);
                return(new Size(w.TotalSize, h.TotalSize));
            }
            else if (!widthConstraint.IsConstrained)
            {
                var childrenSizes = GetPreferredChildrenSizes(visibleChildren, false, false);
                var h             = CalcPreferredCellSizes(visibleChildren, childrenSizes, Orientation.Vertical);
                CalcCellSizes(h, heightConstraint.AvailableSize, false);

                childrenSizes = GetPreferredChildrenSizes(visibleChildren, false, true);
                var w = CalcPreferredCellSizes(visibleChildren, childrenSizes, Orientation.Horizontal);
                return(new Size(w.TotalSize, heightConstraint.AvailableSize));
            }
            else if (!heightConstraint.IsConstrained)
            {
                var childrenSizes = GetPreferredChildrenSizes(visibleChildren, false, false);
                var w             = CalcPreferredCellSizes(visibleChildren, childrenSizes, Orientation.Horizontal);
                CalcCellSizes(w, widthConstraint.AvailableSize, false);

                childrenSizes = GetPreferredChildrenSizes(visibleChildren, true, false);
                var h = CalcPreferredCellSizes(visibleChildren, childrenSizes, Orientation.Vertical);
                return(new Size(widthConstraint.AvailableSize, h.TotalSize));
            }
            else
            {
                var childrenSizes = GetPreferredChildrenSizes(visibleChildren, false, false);
                var width         = CalcPreferredCellSizes(visibleChildren, childrenSizes, Orientation.Horizontal);
                var height        = CalcPreferredCellSizes(visibleChildren, childrenSizes, Orientation.Vertical);

                if (width.TotalSize <= widthConstraint.AvailableSize)
                {
                    return(new Size(width.TotalSize, height.TotalSize));
                }

                CalcCellSizes(width, widthConstraint.AvailableSize, false);
                childrenSizes = GetPreferredChildrenSizes(visibleChildren, true, false);
                height        = CalcPreferredCellSizes(visibleChildren, childrenSizes, Orientation.Vertical);
                return(new Size(widthConstraint.AvailableSize, Math.Min(heightConstraint.AvailableSize, height.TotalSize)));
            }
        }
示例#15
0
        protected override Size OnGetPreferredSize(SizeConstraint widthConstraint, SizeConstraint heightConstraint)
        {
            if (widthConstraint.IsConstrained)
            {
                widthConstraint.AvailableSize -= 2 * padding;
            }
            if (heightConstraint.IsConstrained)
            {
                heightConstraint.AvailableSize -= 2 * padding;
            }

            var s = base.OnGetPreferredSize(widthConstraint, heightConstraint);

            s.Width  += 2 * padding;
            s.Height += 2 * padding;
            return(s);
        }
示例#16
0
文件: Box.cs 项目: wesreid/xwt
        protected override Size OnGetPreferredSize(SizeConstraint widthConstraint, SizeConstraint heightConstraint)
        {
            Size s     = new Size();
            int  count = 0;

            if (direction == Orientation.Horizontal)
            {
                foreach (var cw in Children.Where(b => b.Visible))
                {
                    var wsize = cw.Surface.GetPreferredSize(SizeConstraint.Unconstrained, heightConstraint, true);
                    s.Width += wsize.Width;
                    if (wsize.Height > s.Height)
                    {
                        s.Height = wsize.Height;
                    }
                    count++;
                }
                if (count > 0)
                {
                    s.Width += spacing * (double)(count - 1);
                }
            }
            else
            {
                foreach (var cw in Children.Where(b => b.Visible))
                {
                    var wsize = cw.Surface.GetPreferredSize(widthConstraint, SizeConstraint.Unconstrained, true);
                    s.Height += wsize.Height;
                    if (wsize.Width > s.Width)
                    {
                        s.Width = wsize.Width;
                    }
                    count++;
                }
                if (count > 0)
                {
                    s.Height += spacing * (double)(count - 1);
                }
            }
            return(s);
        }
示例#17
0
 protected override Size OnGetPreferredSize(SizeConstraint widthConstraint, SizeConstraint heightConstraint)
 {
     return renderedImage[(int) SelectedLogLevel].Size;
 }
示例#18
0
文件: BoxBackend.cs 项目: m13253/xwt
		protected Gtk.Requisition OnGetRequisition (SizeConstraint widthConstraint, SizeConstraint heightConstraint)
		{
			var size = Backend.Frontend.Surface.GetPreferredSize (widthConstraint, heightConstraint, true);
			return size.ToGtkRequisition ();
		}
示例#19
0
		protected override Size OnGetPreferredSize (SizeConstraint widthConstraint, SizeConstraint heightConstraint)
		{
			if (parent.CurrentRow == null)
				return new Size (20, 100);
			var row_bg_bounds = parent.TreeView.GetRowBounds (parent.CurrentRow.CurrentPosition, true);
			if (row_bg_bounds == Rectangle.Zero)
				return new Size (20, 100);
			return new Size (row_bg_bounds.Width, row_bg_bounds.Height);
		}
示例#20
0
 Size ICanvasCellViewFrontend.GetRequiredSize(SizeConstraint widthConstraint)
 {
     return(OnGetRequiredSize(widthConstraint));
 }
示例#21
0
		protected override Size OnGetPreferredSize (SizeConstraint widthConstraint, SizeConstraint heightConstraint)
		{
			return new Size (size, size);
		}
示例#22
0
 public void SetSizeConstraints(SizeConstraint widthConstraint, SizeConstraint heightConstraint)
 {
     currentWidthConstraint = widthConstraint;
     currentHeightConstraint = heightConstraint;
 }
示例#23
0
 public void GetConstraints(Gtk.Widget target, out SizeConstraint width, out SizeConstraint height)
 {
     if (Parent is IConstraintProvider)
         ((IConstraintProvider)Parent).GetConstraints (this, out width, out height);
     else
         width = height = SizeConstraint.Unconstrained;
 }
示例#24
0
        internal Size GetPreferredSize(double width, double height)
        {
            var wc = double.IsPositiveInfinity(width) ? SizeConstraint.Unconstrained : SizeConstraint.WithSize(width);
            var hc = double.IsPositiveInfinity(height) ? SizeConstraint.Unconstrained : SizeConstraint.WithSize(height);

            return(Child.Surface.GetPreferredSize(wc, hc));
        }
示例#25
0
文件: Window.cs 项目: inorton/xwt
        internal override void AdjustSize()
        {
            if (child == null)
            {
                return;
            }

            IWidgetSurface s = child.Surface;

            var size = shown ? Size : initialBounds.Size;

            var wc = (shown || widthSet) ? SizeConstraint.WithSize(size.Width - padding.HorizontalSpacing) : SizeConstraint.Unconstrained;
            var hc = (shown || heightSet) ? SizeConstraint.WithSize(size.Height - padding.VerticalSpacing) : SizeConstraint.Unconstrained;

            var ws = s.GetPreferredSize(wc, hc, true);

            if (!shown)
            {
                if (!widthSet)
                {
                    size.Width = ws.Width + padding.HorizontalSpacing;
                }
                if (!heightSet)
                {
                    size.Height = ws.Height + padding.VerticalSpacing;
                }
            }

            if (ws.Width + padding.HorizontalSpacing > size.Width)
            {
                size.Width = ws.Width + padding.HorizontalSpacing;
            }
            if (ws.Height + padding.VerticalSpacing > size.Height)
            {
                size.Height = ws.Height + padding.VerticalSpacing;
            }

            size += Backend.ImplicitMinSize;

            if (!shown)
            {
                shown = true;

                if (size != Size)
                {
                    if (locationSet)
                    {
                        Backend.Bounds = new Rectangle(initialBounds.X, initialBounds.Y, size.Width, size.Height);
                    }
                    else
                    {
                        Backend.SetSize(size.Width, size.Height);
                    }
                }
                else if (locationSet && !shown)
                {
                    Backend.Move(initialBounds.X, initialBounds.Y);
                }

                Backend.SetMinSize(Backend.ImplicitMinSize + new Size(ws.Width + padding.HorizontalSpacing, ws.Height + padding.VerticalSpacing));
            }
            else
            {
                if (size != Size)
                {
                    Backend.SetSize(size.Width, size.Height);
                }
            }
        }
示例#26
0
		// The height of this widget is always half of the width
		protected override Size OnGetPreferredSize (SizeConstraint widthConstraint, SizeConstraint heightConstraint)
		{
			if (widthConstraint.IsConstrained) {
				var w = forceSize ? Math.Max (size, widthConstraint.AvailableSize) : widthConstraint.AvailableSize;
				return new Size (w, w / 2);
			} else if (heightConstraint.IsConstrained) {
				var h = forceSize ? Math.Max (size / 2, widthConstraint.AvailableSize) : widthConstraint.AvailableSize;
				return new Size (h * 2, h);
			}
			return new Size (size, size / 2);
		}
示例#27
0
 public virtual Size GetPreferredSize(SizeConstraint widthConstraint, SizeConstraint heightConstraint)
 {
     try {
         SetSizeConstraints (widthConstraint, heightConstraint);
         gettingPreferredSize = true;
         var sr = Widget.SizeRequest ();
         return new Size (sr.Width, sr.Height);
     } finally {
         gettingPreferredSize = false;
     }
 }
示例#28
0
文件: TabButton.cs 项目: jfreax/BAIMP
        protected override Size OnGetPreferredSize(SizeConstraint widthConstraint, SizeConstraint heightConstraint)
        {
            Size size = text.GetSize();
            size.Width += padding.HorizontalSpacing + Lean.Dx + 2;
            if (next == null) {
                size.Width += Lean.Dx + 2;
            }

            if (Closeable) {
                size.Width += closeNormal.Width;
            }

            size.Height += padding.VerticalSpacing;
            return size;
        }
示例#29
0
 protected override Size OnGetPreferredSize(SizeConstraint widthConstraint, SizeConstraint heightConstraint)
 {
     return bg[0].Size;
 }
 protected override Size OnGetPreferredSize(SizeConstraint widthConstraint, SizeConstraint heightConstraint)
 {
     return(base.OnGetPreferredSize(widthConstraint, heightConstraint));
 }
示例#31
0
		protected override Size OnGetPreferredSize (SizeConstraint widthConstraint, SizeConstraint heightConstraint)
		{
			var row_bg_bounds = parent.ListView.GetRowBounds (parent.CurrentRow, true);
			return new Size (row_bg_bounds.Width, row_bg_bounds.Height);
		}
示例#32
0
 protected override Size OnGetPreferredSize(SizeConstraint widthConstraint, SizeConstraint heightConstraint)
 {
     return(new Size(size, size));
 }
示例#33
0
        internal override void AdjustSize()
        {
            Size mMinSize, mDecorationsSize;

            Backend.GetMetrics(out mMinSize, out mDecorationsSize);

            var size = shown ? Size : initialBounds.Size;

            var wc = (shown || widthSet) ? SizeConstraint.WithSize(Math.Max(size.Width - padding.HorizontalSpacing - mDecorationsSize.Width, mMinSize.Width)) : SizeConstraint.Unconstrained;
            var hc = (shown || heightSet) ? SizeConstraint.WithSize(Math.Max(size.Height - padding.VerticalSpacing - mDecorationsSize.Height, mMinSize.Height)) : SizeConstraint.Unconstrained;

            var ws = mDecorationsSize;

            if (child != null)
            {
                IWidgetSurface s = child.Surface;
                ws += s.GetPreferredSize(wc, hc, true);
            }
            ws.Width  += padding.HorizontalSpacing;
            ws.Height += padding.VerticalSpacing;

            if (!shown)
            {
                if (!widthSet)
                {
                    size.Width = ws.Width;
                }
                if (!heightSet)
                {
                    size.Height = ws.Height;
                }
            }

            if (ws.Width < mMinSize.Width)
            {
                ws.Width = mMinSize.Width;
            }
            if (ws.Height < mMinSize.Height)
            {
                ws.Height = mMinSize.Height;
            }

            if (ws.Width > size.Width)
            {
                size.Width = ws.Width;
            }
            if (ws.Height > size.Height)
            {
                size.Height = ws.Height;
            }

            if (!shown)
            {
                shown = true;

                if (!locationSet && initialLocation != WindowLocation.Manual)
                {
                    Point center;
                    if (initialLocation == WindowLocation.CenterScreen || TransientFor == null)
                    {
                        center = Desktop.PrimaryScreen.VisibleBounds.Center;
                    }
                    else
                    {
                        center = TransientFor.ScreenBounds.Center;
                    }
                    initialBounds.X = Math.Round(center.X - size.Width / 2);
                    initialBounds.Y = Math.Round(center.Y - size.Height / 2);
                    locationSet     = true;
                }

                if (size != Size)
                {
                    if (locationSet)
                    {
                        Backend.Bounds = new Rectangle(initialBounds.X, initialBounds.Y, size.Width, size.Height);
                    }
                    else
                    {
                        Backend.SetSize(size.Width, size.Height);
                    }
                }
                else if (locationSet && !shown)
                {
                    Backend.Move(initialBounds.X, initialBounds.Y);
                }
            }
            else
            {
                if (size != Size)
                {
                    Backend.SetSize(size.Width, size.Height);
                }
            }
            Backend.SetMinSize(new Size(ws.Width, ws.Height));
        }
示例#34
0
        protected override Size OnGetPreferredSize(SizeConstraint widthConstraint, SizeConstraint heightConstraint)
        {
            if (widthConstraint.IsConstrained)
                widthConstraint.AvailableSize -= 2 * padding;
            if (heightConstraint.IsConstrained)
                heightConstraint.AvailableSize -= 2 * padding;

            var s = base.OnGetPreferredSize (widthConstraint, heightConstraint);
            s.Width += 2 * padding;
            s.Height += 2 * padding;
            return s;
        }