Improve grid editors placing
Remove the code in wxGrid::ShowCellEditControl() which moves grid editors unnecessarily and also remove workarounds that were required because of it in the editors SetSize() functions. This helps to ensure that the editor is placed at the same position the renderer draws the cell value, so that it doesn't jump around annoyingly when editing starts (which was especially noticeable for boolean-valued cells).
This commit is contained in:
committed by
Vadim Zeitlin
parent
6a21d6f2e4
commit
3ca9491c5f
@@ -111,6 +111,9 @@ const int GRID_HASH_SIZE = 100;
|
||||
// operation
|
||||
const int DRAG_SENSITIVITY = 3;
|
||||
|
||||
// the space between the cell edge and the checkbox mark
|
||||
const int GRID_CELL_CHECKBOX_MARGIN_X = 2;
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
#include "wx/arrimpl.cpp"
|
||||
@@ -6980,18 +6983,10 @@ void wxGrid::ShowCellEditControl()
|
||||
if (rect.x < 0)
|
||||
nXMove = rect.x;
|
||||
|
||||
#ifndef __WXQT__
|
||||
// cell is shifted by one pixel
|
||||
// However, don't allow x or y to become negative
|
||||
// since the SetSize() method interprets that as
|
||||
// "don't change."
|
||||
if (rect.x > 0)
|
||||
rect.x--;
|
||||
if (rect.y > 0)
|
||||
rect.y--;
|
||||
#else
|
||||
#ifdef __WXQT__
|
||||
// Substract 1 pixel in every dimension to fit in the cell area.
|
||||
// If not, Qt will draw the control outside the cell.
|
||||
// TODO: Check offsets under Qt.
|
||||
rect.Deflate(1, 1);
|
||||
#endif
|
||||
|
||||
@@ -10337,4 +10332,44 @@ wxGridCellEditor* wxGridTypeRegistry::GetEditor(int index)
|
||||
return editor;
|
||||
}
|
||||
|
||||
wxRect wxGetGridCheckBoxRect(const wxSize& checkBoxSize,
|
||||
const wxRect& cellRect,
|
||||
int hAlign, int WXUNUSED(vAlign))
|
||||
{
|
||||
// TODO: support vAlign
|
||||
|
||||
wxRect checkBoxRect;
|
||||
checkBoxRect.SetY(cellRect.y + cellRect.height / 2 - checkBoxSize.y / 2);
|
||||
|
||||
wxCoord minSize = wxMin(cellRect.width, cellRect.height);
|
||||
if ( checkBoxRect.GetWidth() >= minSize || checkBoxRect.GetHeight() >= minSize )
|
||||
{
|
||||
// let the checkbox mark be even smaller than the min size
|
||||
// to leave some space between cell edges and the checkbox
|
||||
const int newSize = wxMax(1, minSize - 2);
|
||||
checkBoxRect.SetWidth(newSize);
|
||||
checkBoxRect.SetHeight(newSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
checkBoxRect.SetSize(checkBoxSize);
|
||||
}
|
||||
|
||||
if ( hAlign & wxALIGN_CENTER_HORIZONTAL )
|
||||
{
|
||||
checkBoxRect.SetX(cellRect.x + cellRect.width / 2 - checkBoxSize.x / 2);
|
||||
}
|
||||
else if ( hAlign & wxALIGN_RIGHT )
|
||||
{
|
||||
checkBoxRect.SetX(cellRect.x + cellRect.width
|
||||
- checkBoxSize.x - GRID_CELL_CHECKBOX_MARGIN_X);
|
||||
}
|
||||
else // ( hAlign == wxALIGN_LEFT ) and invalid alignment value
|
||||
{
|
||||
checkBoxRect.SetX(cellRect.x + GRID_CELL_CHECKBOX_MARGIN_X);
|
||||
}
|
||||
|
||||
return checkBoxRect;
|
||||
}
|
||||
|
||||
#endif // wxUSE_GRID
|
||||
|
Reference in New Issue
Block a user