New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Notebook sample gets bigger every DPI change #23404
Comments
Thanks for reporting this, but unfortunately I don't think overriding Of course, this leaves the question of what do we need to do to actually fix the problem... I think that the root reason of it is that we want to be smart about determining the initial size of the control if it's not explicitly specified, and, in particular, make it bigger than the strict minimum size if it has some contents, but we do not want to do this when determining its minimum size later one. But the trouble is that the same So the logical thing to do here seems to return the latter size from But "mostly" doesn't mean "perfectly", of course. E.g. overriding So, if we want to be on the safe side, and if my initial diagnosis of the root of the problem is correct, we're probably going to have to add yet another virtual size-related function. I think if we add something like But this is going to make explaining how sizing works in wx even more complicated... So maybe the best solution is the simplest one and we should just hardcode some number (5?) of lines in |
I hope I understand all correctly. Is this what you propose before-last? include/wx/msw/textctrl.h | 1 +
include/wx/window.h | 2 ++
src/common/wincmn.cpp | 7 ++++++-
src/msw/textctrl.cpp | 7 ++++++-
4 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/include/wx/msw/textctrl.h b/include/wx/msw/textctrl.h
index ffc322a8ca..a98d785ffd 100644
--- a/include/wx/msw/textctrl.h
+++ b/include/wx/msw/textctrl.h
@@ -235,6 +235,7 @@ protected:
// send TEXT_UPDATED event, return true if it was handled, false otherwise
bool SendUpdateEvent();
+ virtual wxSize GetIdealSize() const override;
virtual wxSize DoGetBestSize() const override;
virtual wxSize DoGetSizeFromTextSize(int xlen, int ylen = -1) const override;
diff --git a/include/wx/window.h b/include/wx/window.h
index 598d547a3f..ef081b0788 100644
--- a/include/wx/window.h
+++ b/include/wx/window.h
@@ -409,6 +409,8 @@ public:
// returns the results.
virtual wxSize GetEffectiveMinSize() const;
+ virtual wxSize GetIdealSize() const;
+
// A 'Smart' SetSize that will fill in default size values with 'best'
// size. Sets the minsize to what was passed in.
void SetInitialSize(const wxSize& size=wxDefaultSize);
diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp
index 7cf091356a..681f65e420 100644
--- a/src/common/wincmn.cpp
+++ b/src/common/wincmn.cpp
@@ -890,7 +890,7 @@ wxSize wxWindowBase::GetEffectiveMinSize() const
if (min.x == wxDefaultCoord || min.y == wxDefaultCoord)
{
- wxSize best = GetBestSize();
+ wxSize best = GetIdealSize();
if (min.x == wxDefaultCoord) min.x = best.x;
if (min.y == wxDefaultCoord) min.y = best.y;
}
@@ -898,6 +898,11 @@ wxSize wxWindowBase::GetEffectiveMinSize() const
return min;
}
+wxSize wxWindowBase::GetIdealSize() const
+{
+ return GetBestSize();
+}
+
wxSize wxWindowBase::GetBestSize() const
{
if ( !m_windowSizer && m_bestSizeCache.IsFullySpecified() )
diff --git a/src/msw/textctrl.cpp b/src/msw/textctrl.cpp
index 6f15bb6284..bdeea06233 100644
--- a/src/msw/textctrl.cpp
+++ b/src/msw/textctrl.cpp
@@ -2501,11 +2501,16 @@ bool wxTextCtrl::AcceptsFocusFromKeyboard() const
return (IsEditable() || IsMultiLine()) && wxControl::AcceptsFocus();
}
-wxSize wxTextCtrl::DoGetBestSize() const
+wxSize wxTextCtrl::GetIdealSize() const
{
return DoGetSizeFromTextSize( FromDIP(DEFAULT_ITEM_WIDTH) );
}
+wxSize wxTextCtrl::DoGetBestSize() const
+{
+ return GetMinSize();
+}
+
wxSize wxTextCtrl::DoGetSizeFromTextSize(int xlen, int ylen) const
{
int cy; |
Thanks for looking into this!
Sorry, no, I don't think this is right: if With this proposal the idea was for
With that proposal the idea was to stop using the number of lines in the existing |
To Reproduce:
Description
This is caused because the minimum size of the multiline
wxTextCtrl
used for the log is based on the number of lines it contains.And the log vs the notebook uses a proportion of 1-to-5, so if the
wxTextCtrl
gets a bit bigger, the notebook grows a a lot more.It has the following call stack:
wxNonOwnedWindow::HandleDPIChange()
->wxSizer::GetMinSize()
->wxSizerItem::CalcMin()
->wxWindowBase::GetEffectiveMinSize()
->wxTextCtrl::DoGetBestSize()
->wxTextCtrl::DoGetSizeFromTextSize()
A possible fix I found is overriding
GetEffectiveMinSize()
inwxTextCtrl
, but I have no idea what other consequences this might have:Platform and version information
The text was updated successfully, but these errors were encountered: