From 4e01ababc65d3af4792cbdd6985ed0d7958db974 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Wed, 17 Apr 2013 11:26:30 +0200 Subject: [PATCH] Dialog: Fix centering in owner when calling Show. --- dialog.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/dialog.go b/dialog.go index 5947df63..bcadd13b 100644 --- a/dialog.go +++ b/dialog.go @@ -190,14 +190,24 @@ func (dlg *Dialog) focusFirstCandidateDescendant() { func (dlg *Dialog) Show() { if dlg.owner != nil { + var size Size + if layout := dlg.Layout(); layout != nil { + size = layout.MinSize() + min := dlg.MinSize() + size.Width = maxi(size.Width, min.Width) + size.Height = maxi(size.Height, min.Height) + } else { + size = dlg.Size() + } + ob := dlg.owner.Bounds() - b := dlg.Bounds() + if dlg.centerInOwnerWhenRun { dlg.SetBounds(Rectangle{ - ob.X + (ob.Width-b.Width)/2, - ob.Y + (ob.Height-b.Height)/2, - b.Width, - b.Height, + ob.X + (ob.Width-size.Width)/2, + ob.Y + (ob.Height-size.Height)/2, + size.Width, + size.Height, }) } } else {