From edd0d9b68fea39e7141594697651290771daad9a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 28 Nov 2019 23:57:15 +0100 Subject: [PATCH] Ensure DrawCheckBox() fits inside the rectangle passed to it This results in rather ugly checkboxes when the rectangle is too small, and even "critical" GTK warnings with wxGTK 3, but is still arguably better than drawing outside of the provided rectangle. --- src/gtk/renderer.cpp | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/gtk/renderer.cpp b/src/gtk/renderer.cpp index c2d01e4a39..c26901817c 100644 --- a/src/gtk/renderer.cpp +++ b/src/gtk/renderer.cpp @@ -633,6 +633,35 @@ struct CheckBoxInfo } #endif // __WXGTK3__/!__WXGTK3__ + // Make sure we fit into the provided rectangle, eliminating margins and + // even reducing the size if necessary. + void FitInto(const wxRect& rect) + { + if ( indicator_width > rect.width ) + { + indicator_width = rect.width; + margin_left = + margin_right = 0; + } + else if ( indicator_width + margin_left + margin_right > rect.width ) + { + margin_left = + margin_right = (rect.width - indicator_width) / 2; + } + + if ( indicator_height > rect.height ) + { + indicator_height = rect.height; + margin_top = + margin_bottom = 0; + } + else if ( indicator_height + margin_top + margin_bottom > rect.height ) + { + margin_top = + margin_bottom = (rect.height - indicator_height) / 2; + } + } + gint indicator_width, indicator_height; gint margin_left, @@ -695,7 +724,8 @@ wxRendererGTK::DrawCheckBox(wxWindow*, wxGtkStyleContext sc(dc.GetContentScaleFactor()); - const CheckBoxInfo info(sc, flags); + CheckBoxInfo info(sc, flags); + info.FitInto(rect); const int w = info.indicator_width + info.margin_left + info.margin_right; const int h = info.indicator_height + info.margin_top + info.margin_bottom; @@ -728,7 +758,8 @@ wxRendererGTK::DrawCheckBox(wxWindow*, #else // !__WXGTK3__ GtkWidget* button = wxGTKPrivate::GetCheckButtonWidget(); - const CheckBoxInfo info(button, flags); + CheckBoxInfo info(button, flags); + info.FitInto(rect); GtkStateType state;