show tips if edit is empty even in focus status

This commit is contained in:
xianjimli 2019-05-07 09:39:19 +08:00
parent c42f4553c6
commit 23445d1436
7 changed files with 102 additions and 58 deletions

View File

@ -3,7 +3,7 @@ TK_CONST_DATA_ALIGN(const unsigned char image_pointer[]) = {
0x62,0x73,0x76,0x67,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x15,0x11,0x18,0x20,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x04,0x00,0x00,0x20,0x00,0x00,0x00,
0x20,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x20,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x22,0x22,0x52,0x44,0xef,0xee,0xce,0x43,0x03,0x00,0x00,0x00,
0xbc,0xbb,0xfb,0x43,0xab,0xaa,0x2a,0x42,0x03,0x00,0x00,0x00,0x66,0x66,0x26,0x43,0xef,0xee,0xce,0x43,
0x09,0x00,0x00,0x00,0x89,0x88,0x08,0x43,0xef,0xee,0xde,0x43,0x55,0x55,0x15,0x43,0xbc,0xbb,0xeb,0x43,

View File

@ -1,5 +1,5 @@
TK_CONST_DATA_ALIGN(const unsigned char ui_soft_keyboard[]) = {
0x04,0x00,0x01,0x01,0x98,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x73,0x6f,0x66,0x74,0x5f,0x6b,0x65,0x79,
0x04,0x00,0x01,0x01,0xa4,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x73,0x6f,0x66,0x74,0x5f,0x6b,0x65,0x79,
0x62,0x6f,0x61,0x72,0x64,0x00,0x64,0x61,0x74,0x61,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x12,0x12,0x22,0x11,0x77,0x69,0x6e,0x64,0x6f,0x77,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
@ -12,52 +12,52 @@ TK_CONST_DATA_ALIGN(const unsigned char ui_soft_keyboard[]) = {
0x6f,0x75,0x74,0x00,0x64,0x65,0x66,0x61,0x75,0x6c,0x74,0x28,0x78,0x3d,0x63,0x2c,0x79,0x3d,0x31,0x30,
0x2c,0x77,0x3d,0x39,0x30,0x25,0x2c,0x68,0x3d,0x33,0x30,0x29,0x00,0x69,0x6e,0x70,0x75,0x74,0x5f,0x74,
0x79,0x70,0x65,0x00,0x63,0x75,0x73,0x74,0x6f,0x6d,0x00,0x66,0x6f,0x63,0x75,0x73,0x00,0x74,0x72,0x75,
0x65,0x00,0x74,0x65,0x78,0x74,0x00,0x00,0x00,0x00,0x76,0x69,0x65,0x77,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00,0x5a,0x00,0x00,0x00,0xc4,0xff,0xff,0xff,0x73,0x65,
0x6c,0x66,0x5f,0x6c,0x61,0x79,0x6f,0x75,0x74,0x00,0x64,0x65,0x66,0x61,0x75,0x6c,0x74,0x28,0x78,0x3d,
0x63,0x2c,0x79,0x3d,0x36,0x30,0x2c,0x77,0x3d,0x39,0x30,0x25,0x2c,0x68,0x3d,0x2d,0x36,0x30,0x29,0x00,
0x69,0x73,0x5f,0x6b,0x65,0x79,0x62,0x6f,0x61,0x72,0x64,0x00,0x74,0x72,0x75,0x65,0x00,0x63,0x68,0x69,
0x6c,0x64,0x72,0x65,0x6e,0x5f,0x6c,0x61,0x79,0x6f,0x75,0x74,0x00,0x64,0x65,0x66,0x61,0x75,0x6c,0x74,
0x28,0x72,0x3d,0x34,0x2c,0x63,0x3d,0x34,0x2c,0x6d,0x3d,0x35,0x2c,0x73,0x3d,0x35,0x29,0x00,0x00,0x62,
0x75,0x74,0x74,0x6f,0x6e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x6e,0x61,0x6d,0x65,0x00,0x6b,0x65,0x79,0x00,0x74,0x65,0x78,0x74,
0x00,0x30,0x00,0x00,0x00,0x62,0x75,0x74,0x74,0x6f,0x6e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x6e,0x61,0x6d,0x65,0x00,0x6b,0x65,
0x79,0x00,0x74,0x65,0x78,0x74,0x00,0x31,0x00,0x00,0x00,0x62,0x75,0x74,0x74,0x6f,0x6e,0x00,0x00,0x00,
0x65,0x00,0x74,0x65,0x78,0x74,0x00,0x00,0x74,0x69,0x70,0x73,0x00,0x63,0x75,0x73,0x74,0x6f,0x6d,0x00,
0x00,0x00,0x76,0x69,0x65,0x77,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,
0x00,0x00,0x5a,0x00,0x00,0x00,0xc4,0xff,0xff,0xff,0x73,0x65,0x6c,0x66,0x5f,0x6c,0x61,0x79,0x6f,0x75,
0x74,0x00,0x64,0x65,0x66,0x61,0x75,0x6c,0x74,0x28,0x78,0x3d,0x63,0x2c,0x79,0x3d,0x36,0x30,0x2c,0x77,
0x3d,0x39,0x30,0x25,0x2c,0x68,0x3d,0x2d,0x36,0x30,0x29,0x00,0x69,0x73,0x5f,0x6b,0x65,0x79,0x62,0x6f,
0x61,0x72,0x64,0x00,0x74,0x72,0x75,0x65,0x00,0x63,0x68,0x69,0x6c,0x64,0x72,0x65,0x6e,0x5f,0x6c,0x61,
0x79,0x6f,0x75,0x74,0x00,0x64,0x65,0x66,0x61,0x75,0x6c,0x74,0x28,0x72,0x3d,0x34,0x2c,0x63,0x3d,0x34,
0x2c,0x6d,0x3d,0x35,0x2c,0x73,0x3d,0x35,0x29,0x00,0x00,0x62,0x75,0x74,0x74,0x6f,0x6e,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x6e,
0x61,0x6d,0x65,0x00,0x6b,0x65,0x79,0x00,0x74,0x65,0x78,0x74,0x00,0x32,0x00,0x00,0x00,0x62,0x75,0x74,
0x61,0x6d,0x65,0x00,0x6b,0x65,0x79,0x00,0x74,0x65,0x78,0x74,0x00,0x30,0x00,0x00,0x00,0x62,0x75,0x74,
0x74,0x6f,0x6e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x6e,0x61,0x6d,0x65,0x00,0x6b,0x65,0x79,0x00,0x74,0x65,0x78,0x74,0x00,0x33,
0x00,0x00,0x00,0x00,0x00,0x6e,0x61,0x6d,0x65,0x00,0x6b,0x65,0x79,0x00,0x74,0x65,0x78,0x74,0x00,0x31,
0x00,0x00,0x00,0x62,0x75,0x74,0x74,0x6f,0x6e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x6e,0x61,0x6d,0x65,0x00,0x6b,0x65,0x79,0x00,
0x74,0x65,0x78,0x74,0x00,0x34,0x00,0x00,0x00,0x62,0x75,0x74,0x74,0x6f,0x6e,0x00,0x00,0x00,0x00,0x00,
0x74,0x65,0x78,0x74,0x00,0x32,0x00,0x00,0x00,0x62,0x75,0x74,0x74,0x6f,0x6e,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x6e,0x61,0x6d,
0x65,0x00,0x6b,0x65,0x79,0x00,0x74,0x65,0x78,0x74,0x00,0x35,0x00,0x00,0x00,0x62,0x75,0x74,0x74,0x6f,
0x65,0x00,0x6b,0x65,0x79,0x00,0x74,0x65,0x78,0x74,0x00,0x33,0x00,0x00,0x00,0x62,0x75,0x74,0x74,0x6f,
0x6e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x6e,0x61,0x6d,0x65,0x00,0x6b,0x65,0x79,0x00,0x74,0x65,0x78,0x74,0x00,0x36,0x00,0x00,
0x00,0x00,0x00,0x6e,0x61,0x6d,0x65,0x00,0x6b,0x65,0x79,0x00,0x74,0x65,0x78,0x74,0x00,0x34,0x00,0x00,
0x00,0x62,0x75,0x74,0x74,0x6f,0x6e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x6e,0x61,0x6d,0x65,0x00,0x6b,0x65,0x79,0x00,0x74,0x65,
0x78,0x74,0x00,0x37,0x00,0x00,0x00,0x62,0x75,0x74,0x74,0x6f,0x6e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x78,0x74,0x00,0x35,0x00,0x00,0x00,0x62,0x75,0x74,0x74,0x6f,0x6e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x6e,0x61,0x6d,0x65,0x00,
0x6b,0x65,0x79,0x00,0x74,0x65,0x78,0x74,0x00,0x38,0x00,0x00,0x00,0x62,0x75,0x74,0x74,0x6f,0x6e,0x00,
0x6b,0x65,0x79,0x00,0x74,0x65,0x78,0x74,0x00,0x36,0x00,0x00,0x00,0x62,0x75,0x74,0x74,0x6f,0x6e,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x6e,0x61,0x6d,0x65,0x00,0x6b,0x65,0x79,0x00,0x74,0x65,0x78,0x74,0x00,0x39,0x00,0x00,0x00,0x62,
0x00,0x6e,0x61,0x6d,0x65,0x00,0x6b,0x65,0x79,0x00,0x74,0x65,0x78,0x74,0x00,0x37,0x00,0x00,0x00,0x62,
0x75,0x74,0x74,0x6f,0x6e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x6e,0x61,0x6d,0x65,0x00,0x6b,0x65,0x79,0x00,0x74,0x65,0x78,0x74,
0x00,0x23,0x00,0x00,0x00,0x62,0x75,0x74,0x74,0x6f,0x6e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x38,0x00,0x00,0x00,0x62,0x75,0x74,0x74,0x6f,0x6e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x6e,0x61,0x6d,0x65,0x00,0x62,0x61,
0x63,0x6b,0x73,0x70,0x61,0x63,0x65,0x00,0x74,0x65,0x78,0x74,0x00,0x3c,0x3d,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,};/*1224*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x6e,0x61,0x6d,0x65,0x00,0x6b,0x65,
0x79,0x00,0x74,0x65,0x78,0x74,0x00,0x39,0x00,0x00,0x00,0x62,0x75,0x74,0x74,0x6f,0x6e,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x6e,
0x61,0x6d,0x65,0x00,0x6b,0x65,0x79,0x00,0x74,0x65,0x78,0x74,0x00,0x23,0x00,0x00,0x00,0x62,0x75,0x74,
0x74,0x6f,0x6e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x6e,0x61,0x6d,0x65,0x00,0x62,0x61,0x63,0x6b,0x73,0x70,0x61,0x63,0x65,0x00,
0x74,0x65,0x78,0x74,0x00,0x3c,0x3d,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};/*1236*/

View File

@ -1,6 +1,6 @@
<window text="Custom Soft Keyboard" anim_hint="htranslate" >
<edit x="c" y="10" w="90%" h="30" focus="true" input_type="custom" text="" />
<edit x="c" y="10" w="90%" h="30" focus="true" input_type="custom" text="" tips="custom"/>
<view y="60" x="c" w="90%" h="-60" is_keyboard="true"
children_layout="default(r=4,c=4,m=5,s=5)" >

View File

@ -1,4 +1,7 @@
# 最新动态
* 2019/05/07
* edit在焦点状态时如果文本为空仍然显示tips。
* 2019/05/06
* rename thread\_t to tk\_thread\_t。
* 软键盘支持delete键。

View File

@ -71,7 +71,7 @@ static ret_t edit_get_display_text(widget_t* widget, canvas_t* c, wstr_t* text,
wstr_t* str = &(widget->text);
bool_t invisible = str->size && (edit->limit.type == INPUT_PASSWORD && !(edit->password_visible));
if (!str->size && !widget->focused) {
if (!str->size) {
if (edit->tips != NULL) {
utf8_to_utf16(edit->tips, temp_str, TEMP_STR_LEN);
}
@ -99,6 +99,65 @@ static ret_t edit_get_display_text(widget_t* widget, canvas_t* c, wstr_t* text,
return RET_OK;
}
static ret_t edit_calc_offset_x(widget_t* widget, rect_t* r, int32_t text_align_h, int32_t pos_w,
int32_t text_w) {
edit_t* edit = EDIT(widget);
return_value_if_fail(edit != NULL && r != NULL, RET_BAD_PARAMS);
if (text_w <= r->w) {
switch (text_align_h) {
case ALIGN_H_LEFT:
edit->offset_x = r->x;
break;
case ALIGN_H_RIGHT:
edit->offset_x = r->x + (r->w - text_w);
break;
default:
edit->offset_x = r->x + ((r->w - text_w) >> 1);
break;
}
} else {
if (edit->caret_x < r->x) {
edit->offset_x += r->x - edit->caret_x;
} else if (edit->caret_x > r->x + r->w - 1) {
edit->offset_x -= edit->caret_x - r->x - r->w + 1;
}
}
return RET_OK;
}
static ret_t edit_calc_caret_x(widget_t* widget, rect_t* r, int32_t text_align_h, int32_t pos_w,
int32_t text_w) {
edit_t* edit = EDIT(widget);
return_value_if_fail(edit != NULL && r != NULL, RET_BAD_PARAMS);
if (text_w == 0) {
switch (text_align_h) {
case ALIGN_H_LEFT:
edit->caret_x = r->x;
break;
case ALIGN_H_RIGHT:
edit->caret_x = r->x + r->w;
break;
default:
edit->caret_x = r->x + ((r->w) >> 1);
break;
}
} else if (text_w <= r->w) {
edit->caret_x = edit->offset_x + pos_w;
} else {
edit->caret_x = edit->offset_x + pos_w;
if (edit->caret_x < r->x) {
edit->caret_x = r->x;
} else if (edit->caret_x > r->x + r->w - 1) {
edit->caret_x = r->x + r->w - 1;
}
}
return RET_OK;
}
static ret_t edit_draw_text(widget_t* widget, canvas_t* c, wstr_t* text, rect_t* r) {
xy_t y = 0;
int32_t min_p = 0;
@ -139,30 +198,8 @@ static ret_t edit_draw_text(widget_t* widget, canvas_t* c, wstr_t* text, rect_t*
break;
}
if (text_w <= r->w) {
switch (c->text_align_h) {
case ALIGN_H_LEFT:
edit->offset_x = r->x;
break;
case ALIGN_H_RIGHT:
edit->offset_x = r->x + (r->w - text_w);
break;
default:
edit->offset_x = r->x + ((r->w - text_w) >> 1);
break;
}
edit->caret_x = edit->offset_x + pos_w;
} else {
edit->caret_x = edit->offset_x + pos_w;
if (edit->caret_x < r->x) {
edit->offset_x += r->x - edit->caret_x;
edit->caret_x = r->x;
} else if (edit->caret_x > r->x + r->w - 1) {
edit->offset_x -= edit->caret_x - r->x - r->w + 1;
edit->caret_x = r->x + r->w - 1;
}
}
edit_calc_offset_x(widget, r, c->text_align_h, pos_w, text_w);
edit_calc_caret_x(widget, r, c->text_align_h, pos_w, widget->text.size ? text_w : 0);
{
rect_t save_r;
@ -655,10 +692,10 @@ static ret_t edit_auto_fix(widget_t* widget) {
}
static ret_t edit_update_status(widget_t* widget) {
if (widget->focused) {
widget_set_state(widget, WIDGET_STATE_FOCUSED);
} else if (widget->text.size == 0) {
if (widget->text.size == 0) {
widget_set_state(widget, WIDGET_STATE_EMPTY);
} else if (widget->focused) {
widget_set_state(widget, WIDGET_STATE_FOCUSED);
} else {
widget_set_state(widget, WIDGET_STATE_NORMAL);
}
@ -809,6 +846,10 @@ ret_t edit_on_event(widget_t* widget, event_t* e) {
}
break;
}
case EVT_VALUE_CHANGING: {
edit_update_status(widget);
break;
}
default:
break;
}