From aa2d159e8cc0d2f729528b018fd1653fa409a6ad Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 4 Aug 2020 01:02:01 +0200 Subject: [PATCH] Use more reasonable length for wxSlider in wxGTK by default Use the same 100 DIPs as in wxMSW, to make the default behaviour more useful. Also update documentation to explain which size component should, and should not, be specified when creating the slider. Closes https://github.com/wxWidgets/wxWidgets/pull/2012 --- include/wx/gtk/slider.h | 2 ++ interface/wx/slider.h | 10 +++++++++- src/gtk/slider.cpp | 10 ++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/include/wx/gtk/slider.h b/include/wx/gtk/slider.h index 0a34fcf729..b59afd3c8b 100644 --- a/include/wx/gtk/slider.h +++ b/include/wx/gtk/slider.h @@ -74,6 +74,8 @@ public: GtkWidget *m_scale; protected: + virtual wxSize DoGetBestSize() const wxOVERRIDE; + GtkWidget *m_minLabel,*m_maxLabel; bool m_blockScrollEvent; diff --git a/interface/wx/slider.h b/interface/wx/slider.h index 9a4aa3df58..04cdb9a9ce 100644 --- a/interface/wx/slider.h +++ b/interface/wx/slider.h @@ -175,7 +175,15 @@ public: If ::wxDefaultPosition is specified then a default position is chosen. @param size Window size. - If ::wxDefaultSize is specified then a default size is chosen. + If ::wxDefaultSize is specified then a default size is chosen, + which is typically appropriate in the transverse slider direction, + but is just fixed 100 (DPI-independent) pixels in the primary + direction (i.e. vertical for ::wxSL_VERTICAL sliders or horizontal + for ::wxSL_HORIZONTAL ones), so it may be preferable to specify it + explicitly. Conversely, when using non-default size, it's usually + best to use @c -1 for the transverse size component, meaning that + the default should be used, as the appropriate value depends on the + platform and theme. @param style Window style. See wxSlider. @param validator diff --git a/src/gtk/slider.cpp b/src/gtk/slider.cpp index 3b59de161c..9d63d7a0e4 100644 --- a/src/gtk/slider.cpp +++ b/src/gtk/slider.cpp @@ -571,6 +571,16 @@ int wxSlider::GetTickFreq() const #endif } +wxSize wxSlider::DoGetBestSize() const +{ + // We need to get the size in the transverse direction from GTK, but we use + // hard-coded default in the other direction, as otherwise the slider would + // have the smallest possible size and not have any extent at all. + wxSize size = GTKGetPreferredSize(m_widget); + (HasFlag(wxSL_VERTICAL) ? size.y : size.x) = 100; + return size; +} + GdkWindow *wxSlider::GTKGetWindow(wxArrayGdkWindows& WXUNUSED(windows)) const { #ifdef __WXGTK3__