protected override void OnSizeAllocated(Gdk.Rectangle allocation) { //shrink the allocation we pass to the base layout, to allow for our extra border if (showBorderLine) { allocation.X += 1; allocation.Y += 1; allocation.Height -= HScrollbar.Visible? 1 : 2; allocation.Width -= VScrollbar.Visible? 1 : 2; } base.OnSizeAllocated(allocation); //expand the scrollbars so they render over the new border if (showBorderLine) { bool hasHScroll = HScrollbar.Visible; bool hasVScroll = VScrollbar.Visible; if (hasHScroll) { var alloc = HScrollbar.Allocation; alloc.X -= 1; alloc.Width += hasVScroll? 1 :2; HScrollbar.SizeAllocate(alloc); } if (hasVScroll) { var alloc = VScrollbar.Allocation; alloc.Y -= 1; alloc.Height += hasHScroll? 1 : 2; VScrollbar.SizeAllocate(alloc); } } }
protected override void OnSizeAllocated(Rectangle allocation) { base.OnSizeAllocated(allocation); int margin = BorderVisible ? 1 : 0; int vwidth = vScrollBar.Visible ? vScrollBar.Requisition.Width : 0; int hheight = hScrollBar.Visible ? hScrollBar.Requisition.Height : 0; var childRectangle = new Rectangle(allocation.X + margin, allocation.Y + margin, allocation.Width - vwidth - margin * 2, allocation.Height - hheight - margin * 2); if (Child != null) { Child.SizeAllocate(childRectangle); } if (vScrollBar.Visible) { int vChildTopHeight = -1; foreach (var child in children.Where(child => child.ChildPosition == ChildPosition.Top)) { child.Child.SizeAllocate(new Rectangle(childRectangle.RightInside(), childRectangle.Y + vChildTopHeight, allocation.Width - vwidth, child.Child.Requisition.Height)); vChildTopHeight += child.Child.Requisition.Height; } int v = vScrollBar is Scrollbar && hScrollBar.Visible ? hScrollBar.Requisition.Height : 0; vScrollBar.SizeAllocate(new Rectangle(childRectangle.X + childRectangle.Width + margin, childRectangle.Y + vChildTopHeight, vwidth, Allocation.Height - v - vChildTopHeight - margin)); vAdjustment.Value = System.Math.Max(System.Math.Min(vAdjustment.Upper - vAdjustment.PageSize, vAdjustment.Value), vAdjustment.Lower); } if (hScrollBar.Visible) { int v = vScrollBar.Visible ? vScrollBar.Requisition.Width : 0; hScrollBar.SizeAllocate(new Rectangle(allocation.X, childRectangle.Y + childRectangle.Height + margin, allocation.Width - v, hheight)); hScrollBar.Value = System.Math.Max(System.Math.Min(hAdjustment.Upper - hAdjustment.PageSize, hScrollBar.Value), hAdjustment.Lower); } }