refactor and fix warnings

This commit is contained in:
lixianjing 2021-04-30 17:52:51 +08:00
parent 820cabb227
commit 35d31e3a5a
6 changed files with 32 additions and 34 deletions

View File

@ -285,7 +285,6 @@ static row_info_t* text_edit_single_line_layout_line(text_edit_t* text_edit, uin
uint32_t caret_text_w = text_edit_measure_text(c, text->str, mask_char, state->cursor);
line_info_t* line = (line_info_t*)darray_head(&row->info);
(uint32_t) line_index;
assert(offset == 0 && row_num == 0);
memset(row, 0x00, sizeof(row_info_t) - sizeof(darray_t));
@ -995,11 +994,11 @@ uint32_t text_edit_get_height(text_edit_t* text_edit, uint32_t offset) {
}
}
return impl->line_height * (k > 1) ? k - 1 : 0;
return impl->line_height * ((k > 1) ? k - 1 : 0);
}
const uint32_t* text_edit_get_rows_line(text_edit_t* text_edit) {
uint32_t* rows_line = NULL;
const uint32_t* text_edit_get_lines_of_each_row(text_edit_t* text_edit) {
uint32_t* lines_of_each_row = NULL;
uint32_t size = 0;
DECL_IMPL(text_edit);
return_value_if_fail(text_edit != NULL && impl != NULL && impl->rows != NULL, NULL);
@ -1008,15 +1007,15 @@ const uint32_t* text_edit_get_rows_line(text_edit_t* text_edit) {
if (size) {
uint32_t i = 0;
rows_line = impl->rows->row_line;
memset(rows_line, 0x00, sizeof(uint32_t) * size);
lines_of_each_row = impl->rows->row_line;
memset(lines_of_each_row, 0x00, sizeof(uint32_t) * size);
for (i = 0; i < impl->rows->size; i++) {
rows_line[i] = impl->rows->row[i].line_num;
lines_of_each_row[i] = impl->rows->row[i].line_num;
}
}
return rows_line;
return lines_of_each_row;
}
ret_t text_edit_set_canvas(text_edit_t* text_edit, canvas_t* canvas) {

View File

@ -295,13 +295,13 @@ ret_t text_edit_set_max_chars(text_edit_t* text_edit, uint32_t max_chars);
uint32_t text_edit_get_height(text_edit_t* text_edit, uint32_t offset);
/**
* @method text_edit_get_rows_line
* row line
* @method text_edit_get_lines_of_each_row
* (row)(line)
* @param {text_edit_t*} text_edit text_edit对象
*
* @return {const uint32_t*} row line
*/
const uint32_t* text_edit_get_rows_line(text_edit_t* text_edit);
const uint32_t* text_edit_get_lines_of_each_row(text_edit_t* text_edit);
/**
* @method text_edit_set_mask

View File

@ -28,10 +28,10 @@
static uint32_t line_number_get_line_num(line_number_t* line_number, uint32_t line) {
uint32_t line_num;
if (line_number->rows_line == NULL || line >= line_number->rows_line_len) {
if (line_number->lines_of_each_row == NULL || line >= line_number->lines_of_each_row_len) {
line_num = 1;
} else {
line_num = tk_max(line_number->rows_line[line], 1);
line_num = tk_max(line_number->lines_of_each_row[line], 1);
}
return line_num;
@ -134,16 +134,16 @@ ret_t line_number_set_bottom_margin(widget_t* widget, int32_t bottom_margin) {
return widget_invalidate_force(widget, NULL);
}
ret_t line_number_set_rows_line(widget_t* widget, const uint32_t* rows_line, uint32_t len) {
ret_t line_number_set_lines_of_each_row(widget_t* widget, const uint32_t* lines_of_each_row, uint32_t len) {
line_number_t* line_number = LINE_NUMBER(widget);
return_value_if_fail(line_number != NULL && rows_line != NULL && len > 0, RET_BAD_PARAMS);
return_value_if_fail(line_number != NULL && lines_of_each_row != NULL && len > 0, RET_BAD_PARAMS);
if (line_number->rows_line == NULL || line_number->rows_line_len != len) {
line_number->rows_line = TKMEM_REALLOCT(uint32_t, line_number->rows_line, len);
return_value_if_fail(line_number->rows_line != NULL, (line_number->rows_line_len = 0, RET_OOM));
line_number->rows_line_len = len;
if (line_number->lines_of_each_row == NULL || line_number->lines_of_each_row_len != len) {
line_number->lines_of_each_row = TKMEM_REALLOCT(uint32_t, line_number->lines_of_each_row, len);
return_value_if_fail(line_number->lines_of_each_row != NULL, (line_number->lines_of_each_row_len = 0, RET_OOM));
line_number->lines_of_each_row_len = len;
}
memcpy(line_number->rows_line, rows_line, sizeof(uint32_t) * len);
memcpy(line_number->lines_of_each_row, lines_of_each_row, sizeof(uint32_t) * len);
return widget_invalidate_force(widget, NULL);
}
@ -152,9 +152,9 @@ static ret_t line_number_on_destroy(widget_t* widget) {
line_number_t* line_number = LINE_NUMBER(widget);
return_value_if_fail(line_number != NULL, RET_BAD_PARAMS);
if (line_number->rows_line != NULL) {
TKMEM_FREE(line_number->rows_line);
line_number->rows_line_len = 0;
if (line_number->lines_of_each_row != NULL) {
TKMEM_FREE(line_number->lines_of_each_row);
line_number->lines_of_each_row_len = 0;
}
return RET_OK;

View File

@ -72,8 +72,8 @@ typedef struct _line_number_t {
int32_t line_height;
int32_t top_margin;
int32_t bottom_margin;
uint32_t* rows_line;
uint32_t rows_line_len;
uint32_t* lines_of_each_row;
uint32_t lines_of_each_row_len;
} line_number_t;
/**
@ -136,15 +136,14 @@ ret_t line_number_set_yoffset(widget_t* widget, int32_t yoffset);
/**
* @method line_number_set_yoffset
*
* @annotation ["scriptable"]
* (row)(line)
* @param {widget_t*} widget
* @param {const uint32_t*} rows_line
* @param {uint32_t} len
* @param {const uint32_t*} lines_of_each_row
* @param {uint32_t} len ()
*
* @return {ret_t} RET_OK表示成功
*/
ret_t line_number_set_rows_line(widget_t* widget, const uint32_t* rows_line, uint32_t len);
ret_t line_number_set_lines_of_each_row(widget_t* widget, const uint32_t* lines_of_each_row, uint32_t len);
/**
* @method line_number_cast

View File

@ -813,9 +813,9 @@ static ret_t mledit_sync_line_number(widget_t* widget, text_edit_state_t* state)
widget_t* line_number = widget_lookup_by_type(widget, WIDGET_TYPE_LINE_NUMBER, TRUE);
return_value_if_fail(mledit != NULL, RET_BAD_PARAMS);
if (line_number != NULL) {
const uint32_t* rows_line = text_edit_get_rows_line(mledit->model);
if (rows_line != NULL) {
line_number_set_rows_line(line_number, rows_line, state->max_rows);
const uint32_t* lines_of_each_row = text_edit_get_lines_of_each_row(mledit->model);
if (lines_of_each_row != NULL) {
line_number_set_lines_of_each_row(line_number, lines_of_each_row, state->max_rows);
}
line_number_set_yoffset(line_number, state->oy);

View File

@ -140,7 +140,7 @@ TEST(TextEdit, get_rows_line) {
text_edit_set_canvas(text_edit, widget_get_canvas(w));
widget_set_prop_pointer(win, WIDGET_PROP_CANVAS, NULL);
const uint32_t* rows_line = text_edit_get_rows_line(text_edit);
const uint32_t* rows_line = text_edit_get_lines_of_each_row(text_edit);
ASSERT_EQ(rows_line[0], 1);
ASSERT_EQ(rows_line[1], 2);