Use a constant for the wxGrid text margin

Use a constant instead of a hardcoded value for the text margin.
This commit is contained in:
Ilya Sinitsyn
2020-02-04 00:08:09 +07:00
parent 72824bc269
commit 45839843e6

View File

@@ -114,6 +114,9 @@ const int DRAG_SENSITIVITY = 3;
// the space between the cell edge and the checkbox mark // the space between the cell edge and the checkbox mark
const int GRID_CELL_CHECKBOX_MARGIN = 2; const int GRID_CELL_CHECKBOX_MARGIN = 2;
// the margin between a cell vertical line and a cell text
const int GRID_TEXT_MARGIN = 1;
} // anonymous namespace } // anonymous namespace
#include "wx/arrimpl.cpp" #include "wx/arrimpl.cpp"
@@ -6747,9 +6750,9 @@ void wxGrid::DrawTextRectangle(wxDC& dc,
{ {
case wxALIGN_BOTTOM: case wxALIGN_BOTTOM:
if ( textOrientation == wxHORIZONTAL ) if ( textOrientation == wxHORIZONTAL )
y = rect.y + (rect.height - textHeight - 1); y = rect.y + (rect.height - textHeight - GRID_TEXT_MARGIN);
else else
x = rect.x + rect.width - textWidth; x = rect.x + (rect.width - textWidth - GRID_TEXT_MARGIN);
break; break;
case wxALIGN_CENTRE: case wxALIGN_CENTRE:
@@ -6762,9 +6765,9 @@ void wxGrid::DrawTextRectangle(wxDC& dc,
case wxALIGN_TOP: case wxALIGN_TOP:
default: default:
if ( textOrientation == wxHORIZONTAL ) if ( textOrientation == wxHORIZONTAL )
y = rect.y + 1; y = rect.y + GRID_TEXT_MARGIN;
else else
x = rect.x + 1; x = rect.x + GRID_TEXT_MARGIN;
break; break;
} }
@@ -6788,9 +6791,9 @@ void wxGrid::DrawTextRectangle(wxDC& dc,
{ {
case wxALIGN_RIGHT: case wxALIGN_RIGHT:
if ( textOrientation == wxHORIZONTAL ) if ( textOrientation == wxHORIZONTAL )
x = rect.x + (rect.width - lineWidth - 1); x = rect.x + (rect.width - lineWidth - GRID_TEXT_MARGIN);
else else
y = rect.y + lineWidth + 1; y = rect.y + lineWidth + GRID_TEXT_MARGIN;
break; break;
case wxALIGN_CENTRE: case wxALIGN_CENTRE:
@@ -6803,9 +6806,9 @@ void wxGrid::DrawTextRectangle(wxDC& dc,
case wxALIGN_LEFT: case wxALIGN_LEFT:
default: default:
if ( textOrientation == wxHORIZONTAL ) if ( textOrientation == wxHORIZONTAL )
x = rect.x + 1; x = rect.x + GRID_TEXT_MARGIN;
else else
y = rect.y + rect.height - 1; y = rect.y + rect.height - GRID_TEXT_MARGIN;
break; break;
} }
@@ -6831,16 +6834,13 @@ void wxGrid::DrawTextRectangle(wxDC& dc,
{ {
attr.GetNonDefaultAlignment(&hAlign, &vAlign); attr.GetNonDefaultAlignment(&hAlign, &vAlign);
// The text will be displaced in final wxGrid::DrawTextRectangle function.
const int textMargin = 2;
// This does nothing if there is no need to ellipsize. // This does nothing if there is no need to ellipsize.
const wxString& ellipsizedText = wxControl::Ellipsize const wxString& ellipsizedText = wxControl::Ellipsize
( (
text, text,
dc, dc,
attr.GetFitMode().GetEllipsizeMode(), attr.GetFitMode().GetEllipsizeMode(),
rect.GetWidth() - textMargin, rect.GetWidth() - 2 * GRID_TEXT_MARGIN,
wxELLIPSIZE_FLAGS_NONE wxELLIPSIZE_FLAGS_NONE
); );