[C] Changed cell padding setting

This commit is contained in:
seleznevae
2018-02-27 21:41:58 +03:00
parent 46758ee032
commit 441442fa9e
6 changed files with 134 additions and 209 deletions

View File

@@ -46,7 +46,9 @@ int hint_width_cell(const fort_cell_t *cell, const context_t *context)
assert(cell);
assert(context);
int result = context->table_options->cell_padding_left + context->table_options->cell_padding_right;
int cell_padding_left = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_OPT_LEFT_PADDING);
int cell_padding_right = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_OPT_RIGHT_PADDING);
int result = cell_padding_left + cell_padding_right;
if (cell->str_buffer && cell->str_buffer->str) {
result += buffer_text_width(cell->str_buffer);
}
@@ -58,10 +60,13 @@ int hint_height_cell(const fort_cell_t *cell, const context_t *context)
{
assert(cell);
assert(context);
int result = context->table_options->cell_padding_top + context->table_options->cell_padding_bottom;
int cell_padding_top = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_OPT_TOP_PADDING);
int cell_padding_bottom = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_OPT_BOTTOM_PADDING);
int cell_empty_string_height = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_OPT_EMPTY_STR_HEIGHT);
int result = cell_padding_top + cell_padding_bottom;
if (cell->str_buffer && cell->str_buffer->str) {
size_t text_height = buffer_text_height(cell->str_buffer);
result += text_height == 0 ? context->table_options->cell_empty_string_height : text_height;
result += text_height == 0 ? cell_empty_string_height : text_height;
}
return result;
}
@@ -94,20 +99,24 @@ int cell_printf(fort_cell_t *cell, size_t row, size_t column, char *buf, size_t
return -1;
}
int cell_padding_top = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_OPT_TOP_PADDING);
int cell_padding_left = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_OPT_LEFT_PADDING);
int cell_padding_right = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_OPT_RIGHT_PADDING);
if (row >= hint_height_cell(cell, context)
|| row < context->table_options->cell_padding_top
|| row >= (context->table_options->cell_padding_top + buffer_text_height(cell->str_buffer))) {
|| row < cell_padding_top
|| row >= (cell_padding_top + buffer_text_height(cell->str_buffer))) {
int k = snprint_n_chars(buf, buf_len, buf_len - 1, ' ');
return k;
} else {
int written = 0;
int left = context->table_options->cell_padding_left;
int right = context->table_options->cell_padding_right;
int left = cell_padding_left;
int right = cell_padding_right;
written += snprint_n_chars(buf + written, buf_len - written, left, ' ');
if (cell->str_buffer)
written += buffer_printf(cell->str_buffer, row - context->table_options->cell_padding_top, column, buf + written, buf_len - written - right, context);
written += buffer_printf(cell->str_buffer, row - cell_padding_top, column, buf + written, buf_len - written - right, context);
else
written += snprint_n_chars(buf + written, buf_len - written, buf_len - written - right, ' ');
written += snprint_n_chars(buf + written, buf_len - written, right, ' ');

View File

@@ -575,30 +575,30 @@ int ft_add_separator(FTABLE *table)
return F_SUCCESS;
}
int ft_set_default_option(uint32_t option, int value)
{
switch (option) {
case FT_OPT_TOP_PADDING:
g_table_options.cell_padding_top = value;
break;
case FT_OPT_BOTTOM_PADDING:
g_table_options.cell_padding_bottom = value;
break;
case FT_OPT_LEFT_PADDING:
g_table_options.cell_padding_left = value;
break;
case FT_OPT_RIGHT_PADDING:
g_table_options.cell_padding_right = value;
break;
case FT_OPT_EMPTY_STR_HEIGHT:
g_table_options.cell_empty_string_height = value;
break;
default:
// todo
exit(22);
}
return F_SUCCESS;
}
//int ft_set_default_option(uint32_t option, int value)
//{
// switch (option) {
// case FT_OPT_TOP_PADDING:
// g_table_options.cell_padding_top = value;
// break;
// case FT_OPT_BOTTOM_PADDING:
// g_table_options.cell_padding_bottom = value;
// break;
// case FT_OPT_LEFT_PADDING:
// g_table_options.cell_padding_left = value;
// break;
// case FT_OPT_RIGHT_PADDING:
// g_table_options.cell_padding_right = value;
// break;
// case FT_OPT_EMPTY_STR_HEIGHT:
// g_table_options.cell_empty_string_height = value;
// break;
// default:
// // todo
// exit(22);
// }
// return F_SUCCESS;
//}
static void set_border_options_for_options(fort_table_options_t *options, struct border_chars *border_chs, struct border_chars *header_border_chs)
@@ -667,37 +667,37 @@ int ft_set_table_borders(FTABLE *table, struct border_chars *border_chs, struct
return F_SUCCESS;
}
int ft_set_table_option(FTABLE *table, uint32_t option, int value)
{
assert(table);
if (table->options == NULL) {
table->options = create_table_options();
if (table->options == NULL)
return F_MEMORY_ERROR;
}
switch (option) {
case FT_OPT_TOP_PADDING:
table->options->cell_padding_top = value;
break;
case FT_OPT_BOTTOM_PADDING:
table->options->cell_padding_bottom = value;
break;
case FT_OPT_LEFT_PADDING:
table->options->cell_padding_left = value;
break;
case FT_OPT_RIGHT_PADDING:
table->options->cell_padding_right = value;
break;
case FT_OPT_EMPTY_STR_HEIGHT:
table->options->cell_empty_string_height = value;
break;
default:
// todo
exit(22);
}
return F_SUCCESS;
//int ft_set_table_option(FTABLE *table, uint32_t option, int value)
//{
// assert(table);
// if (table->options == NULL) {
// table->options = create_table_options();
// if (table->options == NULL)
// return F_MEMORY_ERROR;
// }
// switch (option) {
// case FT_OPT_TOP_PADDING:
// table->options->cell_padding_top = value;
// break;
// case FT_OPT_BOTTOM_PADDING:
// table->options->cell_padding_bottom = value;
// break;
// case FT_OPT_LEFT_PADDING:
// table->options->cell_padding_left = value;
// break;
// case FT_OPT_RIGHT_PADDING:
// table->options->cell_padding_right = value;
// break;
// case FT_OPT_EMPTY_STR_HEIGHT:
// table->options->cell_empty_string_height = value;
// break;
// default:
// // todo
// exit(22);
// }
// return F_SUCCESS;
}
//}

View File

@@ -226,11 +226,11 @@ fort_status_t set_default_cell_option(uint32_t option, int value)
fort_table_options_t g_table_options = {
0, /* cell_padding_top */
0, /* cell_padding_bottom */
1, /* cell_padding_left */
1, /* cell_padding_right */
1, /* cell_empty_string_height */
// 0, /* cell_padding_top */
// 0, /* cell_padding_bottom */
// 1, /* cell_padding_left */
// 1, /* cell_padding_right */
// 1, /* cell_empty_string_height */
/* border_chars */
{

View File

@@ -133,11 +133,11 @@ enum SeparatorItemPos
struct fort_table_options
{
int cell_padding_top;
int cell_padding_bottom;
int cell_padding_left;
int cell_padding_right;
int cell_empty_string_height;
// int cell_padding_top;
// int cell_padding_bottom;
// int cell_padding_left;
// int cell_padding_right;
// int cell_empty_string_height;
char border_chars[BorderItemPosSize];
char header_border_chars[BorderItemPosSize];