From 68ab959c556125b4841961e77a7e6082a3414a14 Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Fri, 20 Oct 2006 14:54:14 +0000 Subject: [PATCH] fixed computation of status bar fields width if the total width is not divisible by the number of fields git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42171 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/statbar.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/common/statbar.cpp b/src/common/statbar.cpp index e1c4fd3dff..3e91d47ec6 100644 --- a/src/common/statbar.cpp +++ b/src/common/statbar.cpp @@ -222,12 +222,21 @@ wxArrayInt wxStatusBarBase::CalculateAbsWidths(wxCoord widthTotal) const { if ( m_nFields ) { - // default: all fields have the same width - int nWidth = widthTotal / m_nFields; - for ( int i = 0; i < m_nFields; i++ ) + // Default: all fields have the same width. This is not always + // possible to do exactly (if widthTotal is not divisible by + // m_nFields) - if that happens, we distribute the extra pixels + // among all fields: + int widthToUse = widthTotal; + + for ( int i = m_nFields; i > 0; i-- ) { - widths.Add(nWidth); + // divide the unassigned width evently between the + // not yet processed fields: + int w = widthToUse / i; + widths.Add(w); + widthToUse -= w; } + } //else: we're empty anyhow } -- 2.47.2