[C] Refactoring
This commit is contained in:
parent
5eee2ec56c
commit
d21052db06
@ -272,6 +272,8 @@ FORT_EXTERN int ft_set_table_borders(FTABLE * FORT_RESTRICT table, struct border
|
||||
FORT_EXTERN int ft_set_default_option(uint32_t option, int value);
|
||||
FORT_EXTERN int ft_set_table_option(FTABLE * FORT_RESTRICT table, uint32_t option, int value);
|
||||
|
||||
FORT_EXTERN int ft_set_cell_option(FTABLE * FORT_RESTRICT table, unsigned row, unsigned col, uint32_t option, int value);
|
||||
|
||||
|
||||
FORT_END_DECLS
|
||||
|
||||
|
18
src/fort.c
18
src/fort.c
@ -754,3 +754,21 @@ int ft_set_table_option(FTABLE *table, uint32_t option, int value)
|
||||
}
|
||||
|
||||
|
||||
|
||||
int ft_set_cell_option(FTABLE *table, unsigned row, unsigned col, uint32_t option, int value)
|
||||
{
|
||||
assert(table);
|
||||
|
||||
if (table->options == NULL) {
|
||||
table->options = create_table_options();
|
||||
if (table->options == NULL)
|
||||
return F_MEMORY_ERROR;
|
||||
}
|
||||
if (table->options->cell_options == NULL) {
|
||||
table->options->cell_options = create_cell_opt_container();
|
||||
if (table->options->cell_options == NULL) {
|
||||
return F_ERROR;
|
||||
}
|
||||
}
|
||||
return set_cell_option(table->options->cell_options, row, col, option, value);
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ fort_table_options_t g_table_options = {
|
||||
'+', '=', '+', '+',
|
||||
},
|
||||
|
||||
NULL, /* col_options */
|
||||
// NULL, /* col_options */
|
||||
NULL, /* cell_options */
|
||||
};
|
||||
|
||||
@ -194,16 +194,16 @@ void destroy_table_options(fort_table_options_t* options)
|
||||
if (options == NULL)
|
||||
return;
|
||||
|
||||
if (options->col_options != NULL) {
|
||||
destroy_vector(options->col_options);
|
||||
}
|
||||
// if (options->col_options != NULL) {
|
||||
// destroy_vector(options->col_options);
|
||||
// }
|
||||
if (options->cell_options != NULL) {
|
||||
destroy_cell_opt_container(options->cell_options);
|
||||
}
|
||||
F_FREE(options);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
#define FORT_OPTIONS_SET_COLUMN_OPTION(options, column, opt_name, opt_value) \
|
||||
assert(options);\
|
||||
\
|
||||
@ -221,17 +221,17 @@ void destroy_table_options(fort_table_options_t* options)
|
||||
fort_column_options_t *col_option = (fort_column_options_t*)vector_at(options->col_options, column);\
|
||||
col_option->opt_name = opt_value;\
|
||||
\
|
||||
return F_SUCCESS;
|
||||
return F_SUCCESS;*/
|
||||
|
||||
fort_status_t fort_options_set_column_min_width(fort_table_options_t *options, size_t column, size_t width)
|
||||
{
|
||||
FORT_OPTIONS_SET_COLUMN_OPTION(options, column, col_min_width, width);
|
||||
}
|
||||
//fort_status_t fort_options_set_column_min_width(fort_table_options_t *options, size_t column, size_t width)
|
||||
//{
|
||||
// FORT_OPTIONS_SET_COLUMN_OPTION(options, column, col_min_width, width);
|
||||
//}
|
||||
|
||||
fort_status_t fort_options_set_column_alignment(fort_table_options_t *options, size_t column, enum TextAlignment al)
|
||||
{
|
||||
FORT_OPTIONS_SET_COLUMN_OPTION(options, column, align, al);
|
||||
}
|
||||
//fort_status_t fort_options_set_column_alignment(fort_table_options_t *options, size_t column, enum TextAlignment al)
|
||||
//{
|
||||
// FORT_OPTIONS_SET_COLUMN_OPTION(options, column, align, al);
|
||||
//}
|
||||
|
||||
//int fort_options_column_width(const fort_table_options_t *options, size_t column)
|
||||
//{
|
||||
|
@ -133,7 +133,7 @@ struct fort_table_options
|
||||
char border_chars[BorderItemPosSize];
|
||||
char header_border_chars[BorderItemPosSize];
|
||||
char separator_chars[SepratorItemPosSize];
|
||||
vector_t *col_options;
|
||||
// vector_t *col_options;
|
||||
|
||||
fort_cell_opt_container_t * cell_options;
|
||||
};
|
||||
@ -146,8 +146,8 @@ extern fort_table_options_t g_table_options;
|
||||
fort_table_options_t* create_table_options();
|
||||
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);
|
||||
//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_alignment(const fort_table_options_t *options, size_t column);
|
||||
|
||||
|
@ -817,10 +817,15 @@ void test_table_options(void **state)
|
||||
|
||||
table = create_test_int_table(0);
|
||||
int status = F_SUCCESS;
|
||||
status |= ft_set_column_min_width(table, 1, 7);
|
||||
status |= ft_set_column_alignment(table, 1, LeftAligned);
|
||||
status |= ft_set_column_min_width(table, 2, 8);
|
||||
status |= ft_set_column_alignment(table, 2, CenterAligned);
|
||||
// status |= ft_set_column_min_width(table, 1, 7);
|
||||
// status |= ft_set_column_alignment(table, 1, LeftAligned);
|
||||
// status |= ft_set_column_min_width(table, 2, 8);
|
||||
// status |= ft_set_column_alignment(table, 2, CenterAligned);
|
||||
|
||||
status |= ft_set_cell_option(table, FT_ANY_ROW, 1, FT_OPT_MIN_WIDTH, 7);
|
||||
status |= ft_set_cell_option(table, FT_ANY_ROW, 1, FT_OPT_TEXT_ALIGN, LeftAligned);
|
||||
status |= ft_set_cell_option(table, FT_ANY_ROW, 2, FT_OPT_MIN_WIDTH, 8);
|
||||
status |= ft_set_cell_option(table, FT_ANY_ROW, 2, FT_OPT_TEXT_ALIGN, CenterAligned);
|
||||
assert_true( status == F_SUCCESS);
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user