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 38 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 35 of file grid_icon_text_helpers.cpp.

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

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  // still need a bitmap to fetch the width
64  else
65  bitmap = KiBitmap( m_icons[ 0 ] );
66 
67  // draw the text
68  rect.SetLeft( rect.GetLeft() + bitmap.GetWidth() + 7 );
69  SetTextColoursAndFont( aGrid, aAttr, aDC, isSelected );
70  aGrid.DrawTextRectangle( aDC, value, rect, wxALIGN_LEFT, wxALIGN_CENTRE );
71 }
wxBitmap KiBitmap(BITMAPS aBitmap)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:104

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 73 of file grid_icon_text_helpers.cpp.

75 {
76  wxBitmap bitmap = KiBitmap( m_icons[ row ] );
77  wxString text = grid.GetCellValue( row, col );
78  wxSize size = wxGridCellStringRenderer::DoGetBestSize( attr, dc, text );
79 
80  size.x += bitmap.GetWidth() + 6;
81 
82  return size;
83 }
wxBitmap KiBitmap(BITMAPS aBitmap)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:104

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 48 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 49 of file grid_icon_text_helpers.h.

Referenced by Draw().


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