Skip to content

Commit 0f81863

Browse files
committed
fix(renderer): incorrect widget content rectangle computation (#122,#123)
1 parent 9995b23 commit 0f81863

File tree

13 files changed

+263
-205
lines changed

13 files changed

+263
-205
lines changed

include/LCUI/draw/background.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@
3333

3434
LCUI_BEGIN_HEADER
3535

36-
/**
37-
* 绘制背景
36+
/**
37+
* 绘制背景
3838
* @param paint 绘制器的上下文句柄
3939
* @param[in] box 背景区域
4040
* @param[in] bg 背景样式参数
4141
*/
42-
LCUI_API void Graph_DrawBackground( LCUI_PaintContext paint,
43-
const LCUI_Rect *box,
44-
const LCUI_Background *bg );
42+
LCUI_API void Background_Paint( const LCUI_Background *bg,
43+
const LCUI_Rect *box,
44+
LCUI_PaintContext paint );
4545

4646
LCUI_END_HEADER
4747

include/LCUI/draw/border.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ LCUI_BEGIN_HEADER
3939
* @param[in] box 需要绘制边框的矩形框
4040
* @param[in] border 边框参数
4141
*/
42-
LCUI_API int Graph_DrawBorder( LCUI_PaintContext paint,
43-
const LCUI_Rect *box,
44-
const LCUI_Border *border );
42+
LCUI_API int Border_Paint( const LCUI_Border *border,
43+
const LCUI_Rect *box,
44+
LCUI_PaintContext paint );
4545

4646
LCUI_END_HEADER
4747

include/LCUI/draw/boxshadow.h

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,32 @@
3333

3434
#define SHADOW_WIDTH(sd) (sd->blur + sd->spread)
3535

36-
LCUI_API void Graph_ClearShadowArea( LCUI_PaintContext paint,
37-
const LCUI_Rect *box,
38-
const LCUI_BoxShadow *shadow );
36+
/* 计算Box在添加阴影后的宽度 */
37+
LCUI_API int BoxShadow_GetBoxWidth( const LCUI_BoxShadow *shadow, int w );
3938

40-
LCUI_API int Graph_DrawBoxShadow( LCUI_PaintContext paint,
41-
const LCUI_Rect *box,
42-
const LCUI_BoxShadow *shadow );
39+
/** 计算Box在添加阴影后的高度 */
40+
LCUI_API int BoxShadow_GetBoxHeight( const LCUI_BoxShadow *shadow, int h );
41+
42+
/** 计算Box在添加阴影后的宽度 */
43+
LCUI_API int BoxShadow_GetWidth( const LCUI_BoxShadow *shadow, int box_w );
44+
45+
/** 计算Box在添加阴影后的高度 */
46+
LCUI_API int BoxShadow_GetHeight( const LCUI_BoxShadow *shadow, int box_h );
47+
48+
LCUI_API int BoxShadow_GetBoxX( const LCUI_BoxShadow *shadow );
49+
50+
LCUI_API int BoxShadow_GetBoxY( const LCUI_BoxShadow *shadow );
51+
52+
LCUI_API int BoxShadow_GetY( const LCUI_BoxShadow *shadow );
53+
54+
LCUI_API int BoxShadow_GetX( const LCUI_BoxShadow *shadow );
55+
56+
LCUI_API void BoxShadow_GetCanvasRect( const LCUI_BoxShadow *shadow,
57+
const LCUI_Rect *box_rect,
58+
LCUI_Rect *canvas_rect );
59+
60+
LCUI_API int BoxShadow_Paint( const LCUI_BoxShadow *shadow,
61+
const LCUI_Rect *box,
62+
LCUI_PaintContext paint );
4363

4464
#endif

include/LCUI/gui/widget_base.h

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ typedef struct LCUI_WidgetStyle {
5858
int pointer_events; /**< 事件的处理方式 */
5959
} LCUI_WidgetStyle;
6060

61+
typedef struct LCUI_WidgetActualStyleRec_ {
62+
float x, y;
63+
LCUI_Rect canvas_box;
64+
LCUI_Rect border_box;
65+
LCUI_Rect padding_box;
66+
LCUI_Rect content_box;
67+
LCUI_Border border;
68+
LCUI_BoxShadow shadow;
69+
LCUI_Background background;
70+
} LCUI_WidgetActualStyleRec, *LCUI_WidgetActualStyle;
71+
6172
/** 部件任务类型,按照任务的依赖顺序排列 */
6273
typedef enum LCUI_WidgetTaskType {
6374
LCUI_WTASK_REFRESH_STYLE, /**< 刷新部件全部样式 */
@@ -116,7 +127,8 @@ typedef void( *LCUI_WidgetFunction )(LCUI_Widget);
116127
typedef void( *LCUI_WidgetResizer )(LCUI_Widget, float*, float*);
117128
typedef void( *LCUI_WidgetAttrSetter )(LCUI_Widget, const char*, const char*);
118129
typedef void( *LCUI_WidgetTextSetter )(LCUI_Widget, const char*);
119-
typedef void( *LCUI_WidgetPainter )(LCUI_Widget, LCUI_PaintContext);
130+
typedef void( *LCUI_WidgetPainter )(LCUI_Widget, LCUI_PaintContext,
131+
LCUI_WidgetActualStyle);
120132

121133
/** 部件原型数据结构 */
122134
typedef struct LCUI_WidgetPrototypeRec_ {
@@ -285,13 +297,21 @@ LCUI_API void Widget_DestroyBackground( LCUI_Widget w );
285297
LCUI_API void Widget_UpdateBackground( LCUI_Widget widget );
286298

287299
/** 绘制部件背景 */
288-
LCUI_API void Widget_PaintBakcground( LCUI_Widget w, LCUI_PaintContext paint );
300+
LCUI_API void Widget_PaintBakcground( LCUI_Widget w, LCUI_PaintContext paint,
301+
LCUI_WidgetActualStyle style );
302+
303+
/** 计算部件背景样式的实际值 */
304+
LCUI_API void Widget_ComputeBackground( LCUI_Widget w, LCUI_Background *out );
289305

290306
/** 更新部件边框样式 */
291307
LCUI_API void Widget_UpdateBorder( LCUI_Widget w );
292308

309+
/** 计算部件边框样式的实际值 */
310+
LCUI_API void Widget_ComputeBorder( LCUI_Widget w, LCUI_Border *out );
311+
293312
/** 绘制部件边框 */
294-
LCUI_API void Widget_PaintBorder( LCUI_Widget w, LCUI_PaintContext paint );
313+
LCUI_API void Widget_PaintBorder( LCUI_Widget w, LCUI_PaintContext paint,
314+
LCUI_WidgetActualStyle style );
295315

296316
LCUI_API float Widget_GetGraphWidth( LCUI_Widget widget );
297317

@@ -312,8 +332,12 @@ LCUI_API float Widget_GetGraphWidth( LCUI_Widget w );
312332
/** 更新部件矩形阴影样式 */
313333
LCUI_API void Widget_UpdateBoxShadow( LCUI_Widget w );
314334

335+
/** 计算部件阴影样式的实际值 */
336+
LCUI_API void Widget_ComputeBoxShadow( LCUI_Widget w, LCUI_BoxShadow *out );
337+
315338
/** 绘制部件阴影 */
316-
LCUI_API void Widget_PaintBoxShadow( LCUI_Widget w, LCUI_PaintContext paint );
339+
LCUI_API void Widget_PaintBoxShadow( LCUI_Widget w, LCUI_PaintContext paint,
340+
LCUI_WidgetActualStyle style );
317341

318342
/** 更新可见性 */
319343
LCUI_API void Widget_UpdateVisibility( LCUI_Widget w );

src/draw/background.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
#include <LCUI/LCUI.h>
3434
#include <LCUI/graph.h>
3535

36-
void Graph_DrawBackground( LCUI_PaintContext paint,
37-
const LCUI_Rect *box,
38-
const LCUI_Background *bg )
36+
void Background_Paint( const LCUI_Background *bg,
37+
const LCUI_Rect *box,
38+
LCUI_PaintContext paint )
3939
{
4040
double scale;
4141
LCUI_Graph graph, buffer;

src/draw/border.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -563,15 +563,15 @@ static int Graph_DrawRoundBorderBottomRight( LCUI_Graph *dst, LCUI_Pos center,
563563
return 0;
564564
}
565565

566-
int Graph_DrawBorder( LCUI_PaintContext paint,
567-
const LCUI_Rect *box,
568-
const LCUI_Border *border )
566+
int Border_Paint( const LCUI_Border *border,
567+
const LCUI_Rect *box,
568+
LCUI_PaintContext paint )
569569
{
570570
LCUI_Pos pos;
571571
LCUI_Graph canvas;
572572
LCUI_Rect bound, rect;
573573

574-
if( !Graph_IsValid(&paint->canvas) ) {
574+
if( !Graph_IsValid( &paint->canvas ) ) {
575575
return -1;
576576
}
577577
/* 左上角的圆角 */
@@ -655,13 +655,13 @@ int Graph_DrawBorder( LCUI_PaintContext paint,
655655
rect.y -= paint->rect.y;
656656
Graph_Quote( &canvas, &paint->canvas, &rect );
657657
Graph_DrawRoundBorderRightBottom( &canvas, pos,
658-
border->bottom_right_radius,
659-
border->right.width,
660-
border->right.color );
658+
border->bottom_right_radius,
659+
border->right.width,
660+
border->right.color );
661661
Graph_DrawRoundBorderBottomRight( &canvas, pos,
662-
border->bottom_right_radius,
663-
border->bottom.width,
664-
border->bottom.color );
662+
border->bottom_right_radius,
663+
border->bottom.width,
664+
border->bottom.color );
665665
}
666666
/* 绘制上边框线 */
667667
bound.x = box->x + border->top_left_radius;

0 commit comments

Comments
 (0)