void UpdateChildSize() { if (child == null) { return; } if (Widget.ContentView is CustomClipView) { } else { NSView view = (NSView)Widget.DocumentView; ViewBackend c = (ViewBackend)child; Size s; if (horizontalScrollPolicy == ScrollPolicy.Never) { s = c.Frontend.Surface.GetPreferredSize(SizeConstraint.WithSize(Widget.ContentView.Frame.Width), SizeConstraint.Unconstrained); } else if (verticalScrollPolicy == ScrollPolicy.Never) { s = c.Frontend.Surface.GetPreferredSize(SizeConstraint.Unconstrained, SizeConstraint.WithSize(Widget.ContentView.Frame.Width)); } else { s = c.Frontend.Surface.GetPreferredSize(); } var w = Math.Max(s.Width, Widget.ContentView.Frame.Width); var h = Math.Max(s.Height, Widget.ContentView.Frame.Height); view.Frame = new System.Drawing.RectangleF(view.Frame.X, view.Frame.Y, (float)s.Width, (float)h); } }
void Reallocate() { var contentWidth = (Controller.DefaultPageSize.Width > 0 ? Controller.DefaultPageSize.Width : 660); var pageRequest = currentPageWidget.Surface.GetPreferredSize(true); contentWidth = Math.Max(contentWidth, pageRequest.Width); pageRequest = currentPageWidget.Surface.GetPreferredSize(SizeConstraint.WithSize(contentWidth), SizeConstraint.Unconstrained, true); var contentHeight = pageRequest.Height; var rightSideWidget = currentPage.GetRightSideWidget() ?? Controller.RightSideWidget; if (rightSideWidget != null) { var widget = (Xwt.Widget)rightSideWidget; if (rightSideFrame.Content != widget) { rightSideFrame.Content = widget; rightSideFrame.Content.VerticalPlacement = rightSideFrame.Content.HorizontalPlacement = WidgetPlacement.Fill; rightSideFrame.Visible = true; } Dialog.Width = contentWidth + RightSideWidgetWidth; } else { rightSideFrame.Visible = false; Dialog.Width = contentWidth; } Dialog.Height = Math.Max(contentHeight, Controller.DefaultPageSize.Height) + buttonBox.Size.Height; }
List <CellPos> GetCells(CGSize cellSize) { int nexpands = 0; double requiredSize = 0; double availableSize = cellSize.Width; var cellFrames = new List <CellPos> (cells.Count); // Get the natural size of each child foreach (var cell in cells) { if (!cell.Backend.Frontend.Visible) { continue; } var cellPos = new CellPos { Cell = (NSView)cell, Frame = CGRect.Empty }; cellFrames.Add(cellPos); var size = cellPos.Cell.FittingSize; cellPos.Frame.Width = size.Width; requiredSize += size.Width; if (cell.Backend.Frontend.Expands) { nexpands++; } } double remaining = availableSize - requiredSize; if (remaining > 0) { var expandRemaining = new SizeSplitter(remaining, nexpands); foreach (var cellFrame in cellFrames) { if (((ICellRenderer)cellFrame.Cell).Backend.Frontend.Expands) { cellFrame.Frame.Width += (nfloat)expandRemaining.NextSizePart(); } } } double x = 0; foreach (var cellFrame in cellFrames) { var width = cellFrame.Frame.Width; var canvas = cellFrame.Cell as ICanvasCellRenderer; var height = (canvas != null) ? canvas.GetRequiredSize(SizeConstraint.WithSize(width)).Height : cellFrame.Cell.FittingSize.Height; // y-align only if the cell has a valid height, otherwise we're just recalculating the required size var y = cellSize.Height > 0 ? (cellSize.Height - height) / 2 : 0; cellFrame.Frame = new CGRect(x, y, width, height); x += width; } return(cellFrames); }
protected override void OnGetSize(Gtk.Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height) { Size size = new Size(); var widthConstraint = cell_area.Width > 0 ? SizeConstraint.WithSize(cell_area.Width) : SizeConstraint.Unconstrained; CellView.ApplicationContext.InvokeUserCode(delegate { size = CellView.GetRequiredSize(widthConstraint); }); width = (int)size.Width; height = (int)size.Height; x_offset = y_offset = 0; }
protected override void OnGetPreferredWidthForHeight(int height, out int minimum_width, out int natural_width) { var size = OnGetRequisition(SizeConstraint.Unconstrained, SizeConstraint.WithSize(height)); if (size.Height < WidthRequest) { minimum_width = natural_width = WidthRequest; } else { minimum_width = natural_width = size.Width; } }
protected override void OnGetPreferredHeightForWidth(int width, out int minimum_height, out int natural_height) { var size = OnGetRequisition(SizeConstraint.WithSize(width), SizeConstraint.Unconstrained); if (size.Height < HeightRequest) { minimum_height = natural_height = HeightRequest; } else { minimum_height = natural_height = size.Height; } }
protected override void OnGetPreferredWidth(out int minimum_width, out int natural_width) { // containers need initial height in width_for_height mode // dirty fix: do not constrain height on first allocation var force_height = SizeConstraint.Unconstrained; if (IsReallocating) { force_height = SizeConstraint.WithSize(Allocation.Width); } var size = OnGetRequisition(SizeConstraint.Unconstrained, force_height); if (size.Height < WidthRequest) { minimum_width = natural_width = WidthRequest; } else { minimum_width = natural_width = size.Width; } }
protected override void OnGetPreferredHeight(out int minimum_height, out int natural_height) { // containers need initial width in heigt_for_width mode // dirty fix: do not constrain width on first allocation var force_width = SizeConstraint.Unconstrained; if (IsReallocating) { force_width = SizeConstraint.WithSize(Allocation.Width); } var size = OnGetRequisition(force_width, SizeConstraint.Unconstrained); if (size.Height < HeightRequest) { minimum_height = natural_height = HeightRequest; } else { minimum_height = natural_height = size.Height; } }
void UpdateChildSize() { if (child == null) { return; } var widthConstraint = SizeConstraint.Unconstrained; var heightConstraint = SizeConstraint.Unconstrained; if (horizontalScrollPolicy == ScrollPolicy.Never) { widthConstraint = SizeConstraint.WithSize(Widget.ContentView.Frame.Width); } if (verticalScrollPolicy == ScrollPolicy.Never) { heightConstraint = SizeConstraint.WithSize(Widget.ContentView.Frame.Height); } var size = ((ViewBackend)child).Frontend.Surface.GetPreferredSize(widthConstraint, heightConstraint, true); size.Width = Math.Max(size.Width, Widget.ContentView.Frame.Width); size.Height = Math.Max(size.Height, Widget.ContentView.Frame.Height); ((NSView)(Widget.DocumentView)).SetFrameSize(size.ToCGSize()); }
public Size OnGetPreferredSize(SizeConstraint widthConstraint, SizeConstraint heightConstraint) { Size s = new Size(); int count = 0; double[] nextsize = null; double spacing = this.owner.Spacing; // 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) { nextsize = CalcDefaultSizes(widthConstraint, heightConstraint, false); // Calculates the width assigned to each child } for (var nit = 0; nit < this.owner.Placements.Count; nit++) { // Use the calculated width if available var wsize = this.owner.Placements[nit].Child.GetBackend().GetPreferredSize(widthConstraint.IsConstrained ? SizeConstraint.WithSize(nextsize[nit]) : SizeConstraint.Unconstrained, heightConstraint); s.Width += wsize.Width; if (wsize.Height > s.Height) { s.Height = wsize.Height; } count++; } if (count > 0) { s.Width += spacing * (double)(count - 1); } return(s); }