wxRuby Documentation Home

# Wx::GridCellRenderer

This class and its subclasses are responsible for actually drawing the
cell in the grid. You may pass instances of this class as arguments to
Grid or GridCellAttr to specify a
renderer to be used by a single cell, a row, a column, or the whole
grid, using grid#set_default_renderer

As well as predefined renderers for displaying numbers, text and so
forth, completely custom subclasses can be defined to draw arbitrary
content in grid cells, including text and graphics. To define your own
renderer, inherit from one of the predefined classes (for example,
GridCellStringRenderer, and define your
own draw method. Among the arguments passed to
draw is a DC which can be used for drawing. Note that it is
not possible to inherit directly from this class.

This example draws the text content normally, with a red diagonal line
running through the cell:

class MyGridCellRenderer < Wx::GridCellStringRenderer def draw(grid, attr, dc, rect, row, col, is_selected) super(grid, attr, dc, rect, row, col, is_selected) dc.pen = Wx::RED_PEN dc.draw_line(rect.left, rect.top, rect.right, rect.bottom) end end

## Derived from

GridCellWorker

## See also

GridCellStringRenderer, GridCellNumberRenderer, GridCellFloatRenderer, GridCellBoolRenderer

## Methods

- GridCellRenderer#draw
- GridCellRenderer#get_best_size
- GridCellRenderer#clone

### GridCellRenderer#draw

draw(%(arg-type)Grid% grid, GridCellAttr attr, DC dc, Rect rect, Integer row, Integer col, Boolean isSelected)

Draw the given cell on the provided DC inside the given rectangle
using the style specified by the attribute and the default or selected
state corresponding to the isSelected value.

This pure virtual function has a default implementation which will
prepare the DC using the given attribute: it will draw the rectangle
with the background colour from attr and set the text colour and font.

### GridCellRenderer#get_best_size

Size get_best_size(%(arg-type)Grid% grid, GridCellAttr attr, DC dc, Integer row, Integer col)

Get the preferred size of the cell for its contents.

### GridCellRenderer#clone

GridCellRenderer clone()

[This page automatically generated from the Textile source at 2023-06-09 00:45:31 +0000]