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.