From 0e16d866ed0897b805dac0855e40c83e9ec6f24e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 2 Feb 2023 17:11:33 +0100 Subject: [PATCH] Fix vertical size and position of wxTreeTextCtrl Use vertical component of the size returned from GetSizeFromTextSize() too, not only the horizontal one, to ensure we make the control tall enough to fit its contents. --- src/generic/treectlg.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/generic/treectlg.cpp b/src/generic/treectlg.cpp index a329290b68..c34ccd037d 100644 --- a/src/generic/treectlg.cpp +++ b/src/generic/treectlg.cpp @@ -428,6 +428,11 @@ wxTreeTextCtrl::wxTreeTextCtrl(wxGenericTreeCtrl *owner, m_owner = owner; m_aboutToFinish = false; + // Create the text hidden to show it with the correct size -- which we + // can't determine before creating it. + Hide(); + Create(m_owner, wxID_ANY, m_startValue); + wxRect rect; m_owner->GetBoundingRect(m_itemEdited, rect, true); @@ -438,10 +443,20 @@ wxTreeTextCtrl::wxTreeTextCtrl(wxGenericTreeCtrl *owner, rect.x -= 5; #endif // platforms - (void)Create(m_owner, wxID_ANY, m_startValue, - rect.GetPosition(), rect.GetSize()); + const wxSize textSize = rect.GetSize(); + wxSize fullSize = GetSizeFromTextSize(textSize); + if ( fullSize.y > textSize.y ) + { + // It's ok to extend the rect to the right horizontally, which happens + // when we just change its size without changing its position below, + // but when extending it vertically, we need to keep it centered. + rect.y -= (fullSize.y - textSize.y + 1) / 2; + } - IncreaseSizeForText(m_startValue); + rect.SetSize(fullSize); + + SetSize(rect); + Show(); SelectAll(); }