mirror of
https://github.com/irssi/irssi.git
synced 2026-08-21 01:22:26 +02:00
get_max_column_count() didn't work properly when there was only one item
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1166 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
f5ea5348c0
commit
4bcae4c071
1 changed files with 14 additions and 8 deletions
|
|
@ -612,6 +612,7 @@ int get_max_column_count(GSList *items, COLUMN_LEN_FUNC len_func,
|
||||||
int max_width, int item_extra, int item_min_size,
|
int max_width, int item_extra, int item_min_size,
|
||||||
int **save_column_widths, int *rows)
|
int **save_column_widths, int *rows)
|
||||||
{
|
{
|
||||||
|
GSList *tmp;
|
||||||
int **columns, *columns_width, *columns_rows;
|
int **columns, *columns_width, *columns_rows;
|
||||||
int item_pos, items_count;
|
int item_pos, items_count;
|
||||||
int ret, len, n, col, max_columns;
|
int ret, len, n, col, max_columns;
|
||||||
|
|
@ -625,15 +626,15 @@ int get_max_column_count(GSList *items, COLUMN_LEN_FUNC len_func,
|
||||||
|
|
||||||
for (n = 1; n < max_columns; n++) {
|
for (n = 1; n < max_columns; n++) {
|
||||||
columns[n] = g_new0(int, n+1);
|
columns[n] = g_new0(int, n+1);
|
||||||
columns_rows[n] = items_count < n+1 ? 1 :
|
columns_rows[n] = items_count <= n+1 ? 1 :
|
||||||
(items_count+n)/(n+1);
|
(items_count+n)/(n+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* for each possible column count, save the column widths and
|
/* for each possible column count, save the column widths and
|
||||||
find the biggest column count that fits to screen. */
|
find the biggest column count that fits to screen. */
|
||||||
item_pos = 0;
|
item_pos = 0;
|
||||||
while (items != NULL) {
|
for (tmp = items; tmp != NULL; tmp = tmp->next) {
|
||||||
len = item_extra+len_func(items->data);
|
len = item_extra+len_func(tmp->data);
|
||||||
for (n = 1; n < max_columns; n++) {
|
for (n = 1; n < max_columns; n++) {
|
||||||
if (columns_width[n] > max_width)
|
if (columns_width[n] > max_width)
|
||||||
continue; /* too wide */
|
continue; /* too wide */
|
||||||
|
|
@ -645,19 +646,24 @@ int get_max_column_count(GSList *items, COLUMN_LEN_FUNC len_func,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
items = items->next;
|
|
||||||
item_pos++;
|
item_pos++;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (n = max_columns-1; n >= 0; n--) {
|
for (n = max_columns-1; n > 0; n--) {
|
||||||
if (columns_width[n] <= max_width && columns[n][n] > 0)
|
if (columns_width[n] <= max_width &&
|
||||||
|
columns[n][n] > 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ret = n+1;
|
ret = n+1;
|
||||||
|
|
||||||
*save_column_widths = g_new(int, ret);
|
*save_column_widths = g_new(int, ret);
|
||||||
|
if (ret == 1) {
|
||||||
|
**save_column_widths = item_extra+len_func(items->data);
|
||||||
|
*rows = 1;
|
||||||
|
} else {
|
||||||
memcpy(*save_column_widths, columns[ret-1], sizeof(int)*ret);
|
memcpy(*save_column_widths, columns[ret-1], sizeof(int)*ret);
|
||||||
*rows = columns_rows[ret-1];
|
*rows = columns_rows[ret-1];
|
||||||
|
}
|
||||||
|
|
||||||
for (n = 1; n < max_columns; n++)
|
for (n = 1; n < max_columns; n++)
|
||||||
g_free(columns[n]);
|
g_free(columns[n]);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue