diff --git a/src/base/canvas.c b/src/base/canvas.c index fb5429444..4b224a401 100644 --- a/src/base/canvas.c +++ b/src/base/canvas.c @@ -186,9 +186,9 @@ ret_t canvas_set_font(canvas_t* c, const char* name, uint16_t size) { return RET_OK; } -static wh_t canvas_measure_text_default(canvas_t* c, wchar_t* str, int32_t nr) { +static float_t canvas_measure_text_default(canvas_t* c, wchar_t* str, int32_t nr) { glyph_t g; - wh_t w = 0; + float_t w = 0; int32_t i = 0; return_value_if_fail(c != NULL && str != NULL && c->font != NULL, 0); @@ -208,7 +208,7 @@ static wh_t canvas_measure_text_default(canvas_t* c, wchar_t* str, int32_t nr) { return w; } -wh_t canvas_measure_text(canvas_t* c, wchar_t* str, int32_t nr) { +float_t canvas_measure_text(canvas_t* c, wchar_t* str, int32_t nr) { return_value_if_fail(c != NULL && c->lcd != NULL && str != NULL, 0); if (c->lcd->measure_text) { diff --git a/src/base/canvas.h b/src/base/canvas.h index a64997309..bf3ce3857 100644 --- a/src/base/canvas.h +++ b/src/base/canvas.h @@ -66,7 +66,7 @@ ret_t canvas_set_stroke_color(canvas_t* c, color_t color); ret_t canvas_set_global_alpha(canvas_t* c, uint8_t alpha); ret_t canvas_set_font(canvas_t* c, const char* name, uint16_t size); -wh_t canvas_measure_text(canvas_t* c, wchar_t* str, int32_t nr); +float_t canvas_measure_text(canvas_t* c, wchar_t* str, int32_t nr); ret_t canvas_begin_frame(canvas_t* c, rect_t* dirty_rect, lcd_draw_mode_t draw_mode); diff --git a/src/base/edit.c b/src/base/edit.c index 380b23bdf..17c7f7c9b 100644 --- a/src/base/edit.c +++ b/src/base/edit.c @@ -56,7 +56,7 @@ static ret_t edit_on_paint_self(widget_t* widget, canvas_t* c) { style_t* style = &(widget->style); wchar_t password[MAX_PASSWORD_LEN + 1]; int32_t margin = style_get_int(style, STYLE_ID_MARGIN, 4); - wh_t caret_x = margin; + float_t caret_x = margin; wchar_t invisible_char = '*'; bool_t invisible = str->size && (edit->limit.type == INPUT_PASSWORD && !(edit->password_visible)); @@ -65,7 +65,7 @@ static ret_t edit_on_paint_self(widget_t* widget, canvas_t* c) { } if (str->size > 0) { - wh_t cw = 0; + float_t cw = 0; wh_t w = widget->w - 2 * margin; color_t trans = color_init(0, 0, 0, 0); color_t tc = style_get_color(style, STYLE_ID_TEXT_COLOR, trans); @@ -114,7 +114,7 @@ static ret_t edit_on_paint_self(widget_t* widget, canvas_t* c) { canvas_set_stroke_color(c, color_init(0, 0, 0, 0xff)); canvas_draw_vline(c, caret_x, margin, widget->h - 2 * margin); } - edit->caret_x = caret_x; + edit->caret_x = caret_x + 0.5; return RET_OK; } @@ -233,7 +233,7 @@ static ret_t edit_on_key_down(widget_t* widget, key_event_t* e) { } else if (key == FKEY_DELETE) { return edit_delete_next_char(widget); } else { - if(isprint(key)) { + if (isprint(key)) { return edit_input_char(widget, (wchar_t)key); } else { return RET_OK; diff --git a/src/base/lcd.c b/src/base/lcd.c index ce0e69134..afddaa197 100644 --- a/src/base/lcd.c +++ b/src/base/lcd.c @@ -164,8 +164,8 @@ ret_t lcd_draw_glyph(lcd_t* lcd, glyph_t* glyph, rect_t* src, xy_t x, xy_t y) { return lcd->draw_glyph(lcd, glyph, src, x, y); } -wh_t lcd_measure_text(lcd_t* lcd, wchar_t* str, int32_t nr) { - return_value_if_fail(lcd != NULL && lcd->measure_text != NULL && str != NULL, 0); +float lcd_measure_text(lcd_t* lcd, wchar_t* str, int32_t nr) { + return_value_if_fail(lcd != NULL && lcd->measure_text != NULL && str != NULL, 0.0f); return lcd->measure_text(lcd, str, nr); } diff --git a/src/base/lcd.h b/src/base/lcd.h index 74692afc0..f9bb8b072 100644 --- a/src/base/lcd.h +++ b/src/base/lcd.h @@ -51,7 +51,7 @@ typedef ret_t (*lcd_fill_rect_t)(lcd_t* lcd, xy_t x, xy_t y, wh_t w, wh_t h); typedef ret_t (*lcd_stroke_rect_t)(lcd_t* lcd, xy_t x, xy_t y, wh_t w, wh_t h); typedef ret_t (*lcd_draw_glyph_t)(lcd_t* lcd, glyph_t* glyph, rect_t* src, xy_t x, xy_t y); -typedef wh_t (*lcd_measure_text_t)(lcd_t* lcd, wchar_t* str, int32_t nr); +typedef float (*lcd_measure_text_t)(lcd_t* lcd, wchar_t* str, int32_t nr); typedef ret_t (*lcd_draw_text_t)(lcd_t* lcd, wchar_t* str, int32_t nr, xy_t x, xy_t y); typedef ret_t (*lcd_draw_image_t)(lcd_t* lcd, bitmap_t* img, rect_t* src, rect_t* dst); @@ -403,9 +403,9 @@ ret_t lcd_draw_glyph(lcd_t* lcd, glyph_t* glyph, rect_t* src, xy_t x, xy_t y); * @param {wchar_t*} str 字符串。 * @param {int32_t} nr 字符数。 * - * @return {ret_t} 返回字符串占用的宽度。 + * @return {float_t} 返回字符串占用的宽度。 */ -wh_t lcd_measure_text(lcd_t* lcd, wchar_t* str, int32_t nr); +float_t lcd_measure_text(lcd_t* lcd, wchar_t* str, int32_t nr); /** * @method lcd_draw_text diff --git a/src/base/vgcanvas.c b/src/base/vgcanvas.c index df6a2eef8..452a555e9 100644 --- a/src/base/vgcanvas.c +++ b/src/base/vgcanvas.c @@ -214,7 +214,7 @@ ret_t vgcanvas_fill_text(vgcanvas_t* vg, const char* text, float_t x, float_t y, return vg->vt->fill_text(vg, text, x, y, max_width); } -uint32_t vgcanvas_measure_text(vgcanvas_t* vg, const char* text) { +float_t vgcanvas_measure_text(vgcanvas_t* vg, const char* text) { return_value_if_fail(vg != NULL && vg->vt->measure_text != NULL && text != NULL, RET_BAD_PARAMS); return vg->vt->measure_text(vg, text); diff --git a/src/base/vgcanvas.h b/src/base/vgcanvas.h index c3d5e9244..b8ee15f1f 100644 --- a/src/base/vgcanvas.h +++ b/src/base/vgcanvas.h @@ -81,7 +81,7 @@ typedef ret_t (*vgcanvas_set_text_align_t)(vgcanvas_t* vg, const char* value); typedef ret_t (*vgcanvas_set_text_baseline_t)(vgcanvas_t* vg, const char* value); typedef ret_t (*vgcanvas_fill_text_t)(vgcanvas_t* vg, const char* text, float_t x, float_t y, float_t max_width); -typedef uint32_t (*vgcanvas_measure_text_t)(vgcanvas_t* vg, const char* text); +typedef float_t (*vgcanvas_measure_text_t)(vgcanvas_t* vg, const char* text); typedef ret_t (*vgcanvas_draw_image_t)(vgcanvas_t* vg, bitmap_t* img, float_t sx, float_t sy, float_t sw, float_t sh, float_t dx, float_t dy, float_t dw, float_t dh); @@ -635,9 +635,9 @@ ret_t vgcanvas_fill_text(vgcanvas_t* vg, const char* text, float_t x, float_t y, * @param {vgcanvas_t*} vg vgcanvas对象。 * @param {char*} text text * - * @return {uint32_t} 返回text的宽度。 + * @return {float_t} 返回text的宽度。 */ -uint32_t vgcanvas_measure_text(vgcanvas_t* vg, const char* text); +float_t vgcanvas_measure_text(vgcanvas_t* vg, const char* text); /** * @method vgcanvas_draw_image diff --git a/src/lcd/lcd_vgcanvas.inc b/src/lcd/lcd_vgcanvas.inc index ecbac5087..021c8c3d0 100644 --- a/src/lcd/lcd_vgcanvas.inc +++ b/src/lcd/lcd_vgcanvas.inc @@ -134,7 +134,7 @@ static ret_t lcd_vgcanvas_draw_image(lcd_t* lcd, bitmap_t* img, rect_t* src, rec } #define MAX_CHARS 256 -wh_t lcd_vgcanvas_measure_text(lcd_t* lcd, wchar_t* str, int32_t nr) { +float_t lcd_vgcanvas_measure_text(lcd_t* lcd, wchar_t* str, int32_t nr) { wchar_t temp[MAX_CHARS + 1]; char text[2 * MAX_CHARS + 1]; vgcanvas_t* canvas = LCD(lcd)->canvas; diff --git a/src/vgcanvas/vgcanvas_agg.cpp b/src/vgcanvas/vgcanvas_agg.cpp index 34f6dbe07..a59849f89 100644 --- a/src/vgcanvas/vgcanvas_agg.cpp +++ b/src/vgcanvas/vgcanvas_agg.cpp @@ -262,11 +262,11 @@ static ret_t vgcanvas_agg_fill_text(vgcanvas_t* vg, const char* text, float_t x, return RET_OK; } -static uint32_t vgcanvas_agg_measure_text(vgcanvas_t* vg, const char* text) { +static float_t vgcanvas_agg_measure_text(vgcanvas_t* vg, const char* text) { vgcanvas_agg_t* agg = (vgcanvas_agg_t*)vg; return_value_if_fail(agg->canvas != NULL, RET_BAD_PARAMS); /*TODO*/ - return 0; + return 0.0f; } static ret_t vgcanvas_agg_draw_image(vgcanvas_t* vg, bitmap_t* img, float_t sx, float_t sy, diff --git a/src/vgcanvas/vgcanvas_nanovg.c b/src/vgcanvas/vgcanvas_nanovg.c index 09ab7eabd..de166e7a6 100644 --- a/src/vgcanvas/vgcanvas_nanovg.c +++ b/src/vgcanvas/vgcanvas_nanovg.c @@ -360,7 +360,7 @@ static ret_t vgcanvas_nanovg_fill_text(vgcanvas_t* vgcanvas, const char* text, f return RET_OK; } -static uint32_t vgcanvas_nanovg_measure_text(vgcanvas_t* vgcanvas, const char* text) { +static float_t vgcanvas_nanovg_measure_text(vgcanvas_t* vgcanvas, const char* text) { float bounds[4]; vgcanvas_nanovg_t* canvas = (vgcanvas_nanovg_t*)vgcanvas; NVGcontext* vg = ((vgcanvas_nanovg_t*)vgcanvas)->vg; diff --git a/src/vgcanvas/vgcanvas_picasso.cpp b/src/vgcanvas/vgcanvas_picasso.cpp index cbe943114..7e41cab6b 100644 --- a/src/vgcanvas/vgcanvas_picasso.cpp +++ b/src/vgcanvas/vgcanvas_picasso.cpp @@ -452,7 +452,7 @@ static ret_t vgcanvas_picasso_fill_text(vgcanvas_t* vgcanvas, const char* text, return RET_OK; } -static uint32_t vgcanvas_picasso_measure_text(vgcanvas_t* vgcanvas, const char* text) { +static float_t vgcanvas_picasso_measure_text(vgcanvas_t* vgcanvas, const char* text) { ps_size size = {0, 0}; ps_context* vg = ((vgcanvas_picasso_t*)vgcanvas)->vg;