[C] Refactoring of min column width implementation

This commit is contained in:
seleznevae 2018-02-26 21:47:19 +03:00
parent 284cb61321
commit 85ffccfdb2
4 changed files with 33 additions and 18 deletions

View File

@ -39,12 +39,18 @@ void destroy_cell(fort_cell_t *cell)
int hint_width_cell(const fort_cell_t *cell, const context_t *context)
{
/* todo:
* At the moment min width includes paddings. Maybe it is better that min width weren't include
* paddings but be min width of the cell content without padding
*/
assert(cell);
assert(context);
int result = context->table_options->cell_padding_left + context->table_options->cell_padding_right;
if (cell->str_buffer && cell->str_buffer->str) {
result += buffer_text_width(cell->str_buffer);
}
result = MAX(result, get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_OPT_MIN_WIDTH));
return result;
}

View File

@ -304,19 +304,28 @@ void destroy_table_options(fort_table_options_t* options)
// return ((fort_column_options_t*)vector_at(options->col_options, column))->col_min_width;
//}
int fort_options_column_width(const fort_table_options_t *options, size_t column)
{
assert(options);
if (options->cell_options == NULL)
return -1;
const fort_cell_options_t* col_opt = cget_cell_opt(options->cell_options, FT_ANY_ROW, column);
if (col_opt == NULL || ((col_opt->options & FT_OPT_MIN_WIDTH) == 0))
return -1;
else {
return col_opt->col_min_width;
}
}
//int fort_options_column_width(const fort_table_options_t *options, size_t column)
//{
// assert(options);
// if (options->cell_options == NULL)
// return -1;
// const fort_cell_options_t* col_opt = cget_cell_opt(options->cell_options, FT_ANY_ROW, column);
// if (col_opt == NULL || ((col_opt->options & FT_OPT_MIN_WIDTH) == 0))
// return -1;
// else {
// return col_opt->col_min_width;
// }
//}
//int fort_options_column_alignment(const fort_table_options_t *options, size_t column)
//{

View File

@ -151,7 +151,7 @@ fort_table_options_t* copy_table_options(const fort_table_options_t *option);
void destroy_table_options(fort_table_options_t* options);
//fort_status_t fort_options_set_column_min_width(fort_table_options_t *options, size_t column, size_t width);
//fort_status_t fort_options_set_column_alignment(fort_table_options_t *options, size_t column, enum TextAlignment al);
int fort_options_column_width(const fort_table_options_t *options, size_t column);
//int fort_options_column_width(const fort_table_options_t *options, size_t column);
//int fort_options_column_alignment(const fort_table_options_t *options, size_t column);

View File

@ -132,11 +132,11 @@ fort_status_t table_rows_and_cols_geometry(const FTABLE *table,
* At the moment min width includes paddings. Maybe it is better that min width weren't include
* paddings but be min width of the cell content without padding
*/
if (table->options) {
for (size_t i = 0; i < cols; ++i) {
col_width_arr[i] = MAX((int)col_width_arr[i], fort_options_column_width(table->options, i));
}
}
// if (table->options) {
// for (size_t i = 0; i < cols; ++i) {
// col_width_arr[i] = MAX((int)col_width_arr[i], fort_options_column_width(table->options, i));
// }
// }
*col_width_arr_p = col_width_arr;
*col_width_arr_sz = cols;