KiCad PCB EDA Suite
GRID_CELL_ICON_TEXT_RENDERER Class Reference

#include <grid_icon_text_helpers.h>

Inheritance diagram for GRID_CELL_ICON_TEXT_RENDERER:

Public Member Functions

 GRID_CELL_ICON_TEXT_RENDERER (const std::vector< BITMAPS > &icons, const wxArrayString &names)
 
void Draw (wxGrid &aGrid, wxGridCellAttr &aAttr, wxDC &aDC, const wxRect &aRect, int aRow, int aCol, bool isSelected) override
 
wxSize GetBestSize (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, int col) override
 

Private Attributes

std::vector< BITMAPSm_icons
 
wxArrayString m_names
 

Detailed Description

Definition at line 39 of file grid_icon_text_helpers.h.

Constructor & Destructor Documentation

◆ GRID_CELL_ICON_TEXT_RENDERER()

GRID_CELL_ICON_TEXT_RENDERER::GRID_CELL_ICON_TEXT_RENDERER ( const std::vector< BITMAPS > &  icons,
const wxArrayString &  names 
)

Definition at line 34 of file grid_icon_text_helpers.cpp.

35 :
36 m_icons( icons ),
37 m_names( names )
38{
39}

Member Function Documentation

◆ Draw()

void GRID_CELL_ICON_TEXT_RENDERER::Draw ( wxGrid &  aGrid,
wxGridCellAttr &  aAttr,
wxDC &  aDC,
const wxRect &  aRect,
int  aRow,
int  aCol,
bool  isSelected 
)
override

Definition at line 42 of file grid_icon_text_helpers.cpp.

44{
45 wxString value = aGrid.GetCellValue( aRow, aCol );
46 wxBitmap bitmap;
47
48 wxRect rect = aRect;
49 rect.Inflate( -1 );
50
51 // erase background
52 wxGridCellRenderer::Draw( aGrid, aAttr, aDC, aRect, aRow, aCol, isSelected );
53
54 // draw the icon
55 // note that the set of icons might be smaller than the set of labels if the last
56 // label is <...>.
57 int position = m_names.Index( value );
58
59 if( position < (int) m_icons.size() && position != wxNOT_FOUND )
60 {
61 bitmap = KiBitmap( m_icons[ position ] );
62 aDC.DrawBitmap( bitmap, rect.GetLeft() + 3, rect.GetTop() + 2, true );
63 }
64 else // still need a bitmap to fetch the width
65 {
66 bitmap = KiBitmap( m_icons[ 0 ] );
67 }
68
69 // draw the text
70 rect.SetLeft( rect.GetLeft() + bitmap.GetWidth() + 7 );
71 SetTextColoursAndFont( aGrid, aAttr, aDC, isSelected );
72 aGrid.DrawTextRectangle( aDC, value, rect, wxALIGN_LEFT, wxALIGN_CENTRE );
73}
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:105

References KiBitmap(), m_icons, and m_names.

◆ GetBestSize()

wxSize GRID_CELL_ICON_TEXT_RENDERER::GetBestSize ( wxGrid &  grid,
wxGridCellAttr &  attr,
wxDC &  dc,
int  row,
int  col 
)
override

Definition at line 75 of file grid_icon_text_helpers.cpp.

77{
78 wxBitmap bitmap = KiBitmap( m_icons[ row ] );
79 wxString text = grid.GetCellValue( row, col );
80 wxSize size = wxGridCellStringRenderer::DoGetBestSize( attr, dc, text );
81
82 size.x += bitmap.GetWidth() + 6;
83
84 return size;
85}

References grid, KiBitmap(), m_icons, and text.

Member Data Documentation

◆ m_icons

std::vector<BITMAPS> GRID_CELL_ICON_TEXT_RENDERER::m_icons
private

Definition at line 49 of file grid_icon_text_helpers.h.

Referenced by Draw(), and GetBestSize().

◆ m_names

wxArrayString GRID_CELL_ICON_TEXT_RENDERER::m_names
private

Definition at line 50 of file grid_icon_text_helpers.h.

Referenced by Draw().


The documentation for this class was generated from the following files: