Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new API functions to get/set table column widths. #514

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions darwin/table.m
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,16 @@ static void uiTableDestroy(uiControl *c)

return t;
}

int uiTableColumnWidth(uiTable *t, int column)
{
NSTableColumn *tc = [t->tv tableColumnWithIdentifier:[@(column) stringValue]];
return [tc width];
}

void uiTableColumnSetWidth(uiTable *t, int column, int width)
{
NSTableColumn *tc = [t->tv tableColumnWithIdentifier:[@(column) stringValue]];
[tc setWidth: width];
}

28 changes: 21 additions & 7 deletions darwin/tablecolumn.m
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ void uiTableAppendTextColumn(uiTable *t, const char *name, int textModelColumn,
struct textColumnCreateParams p;
uiprivTableColumn *col;
NSString *str;
NSString *ident;

memset(&p, 0, sizeof (struct textColumnCreateParams));
p.t = t;
Expand All @@ -597,8 +598,9 @@ void uiTableAppendTextColumn(uiTable *t, const char *name, int textModelColumn,
else
p.textParams = uiprivDefaultTextColumnOptionalParams;

ident = [@([[t->tv tableColumns] count]) stringValue];
col = [[uiprivTextImageCheckboxTableColumn alloc] initWithIdentifier:ident params:&p];
str = [NSString stringWithUTF8String:name];
col = [[uiprivTextImageCheckboxTableColumn alloc] initWithIdentifier:str params:&p];
[col setTitle:str];
[t->tv addTableColumn:col];
}
Expand All @@ -608,6 +610,7 @@ void uiTableAppendImageColumn(uiTable *t, const char *name, int imageModelColumn
struct textColumnCreateParams p;
uiprivTableColumn *col;
NSString *str;
NSString *ident;

memset(&p, 0, sizeof (struct textColumnCreateParams));
p.t = t;
Expand All @@ -616,8 +619,9 @@ void uiTableAppendImageColumn(uiTable *t, const char *name, int imageModelColumn
p.makeImageView = YES;
p.imageModelColumn = imageModelColumn;

ident = [@([[t->tv tableColumns] count]) stringValue];
col = [[uiprivTextImageCheckboxTableColumn alloc] initWithIdentifier:ident params:&p];
str = [NSString stringWithUTF8String:name];
col = [[uiprivTextImageCheckboxTableColumn alloc] initWithIdentifier:str params:&p];
[col setTitle:str];
[t->tv addTableColumn:col];
}
Expand All @@ -627,6 +631,7 @@ void uiTableAppendImageTextColumn(uiTable *t, const char *name, int imageModelCo
struct textColumnCreateParams p;
uiprivTableColumn *col;
NSString *str;
NSString *ident;

memset(&p, 0, sizeof (struct textColumnCreateParams));
p.t = t;
Expand All @@ -643,8 +648,9 @@ void uiTableAppendImageTextColumn(uiTable *t, const char *name, int imageModelCo
p.makeImageView = YES;
p.imageModelColumn = imageModelColumn;

ident = [@([[t->tv tableColumns] count]) stringValue];
col = [[uiprivTextImageCheckboxTableColumn alloc] initWithIdentifier:ident params:&p];
str = [NSString stringWithUTF8String:name];
col = [[uiprivTextImageCheckboxTableColumn alloc] initWithIdentifier:str params:&p];
[col setTitle:str];
[t->tv addTableColumn:col];
}
Expand All @@ -654,6 +660,7 @@ void uiTableAppendCheckboxColumn(uiTable *t, const char *name, int checkboxModel
struct textColumnCreateParams p;
uiprivTableColumn *col;
NSString *str;
NSString *ident;

memset(&p, 0, sizeof (struct textColumnCreateParams));
p.t = t;
Expand All @@ -663,8 +670,9 @@ void uiTableAppendCheckboxColumn(uiTable *t, const char *name, int checkboxModel
p.checkboxModelColumn = checkboxModelColumn;
p.checkboxEditableModelColumn = checkboxEditableModelColumn;

ident = [@([[t->tv tableColumns] count]) stringValue];
col = [[uiprivTextImageCheckboxTableColumn alloc] initWithIdentifier:ident params:&p];
str = [NSString stringWithUTF8String:name];
col = [[uiprivTextImageCheckboxTableColumn alloc] initWithIdentifier:str params:&p];
[col setTitle:str];
[t->tv addTableColumn:col];
}
Expand All @@ -674,6 +682,7 @@ void uiTableAppendCheckboxTextColumn(uiTable *t, const char *name, int checkboxM
struct textColumnCreateParams p;
uiprivTableColumn *col;
NSString *str;
NSString *ident;

memset(&p, 0, sizeof (struct textColumnCreateParams));
p.t = t;
Expand All @@ -691,8 +700,9 @@ void uiTableAppendCheckboxTextColumn(uiTable *t, const char *name, int checkboxM
p.checkboxModelColumn = checkboxModelColumn;
p.checkboxEditableModelColumn = checkboxEditableModelColumn;

ident = [@([[t->tv tableColumns] count]) stringValue];
col = [[uiprivTextImageCheckboxTableColumn alloc] initWithIdentifier:ident params:&p];
str = [NSString stringWithUTF8String:name];
col = [[uiprivTextImageCheckboxTableColumn alloc] initWithIdentifier:str params:&p];
[col setTitle:str];
[t->tv addTableColumn:col];
}
Expand All @@ -701,9 +711,11 @@ void uiTableAppendProgressBarColumn(uiTable *t, const char *name, int progressMo
{
uiprivTableColumn *col;
NSString *str;
NSString *ident;

ident = [@([[t->tv tableColumns] count]) stringValue];
col = [[uiprivProgressBarTableColumn alloc] initWithIdentifier:ident table:t model:t->m modelColumn:progressModelColumn];
str = [NSString stringWithUTF8String:name];
col = [[uiprivProgressBarTableColumn alloc] initWithIdentifier:str table:t model:t->m modelColumn:progressModelColumn];
[col setTitle:str];
[t->tv addTableColumn:col];
}
Expand All @@ -712,9 +724,11 @@ void uiTableAppendButtonColumn(uiTable *t, const char *name, int buttonModelColu
{
uiprivTableColumn *col;
NSString *str;
NSString *ident;

ident = [@([[t->tv tableColumns] count]) stringValue];
col = [[uiprivButtonTableColumn alloc] initWithIdentifier:ident table:t model:t->m modelColumn:buttonModelColumn editableColumn:buttonClickableModelColumn];
str = [NSString stringWithUTF8String:name];
col = [[uiprivButtonTableColumn alloc] initWithIdentifier:str table:t model:t->m modelColumn:buttonModelColumn editableColumn:buttonClickableModelColumn];
[col setTitle:str];
[t->tv addTableColumn:col];
}
27 changes: 27 additions & 0 deletions test/page16.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,26 @@ static void modelSetCellValue(uiTableModelHandler *mh, uiTableModel *m, int row,
checkStates[row] = uiTableValueInt(val);
}

uiSpinbox *columnID;
uiSpinbox *columnWidth;
static void changedColumnID(uiSpinbox *s, void *data)
{
uiTable *t = data;
uiSpinboxSetValue(columnWidth, uiTableColumnWidth(t, uiSpinboxValue(columnID)));
}

static void changedColumnWidth(uiSpinbox *s, void *data)
{
uiTable *t = data;
uiTableColumnSetWidth(t, uiSpinboxValue(columnID), uiSpinboxValue(columnWidth));
}

static uiTableModel *m;

uiBox *makePage16(void)
{
uiBox *page16;
uiBox *controls;
uiTable *t;
uiTableParams p;
uiTableTextColumnOptionalParams tp;
Expand All @@ -119,6 +134,8 @@ uiBox *makePage16(void)
memset(checkStates, 0, 15 * sizeof (int));

page16 = newVerticalBox();
controls = newHorizontalBox();
uiBoxAppend(page16, uiControl(controls), 0);

mh.NumColumns = modelNumColumns;
mh.ColumnType = modelColumnType;
Expand Down Expand Up @@ -152,6 +169,16 @@ uiBox *makePage16(void)
uiTableAppendProgressBarColumn(t, "Progress Bar",
8);

uiBoxAppend(controls, uiControl(uiNewLabel("Column")), 0);
columnID = uiNewSpinbox(0, INT_MAX);
uiBoxAppend(controls, uiControl(columnID), 0);
uiBoxAppend(controls, uiControl(uiNewLabel("Width")), 0);
columnWidth = uiNewSpinbox(0, INT_MAX);
uiBoxAppend(controls, uiControl(columnWidth), 0);

uiSpinboxOnChanged(columnID, changedColumnID, t);
uiSpinboxOnChanged(columnWidth, changedColumnWidth, t);

return page16;
}

Expand Down
6 changes: 6 additions & 0 deletions ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,12 @@ _UI_EXTERN void uiTableAppendButtonColumn(uiTable *t,
// uiNewTable() creates a new uiTable with the specified parameters.
_UI_EXTERN uiTable *uiNewTable(uiTableParams *params);

// uiTableColumnWidth() return current table column width
_UI_EXTERN int uiTableColumnWidth(uiTable *t, int column);

// uiTableColumnSetWidth() set table column width
_UI_EXTERN void uiTableColumnSetWidth(uiTable *t, int column, int width);

#ifdef __cplusplus
}
#endif
Expand Down
13 changes: 13 additions & 0 deletions unix/table.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,3 +522,16 @@ uiTable *uiNewTable(uiTableParams *p)

return t;
}

int uiTableColumnWidth(uiTable *t, int column)
{
GtkTreeViewColumn *c = gtk_tree_view_get_column(t->tv, column);
return gtk_tree_view_column_get_width(c);
}

void uiTableColumnSetWidth(uiTable *t, int column, int width)
{
GtkTreeViewColumn *c = gtk_tree_view_get_column(t->tv, column);
gtk_tree_view_column_set_fixed_width(c, width);
}

11 changes: 11 additions & 0 deletions windows/table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,3 +520,14 @@ uiTable *uiNewTable(uiTableParams *p)

return t;
}

int uiTableColumnWidth(uiTable *t, int column)
{
return ListView_GetColumnWidth(t->hwnd, column);
}

void uiTableColumnSetWidth(uiTable *t, int column, int width)
{
ListView_SetColumnWidth(t->hwnd, column, width);
}