fix caret position

This commit is contained in:
xianjimli 2018-06-22 06:35:17 +08:00
parent d188a9193b
commit 0b39fa08c4
11 changed files with 22 additions and 22 deletions

View File

@ -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) {

View File

@ -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);

View File

@ -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;

View File

@ -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);
}

View File

@ -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

View File

@ -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);

View File

@ -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

View File

@ -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;

View File

@ -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,

View File

@ -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;

View File

@ -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;