Merge branch 'grid-appearance-fixes'
Draw row/columns labels better in the disabled state and improve appearance of wxGrids with a border. See https://github.com/wxWidgets/wxWidgets/pull/1358
This commit is contained in:
@@ -2511,7 +2511,17 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Hides the column labels by calling SetColLabelSize() with a size of 0.
|
Hides the column labels by calling SetColLabelSize() with a size of 0.
|
||||||
Show labels again by calling that method with a width greater than 0.
|
|
||||||
|
The labels can be shown again by calling SetColLabelSize() with a
|
||||||
|
height greater than 0.
|
||||||
|
|
||||||
|
Note that when the column labels are hidden, the grid won't have any
|
||||||
|
visible border on the top side, which may result in a less than ideal
|
||||||
|
appearance. Because of this, you may want to create the grid window
|
||||||
|
with a border style, such as @c wxBORDER_SIMPLE, when you don't plan to
|
||||||
|
show the column labels for it.
|
||||||
|
|
||||||
|
@see HideRowLabels()
|
||||||
*/
|
*/
|
||||||
void HideColLabels();
|
void HideColLabels();
|
||||||
|
|
||||||
@@ -2520,6 +2530,9 @@ public:
|
|||||||
|
|
||||||
The labels can be shown again by calling SetRowLabelSize() with a width
|
The labels can be shown again by calling SetRowLabelSize() with a width
|
||||||
greater than 0.
|
greater than 0.
|
||||||
|
|
||||||
|
See HideColLabels() for a note explaining why you may want to use a
|
||||||
|
border with a grid without the row labels.
|
||||||
*/
|
*/
|
||||||
void HideRowLabels();
|
void HideRowLabels();
|
||||||
|
|
||||||
|
@@ -228,55 +228,101 @@ void wxGridHeaderLabelsRenderer::DrawLabel(const wxGrid& grid,
|
|||||||
int textOrientation) const
|
int textOrientation) const
|
||||||
{
|
{
|
||||||
dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT);
|
dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT);
|
||||||
dc.SetTextForeground(grid.GetLabelTextColour());
|
|
||||||
dc.SetFont(grid.GetLabelFont());
|
dc.SetFont(grid.GetLabelFont());
|
||||||
|
|
||||||
|
// Draw text in a different colour and with a shadow when the control
|
||||||
|
// is disabled.
|
||||||
|
//
|
||||||
|
// Note that the colours used here are consistent with wxGenericStaticText
|
||||||
|
// rather than our own wxGridCellStringRenderer::SetTextColoursAndFont()
|
||||||
|
// because this results in a better disabled appearance for the default
|
||||||
|
// bold font used for the labels.
|
||||||
|
wxColour colText;
|
||||||
|
if ( !grid.IsThisEnabled() )
|
||||||
|
{
|
||||||
|
colText = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNHIGHLIGHT);
|
||||||
|
dc.SetTextForeground(colText);
|
||||||
|
|
||||||
|
wxRect rectShadow = rect;
|
||||||
|
rectShadow.Offset(1, 1);
|
||||||
|
grid.DrawTextRectangle(dc, value, rectShadow,
|
||||||
|
horizAlign, vertAlign, textOrientation);
|
||||||
|
|
||||||
|
colText = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
colText = grid.GetLabelTextColour();
|
||||||
|
}
|
||||||
|
|
||||||
|
dc.SetTextForeground(colText);
|
||||||
|
|
||||||
grid.DrawTextRectangle(dc, value, rect, horizAlign, vertAlign, textOrientation);
|
grid.DrawTextRectangle(dc, value, rect, horizAlign, vertAlign, textOrientation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void wxGridRowHeaderRendererDefault::DrawBorder(const wxGrid& WXUNUSED(grid),
|
void wxGridRowHeaderRendererDefault::DrawBorder(const wxGrid& grid,
|
||||||
wxDC& dc,
|
wxDC& dc,
|
||||||
wxRect& rect) const
|
wxRect& rect) const
|
||||||
{
|
{
|
||||||
dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW)));
|
dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW)));
|
||||||
dc.DrawLine(rect.GetRight(), rect.GetTop(),
|
dc.DrawLine(rect.GetRight(), rect.GetTop(),
|
||||||
rect.GetRight(), rect.GetBottom());
|
rect.GetRight(), rect.GetBottom());
|
||||||
dc.DrawLine(rect.GetLeft(), rect.GetTop(),
|
|
||||||
rect.GetLeft(), rect.GetBottom());
|
|
||||||
dc.DrawLine(rect.GetLeft(), rect.GetBottom(),
|
dc.DrawLine(rect.GetLeft(), rect.GetBottom(),
|
||||||
rect.GetRight() + 1, rect.GetBottom());
|
rect.GetRight() + 1, rect.GetBottom());
|
||||||
|
|
||||||
|
// Only draw the external borders when the containing control doesn't have
|
||||||
|
// any border, otherwise they would compound with the outer border which
|
||||||
|
// looks bad.
|
||||||
|
int ofs = 0;
|
||||||
|
if ( grid.GetBorder() == wxBORDER_NONE )
|
||||||
|
{
|
||||||
|
dc.DrawLine(rect.GetLeft(), rect.GetTop(),
|
||||||
|
rect.GetLeft(), rect.GetBottom());
|
||||||
|
|
||||||
|
ofs = 1;
|
||||||
|
}
|
||||||
|
|
||||||
dc.SetPen(*wxWHITE_PEN);
|
dc.SetPen(*wxWHITE_PEN);
|
||||||
dc.DrawLine(rect.GetLeft() + 1, rect.GetTop(),
|
dc.DrawLine(rect.GetLeft() + ofs, rect.GetTop(),
|
||||||
rect.GetLeft() + 1, rect.GetBottom());
|
rect.GetLeft() + ofs, rect.GetBottom());
|
||||||
dc.DrawLine(rect.GetLeft() + 1, rect.GetTop(),
|
dc.DrawLine(rect.GetLeft() + ofs, rect.GetTop(),
|
||||||
rect.GetRight(), rect.GetTop());
|
rect.GetRight(), rect.GetTop());
|
||||||
|
|
||||||
rect.Deflate(2);
|
rect.Deflate(1 + ofs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxGridColumnHeaderRendererDefault::DrawBorder(const wxGrid& WXUNUSED(grid),
|
void wxGridColumnHeaderRendererDefault::DrawBorder(const wxGrid& grid,
|
||||||
wxDC& dc,
|
wxDC& dc,
|
||||||
wxRect& rect) const
|
wxRect& rect) const
|
||||||
{
|
{
|
||||||
dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW)));
|
dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW)));
|
||||||
dc.DrawLine(rect.GetRight(), rect.GetTop(),
|
dc.DrawLine(rect.GetRight(), rect.GetTop(),
|
||||||
rect.GetRight(), rect.GetBottom());
|
rect.GetRight(), rect.GetBottom());
|
||||||
dc.DrawLine(rect.GetLeft(), rect.GetTop(),
|
|
||||||
rect.GetRight(), rect.GetTop());
|
|
||||||
dc.DrawLine(rect.GetLeft(), rect.GetBottom(),
|
dc.DrawLine(rect.GetLeft(), rect.GetBottom(),
|
||||||
rect.GetRight() + 1, rect.GetBottom());
|
rect.GetRight() + 1, rect.GetBottom());
|
||||||
|
|
||||||
dc.SetPen(*wxWHITE_PEN);
|
// As above, don't draw the outer border if the control has its own one.
|
||||||
dc.DrawLine(rect.GetLeft(), rect.GetTop() + 1,
|
int ofs = 0;
|
||||||
rect.GetLeft(), rect.GetBottom());
|
if ( grid.GetBorder() == wxBORDER_NONE )
|
||||||
dc.DrawLine(rect.GetLeft(), rect.GetTop() + 1,
|
{
|
||||||
rect.GetRight(), rect.GetTop() + 1);
|
dc.DrawLine(rect.GetLeft(), rect.GetTop(),
|
||||||
|
rect.GetRight(), rect.GetTop());
|
||||||
|
|
||||||
rect.Deflate(2);
|
ofs = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
dc.SetPen(*wxWHITE_PEN);
|
||||||
|
dc.DrawLine(rect.GetLeft(), rect.GetTop() + ofs,
|
||||||
|
rect.GetLeft(), rect.GetBottom());
|
||||||
|
dc.DrawLine(rect.GetLeft(), rect.GetTop() + ofs,
|
||||||
|
rect.GetRight(), rect.GetTop() + ofs);
|
||||||
|
|
||||||
|
rect.Deflate(1 + ofs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxGridCornerHeaderRendererDefault::DrawBorder(const wxGrid& WXUNUSED(grid),
|
void wxGridCornerHeaderRendererDefault::DrawBorder(const wxGrid& grid,
|
||||||
wxDC& dc,
|
wxDC& dc,
|
||||||
wxRect& rect) const
|
wxRect& rect) const
|
||||||
{
|
{
|
||||||
@@ -285,18 +331,27 @@ void wxGridCornerHeaderRendererDefault::DrawBorder(const wxGrid& WXUNUSED(grid),
|
|||||||
rect.GetRight() - 1, rect.GetTop());
|
rect.GetRight() - 1, rect.GetTop());
|
||||||
dc.DrawLine(rect.GetRight() - 1, rect.GetBottom() - 1,
|
dc.DrawLine(rect.GetRight() - 1, rect.GetBottom() - 1,
|
||||||
rect.GetLeft(), rect.GetBottom() - 1);
|
rect.GetLeft(), rect.GetBottom() - 1);
|
||||||
dc.DrawLine(rect.GetLeft(), rect.GetTop(),
|
|
||||||
rect.GetRight(), rect.GetTop());
|
// As above, don't draw either of outer border if there is already a border
|
||||||
dc.DrawLine(rect.GetLeft(), rect.GetTop(),
|
// around the entire window.
|
||||||
rect.GetLeft(), rect.GetBottom());
|
int ofs = 0;
|
||||||
|
if ( grid.GetBorder() == wxBORDER_NONE )
|
||||||
|
{
|
||||||
|
dc.DrawLine(rect.GetLeft(), rect.GetTop(),
|
||||||
|
rect.GetRight(), rect.GetTop());
|
||||||
|
dc.DrawLine(rect.GetLeft(), rect.GetTop(),
|
||||||
|
rect.GetLeft(), rect.GetBottom());
|
||||||
|
|
||||||
|
ofs = 1;
|
||||||
|
}
|
||||||
|
|
||||||
dc.SetPen(*wxWHITE_PEN);
|
dc.SetPen(*wxWHITE_PEN);
|
||||||
dc.DrawLine(rect.GetLeft() + 1, rect.GetTop() + 1,
|
dc.DrawLine(rect.GetLeft() + 1, rect.GetTop() + ofs,
|
||||||
rect.GetRight() - 1, rect.GetTop() + 1);
|
rect.GetRight() - 1, rect.GetTop() + ofs);
|
||||||
dc.DrawLine(rect.GetLeft() + 1, rect.GetTop() + 1,
|
dc.DrawLine(rect.GetLeft() + ofs, rect.GetTop() + ofs,
|
||||||
rect.GetLeft() + 1, rect.GetBottom() - 1);
|
rect.GetLeft() + ofs, rect.GetBottom() - 1);
|
||||||
|
|
||||||
rect.Deflate(2);
|
rect.Deflate(1 + ofs);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user