Skip to content

Commit e405005

Browse files
committed
TextBox: 解决在增删文本行时文本区域的更新问题
1 parent 43cf0c8 commit e405005

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/widget/LCUI_TextBox.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,9 @@ TextBox_Scroll_TextLayer( ScrollBar_Data data, void *arg )
198198
LCUI_Pos pos;
199199

200200
pos.x = 0;
201-
pos.y = data.max_size - data.current_size;
202-
pos.y = pos.y * data.current_num * 1.0 / data.max_num;
201+
pos.y = data.current_num;
203202
pos.y = 0 - pos.y;
204-
printf("%d\n", pos.y);
203+
printf("offset.y: %d\n", pos.y);
205204
TextBox_TextLayer_Set_Offset( widget, pos );
206205
Update_Widget( widget );
207206
}
@@ -315,9 +314,11 @@ static void
315314
Exec_TextBox_Update( LCUI_Widget *widget )
316315
/* 更新文本框的文本图层 */
317316
{
317+
printf("Exec_TextBox_Update(): enter\n");
318318
Exec_Update_Widget( TextBox_Get_Label( widget ) );
319319
TextBox_ScrollBar_Update( widget );
320320
TextBox_Cursor_Update( widget );
321+
printf("Exec_TextBox_Update(): quit\n");
321322
}
322323

323324
static void
@@ -419,7 +420,9 @@ TextBox_ViewArea_Update( LCUI_Widget *widget )
419420
area_pos.y = cursor_pos.y;
420421
}
421422
if(cursor_pos.y + cursor_h > area_pos.y + area_size.h ) {
423+
printf("outrange\n");
422424
area_pos.y = cursor_pos.y + cursor_h - area_size.h;
425+
printf("area_pos.y: %d\n", area_pos.y);
423426
}
424427
/* 如果显示区域在Y轴上超过文本图层的范围 */
425428
if( area_pos.y + area_size.h > layer_size.h ) {
@@ -432,9 +435,12 @@ TextBox_ViewArea_Update( LCUI_Widget *widget )
432435
ScrollBar_Set_CurrentNum( scrollbar, area_pos.y );
433436
/* 获取滚动条的数据,供滚动文本层利用 */
434437
scrollbar_data = ScrollBar_Get_Data( scrollbar );
438+
439+
printf("scrollbar_data: size: %d / %d, num: %d / %d\n",
440+
scrollbar_data.current_size, scrollbar_data.max_size,
441+
scrollbar_data.current_num, scrollbar_data.max_num);
435442
/* 根据数据,滚动文本图层至响应的位置,也就是移动文本显示区域 */
436443
TextBox_Scroll_TextLayer( scrollbar_data, widget );
437-
Update_Widget( widget );
438444
printf("TextBox_ViewArea_Update(): quit\n");
439445
return 0;
440446
}
@@ -484,6 +490,7 @@ void TextBox_Text_Add(LCUI_Widget *widget, char *new_text)
484490

485491
layer = TextBox_Get_TextLayer( widget );
486492
TextLayer_Text_Add( layer, new_text );
493+
Update_Widget( widget );
487494
TextBox_ViewArea_Update( widget );
488495
}
489496

0 commit comments

Comments
 (0)