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  auto position = m_names.Index( value );
58  if( position < (int) m_icons.size() && position != wxNOT_FOUND )
59  {
60  bitmap = KiBitmap( m_icons[ position ] );
61  aDC.DrawBitmap( bitmap, rect.GetLeft() + 3, rect.GetTop() + 2, true );
62  }
63  else // still need a bitmap to fetch the width
64  {
65  bitmap = KiBitmap( m_icons[ 0 ] );
66  }
67 
68  // draw the text
69  rect.SetLeft( rect.GetLeft() + bitmap.GetWidth() + 7 );
70  SetTextColoursAndFont( aGrid, aAttr, aDC, isSelected );
71  aGrid.DrawTextRectangle( aDC, value, rect, wxALIGN_LEFT, wxALIGN_CENTRE );
72 }
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 74 of file grid_icon_text_helpers.cpp.

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