From 9ef1b1529d68ffbdeee01eb91d77ef1b6ada0f27 Mon Sep 17 00:00:00 2001 From: Ilya Sinitsyn Date: Mon, 7 Oct 2019 17:54:27 +0700 Subject: [PATCH] Add wxControl::GetSizeFromText() helper function Add the helper function that combines GetSizeFromTextSize() and GetTextExtent() as they are often used together. --- include/wx/control.h | 5 +++++ interface/wx/control.h | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/include/wx/control.h b/include/wx/control.h index 0e646b2faa..3500aa5253 100644 --- a/include/wx/control.h +++ b/include/wx/control.h @@ -115,6 +115,11 @@ public: wxSize GetSizeFromTextSize(const wxSize& tsize) const { return DoGetSizeFromTextSize(tsize.x, tsize.y); } + wxSize GetSizeFromText(const wxString& text) const + { + return GetSizeFromTextSize(GetTextExtent(text).GetWidth()); + } + // static utilities for mnemonics char (&) handling // ------------------------------------------------ diff --git a/interface/wx/control.h b/interface/wx/control.h index 04670c9e04..0441883ef9 100644 --- a/interface/wx/control.h +++ b/interface/wx/control.h @@ -140,6 +140,27 @@ public: */ wxSize GetSizeFromTextSize(const wxSize& tsize) const; + /** + Determine the minimum size needed by the control to display the given text. + + The helper function that uses combination of GetSizeFromTextSize() and + GetTextExtent() which used together pretty often: + @code + wxSize GetSizeFromText(const wxString& text) const + { + return GetSizeFromTextSize(GetTextExtent(text).GetWidth()); + } + @endcode + + @param text The given text. + @return The size that the control should have to leave the area of the + specified text. May return wxDefaultSize if this method is not + implemented for this particular control under the current platform. + + @since 3.1.3 + */ + wxSize GetSizeFromText(const wxString& text) const; + /** Sets the control's label.