Home » U++ Library support » ArrayCtrl, HeaderCtrl & GridCtrl » How can I set an image in GridCtrl cell ?
Re: How can I set an image in GridCtrl cell ? [message #59211 is a reply to message #13461] |
Sat, 26 November 2022 23:46 |
|
fudadmin
Messages: 1321 Registered: November 2005 Location: Kaunas, Lithuania
|
Ultimate Contributor Administrator |
|
|
If you want a view something like this:
One possibility is:
#include <GridCtrl/GridCtrl.h>
using namespace Upp;
#define IMAGEFILE "ImageGridCtrl/Icons.iml"
#define IMAGECLASS Images
#include <Draw/iml.h>
//from HomeBudget example
struct DispPM : GridDisplay
{
virtual void Paint(Draw &w, int x, int y, int cx, int cy, const Value &val, dword style,
Color &fg, Color &bg, Font &fnt, bool found, int fs, int fe)
{
if (val==0)
SetCenterImage(Images::one());
else if (val==1)
SetCenterImage(Images::two());
else if (val==2)
SetCenterImage(Images::three());
else
SetCenterImage(val);
GridDisplay::Paint(w, x, y, cx, cy, Value(""), style, fg, bg, fnt, found, fs, fe);
}
};
struct ImageGrid : TopWindow
{
GridCtrl gr;
ImageGrid() {
gr.AddColumn("Images").SetDisplay(Single<DispPM>());
for (int i = 0; i < 3; i++ )
{
gr.Add(i);
}
for (int i = 0; i < 10; i++ )
{
int r = Random(255);
int g = Random(255);
int b = Random(255);
Image img = CreateImage(Size(64,64), Color(r, g, b));
gr.Add(img);
}
Add(gr.SizePos());
};
~ImageGrid() {;};
};
GUI_APP_MAIN
{
ImageGrid().Title("ImageGrid").Run();
}
Another possibility would be something like this:
gr.AddColumn("RichText").Ctrls<RichTextView>();
with a possible mini Uword Editor to add images and/or links.
Btw, for some reasons, I couldn't get to work this case:
gr.AddColumn("ImageCtrl").Ctrls<ImageCtrl>();
which seems the most logical to use...
P.S. I see you need some help with answering questions on forums?..
P.P.S. Also, imho, there is a bug in GridCtrl::Clear(columns=true)
missing line:
aliases.Remove(1, aliases.GetCount() - 1); //TODO Report a BUG?
because if you clear columns and then add columns in the same GridCtrl again, it accumulates/duplicates aliases, messes up indexes and crashes...
the whole method should be at least like this:
void GridCtrl::Clear(bool columns)
{
doscroll = false;
anchor = Null;
UpdateCtrls(UC_HIDE | UC_CTRLS);
int nrows = columns ? 1 : fixed_rows;
items.Remove(nrows, items.GetCount() - nrows);
vitems.Remove(nrows, vitems.GetCount() - nrows);
total_rows = nrows;
fixed_rows = nrows;
if(columns)
{
hitems.Remove(1, hitems.GetCount() - 1);
items[0].Remove(1, items[0].GetCount() - 1);
rowbkp.Remove(1, rowbkp.GetCount() - 1);
edits.Remove(1, edits.GetCount() - 1);
sortOrder.Clear();
total_cols = 1;
total_width = 0;
total_height = 0;
firstCol = -1;
lastCol = -1;
fixed_cols = 1;
coluid = 0;
hcol = -1;
sortCol = -1;
genr_ctrls = 0;
firstVisCol = fixed_cols;
lastVisCol = total_cols - 1;
aliases.Remove(1, aliases.GetCount() - 1); //TODO Report a BUG?
}
else
{
total_height = fixed_height;
}
firstVisRow = fixed_rows;
lastVisRow = total_rows - 1;
focused_ctrl = NULL;
valid_cursor = false;
firstRow = -1;
lastRow = -1;
curpos.x = curpos.y = -1;
curid.x = curid.y = -1;
hrow = -1;
rowidx = -1;
rowuid = 0;
row_modified = 0;
UpdateSizes();
UpdateSb();
if(ready)
{
UpdateHolder();
oldpos.x = sbx;
oldpos.y = sby;
RebuildToolBar();
Refresh();
}
WhenEmpty();
WhenCursor();
doscroll = true;
}
|
|
|
Goto Forum:
Current Time: Fri May 10 03:32:09 CEST 2024
Total time taken to generate the page: 0.02483 seconds
|