Added a way to set the text color of a part.

This commit is contained in:
Pietro Gagliardi 2016-06-23 22:16:25 -04:00
parent 9d22d741c6
commit 4914d0c64c
3 changed files with 37 additions and 3 deletions

View File

@ -19,6 +19,7 @@ enum {
@interface tablePart : NSObject
@property int type;
@property int textColumn;
@property int textColorColumn;
@property int expand;
- (NSView *)mkView:(uiTableModel *)m row:(int)row;
@end
@ -150,6 +151,16 @@ done:
@implementation tablePart
- (id)init
{
self = [super init];
if (self) {
self.textColumn = -1;
self.textColorColumn = -1;
}
return self;
}
- (NSView *)mkView:(uiTableModel *)m row:(int)row
{
void *data;
@ -163,7 +174,15 @@ done:
str = toNSString((char *) data);
uiFree(data);
tf = newLabel(str);
// TODO set wrap and ellipsize modes
// TODO set wrap and ellipsize modes?
if (self.textColorColumn != -1) {
NSColor *color;
color = (NSColor *) ((*(m->mh->CellValue))(m->mh, m, row, self.textColorColumn));
if (color != nil)
[tf setTextColor:color];
// TODO release color
}
view = tf;
break;
}
@ -268,6 +287,14 @@ void uiTableColumnAppendTextPart(uiTableColumn *c, int modelColumn, int expand)
[c->parts addObject:part];
}
void uiTableColumnPartSetTextColor(uiTableColumn *c, int part, int modelColumn)
{
tablePart *p;
p = (tablePart *) [c->parts objectAtIndex:part];
p.textColorColumn = modelColumn;
}
uiDarwinControlAllDefaultsExceptDestroy(uiTable, sv)
static void uiTableDestroy(uiControl *c)

View File

@ -5,12 +5,12 @@ static uiTableModelHandler mh;
static int modelNumColumns(uiTableModelHandler *mh, uiTableModel *m)
{
return 4;
return 5;
}
static uiTableModelColumnType modelColumnType(uiTableModelHandler *mh, uiTableModel *m, int column)
{
if (column == 3)
if (column == 3 || column == 4)
return uiTableModelColumnColor;
return uiTableModelColumnString;
}
@ -31,6 +31,11 @@ static void *modelCellValue(uiTableModelHandler *mh, uiTableModel *m, int row, i
return uiTableModelGiveColor(0, 0.5, 1, 0.5);
return NULL;
}
if (col == 4) {
if ((row % 2) == 1)
return uiTableModelGiveColor(0.5, 0, 0.75, 1);
return NULL;
}
switch (col) {
case 0:
sprintf(buf, "Row %d", row);
@ -72,6 +77,7 @@ uiBox *makePage16(void)
tc = uiTableAppendColumn(t, "Column 2");
uiTableColumnAppendTextPart(tc, 1, 0);
uiTableColumnAppendTextPart(tc, 2, 1);
uiTableColumnPartSetTextColor(tc, 1, 4);
uiTableSetRowBackgroundColorModelColumn(t, 3);

View File

@ -31,6 +31,7 @@ _UI_EXTERN void uiTableModelRowDeleted(uiTableModel *m, int oldIndex);
typedef struct uiTableColumn uiTableColumn;
_UI_EXTERN void uiTableColumnAppendTextPart(uiTableColumn *c, int modelColumn, int expand);
_UI_EXTERN void uiTableColumnPartSetTextColor(uiTableColumn *c, int part, int modelColumn);
typedef struct uiTable uiTable;
#define uiTable(this) ((uiTable *) (this))