@@ -146,7 +146,8 @@ static void TextView_SetTaskForLineHeight( LCUI_Widget w, int height )
146
146
txt -> tasks [TASK_UPDATE ].is_valid = TRUE;
147
147
}
148
148
149
- static void TextView_SetTaskForTextStyle ( LCUI_Widget w , LCUI_TextStyle style )
149
+ static void TextView_SetTaskForTextStyle ( LCUI_Widget w ,
150
+ LCUI_TextStyle style )
150
151
{
151
152
LCUI_TextView txt = GetData ( w );
152
153
TextStyle_Copy ( & txt -> tasks [TASK_SET_TEXT_STYLE ].style , style );
@@ -196,19 +197,16 @@ static void TextView_UpdateStyle( LCUI_Widget w )
196
197
TextStyle_Destroy ( & ts );
197
198
}
198
199
199
- static void TextView_UpdateSize ( LCUI_Widget w )
200
+ static void TextView_UpdateLayerSize ( LCUI_Widget w )
200
201
{
201
- LCUI_RectF rect ;
202
202
LCUI_TextView txt ;
203
- LinkedList rects ;
204
- LinkedListNode * node ;
205
203
int width = 0 , height = 0 ;
206
204
float scale , max_width = 0 , max_height = 0 ;
207
205
208
206
txt = GetData ( w );
209
- LinkedList_Init ( & rects );
210
207
scale = LCUIMetrics_GetScale ();
211
- if ( Widget_HasFitContentWidth ( w ) ) {
208
+ if ( Widget_HasFitContentWidth ( w ) ||
209
+ Widget_HasParentDependentWidth ( w ) ) {
212
210
max_width = Widget_ComputeMaxContentWidth ( w );
213
211
} else {
214
212
max_width = w -> box .content .width ;
@@ -223,6 +221,20 @@ static void TextView_UpdateSize( LCUI_Widget w )
223
221
width = LCUIMetrics_ComputeActual ( max_width , SVT_PX );
224
222
height = LCUIMetrics_ComputeActual ( max_height , SVT_PX );
225
223
TextLayer_SetMaxSize ( txt -> layer , width , height );
224
+ }
225
+
226
+ static void TextView_OnResize ( LCUI_Widget w , LCUI_WidgetEvent e , void * arg )
227
+ {
228
+ float scale ;
229
+ LCUI_RectF rect ;
230
+ LCUI_TextView txt ;
231
+ LinkedList rects ;
232
+ LinkedListNode * node ;
233
+
234
+ txt = GetData ( w );
235
+ LinkedList_Init ( & rects );
236
+ scale = LCUIMetrics_GetScale ();
237
+ TextView_UpdateLayerSize ( w );
226
238
TextLayer_Update ( txt -> layer , & rects );
227
239
for ( LinkedList_Each ( node , & rects ) ) {
228
240
LCUIRect_ToRectF ( node -> data , & rect , 1.0f / scale );
@@ -232,11 +244,6 @@ static void TextView_UpdateSize( LCUI_Widget w )
232
244
TextLayer_ClearInvalidRect ( txt -> layer );
233
245
}
234
246
235
- static void TextView_OnResize ( LCUI_Widget w , LCUI_WidgetEvent e , void * arg )
236
- {
237
- TextView_UpdateSize ( w );
238
- }
239
-
240
247
/** 初始化 TextView 部件数据 */
241
248
static void TextView_OnInit ( LCUI_Widget w )
242
249
{
@@ -287,14 +294,22 @@ static void TextView_OnDestroy( LCUI_Widget w )
287
294
288
295
static void TextView_AutoSize ( LCUI_Widget w , float * width , float * height )
289
296
{
297
+ float max_width ;
298
+ int fixed_w , fixed_h ;
290
299
LCUI_TextView txt = GetData ( w );
291
300
float scale = LCUIMetrics_GetScale ();
301
+
302
+ TextView_UpdateLayerSize ( w );
303
+ fixed_w = txt -> layer -> fixed_width ;
304
+ fixed_h = txt -> layer -> fixed_height ;
292
305
if ( Widget_HasFitContentWidth ( w ) ||
293
306
!Widget_HasStaticWidthParent ( w ) ) {
294
- int fixed_w = txt -> layer -> fixed_width ;
295
- int fixed_h = txt -> layer -> fixed_height ;
296
307
/* 解除固定宽高设置,以计算最大宽高 */
297
308
TextLayer_SetFixedSize ( txt -> layer , (int )(* width * scale ), 0 );
309
+ if ( Widget_HasParentDependentWidth ( w ) ) {
310
+ max_width = scale * Widget_ComputeMaxContentWidth ( w );
311
+ TextLayer_SetMaxSize ( txt -> layer , (int )max_width , 0 );
312
+ }
298
313
TextLayer_Update ( txt -> layer , NULL );
299
314
if ( * width <= 0 ) {
300
315
* width = TextLayer_GetWidth ( txt -> layer ) / scale ;
@@ -379,8 +394,12 @@ static void TextView_OnTask( LCUI_Widget w )
379
394
}
380
395
i = TASK_UPDATE_SIZE ;
381
396
if ( txt -> tasks [i ].is_valid ) {
382
- TextView_UpdateSize ( w );
397
+ TextView_UpdateLayerSize ( w );
398
+ if ( Widget_HasFitContentWidth ( w ) ) {
399
+ Widget_AddTask ( w , LCUI_WTASK_RESIZE );
400
+ }
383
401
txt -> tasks [i ].is_valid = FALSE;
402
+ txt -> tasks [TASK_UPDATE ].is_valid = TRUE;
384
403
}
385
404
i = TASK_UPDATE ;
386
405
if ( !txt -> tasks [i ].is_valid ) {
@@ -396,9 +415,10 @@ static void TextView_OnTask( LCUI_Widget w )
396
415
}
397
416
RectList_Clear ( & rects );
398
417
TextLayer_ClearInvalidRect ( txt -> layer );
399
- if ( w -> style -> sheet [key_width ].type == SVT_AUTO
400
- || w -> style -> sheet [key_height ].type == SVT_AUTO ) {
401
- Widget_AddTask ( w , LCUI_WTASK_RESIZE );
418
+ if ( Widget_HasParentDependentWidth ( w ) ||
419
+ Widget_HasAutoStyle ( w , key_width ) ||
420
+ Widget_HasAutoStyle ( w , key_height ) ) {
421
+ Widget_AddTask ( w -> parent , LCUI_WTASK_RESIZE );
402
422
}
403
423
}
404
424
0 commit comments