Skip to content

Commit 2fa6cf3

Browse files
committed
feat(util): add return value for LCUIRect_ValidateArea()
1 parent 23090eb commit 2fa6cf3

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

include/LCUI/util/rect.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ LCUI_API void LCUIRect_GetCutArea(int box_w, int box_h,
4545
&& Y < (rect)->y + (rect)->height)
4646

4747
/** 将矩形区域范围调整在容器有效范围内 */
48-
LCUI_API void LCUIRect_ValidateArea(LCUI_Rect *rect, int box_w, int box_h);
48+
LCUI_API LCUI_BOOL LCUIRect_ValidateArea(LCUI_Rect *rect, int box_w, int box_h);
4949

50-
LCUI_API void LCUIRectF_ValidateArea(LCUI_RectF *rect, float box_w, float box_h);
50+
LCUI_API LCUI_BOOL LCUIRectF_ValidateArea(LCUI_RectF *rect, float box_w, float box_h);
5151

5252
LCUI_API void LCUIRect_ToRectF(const LCUI_Rect *rect,
5353
LCUI_RectF *rectf, float scale);

src/util/rect.c

+16-2
Original file line numberDiff line numberDiff line change
@@ -101,58 +101,72 @@ void LCUIRect_GetCutArea(int box_w, int box_h,
101101
}
102102

103103
/* FIXME: need new shorter name */
104-
void LCUIRect_ValidateArea(LCUI_Rect *rect, int box_w, int box_h)
104+
LCUI_BOOL LCUIRect_ValidateArea(LCUI_Rect *rect, int box_w, int box_h)
105105
{
106+
LCUI_BOOL overflow = FALSE;
107+
106108
if (rect->x < 0) {
109+
overflow = TRUE;
107110
rect->width += rect->x;
108111
rect->x = 0;
109112
}
110113
if (rect->y < 0) {
114+
overflow = TRUE;
111115
rect->height += rect->y;
112116
rect->y = 0;
113117
}
114118

115119
if (rect->x + rect->width > box_w) {
120+
overflow = TRUE;
116121
if (rect->x < box_w) {
117122
rect->width = box_w - rect->x;
118123
} else {
119124
rect->width = 0;
120125
}
121126
}
122127
if (rect->y + rect->height > box_h) {
128+
overflow = TRUE;
123129
if (rect->y < box_h) {
124130
rect->height = box_h - rect->y;
125131
} else {
126132
rect->height = 0;
127133
}
128134
}
135+
return overflow;
129136
}
130137

131-
void LCUIRectF_ValidateArea(LCUI_RectF *rect, float box_w, float box_h)
138+
LCUI_BOOL LCUIRectF_ValidateArea(LCUI_RectF *rect, float box_w, float box_h)
132139
{
140+
LCUI_BOOL overflow = FALSE;
141+
133142
if (rect->x < 0) {
143+
overflow = TRUE;
134144
rect->width += rect->x;
135145
rect->x = 0;
136146
}
137147
if (rect->y < 0) {
148+
overflow = TRUE;
138149
rect->height += rect->y;
139150
rect->y = 0;
140151
}
141152

142153
if (rect->x + rect->width - box_w > 0) {
154+
overflow = TRUE;
143155
if (rect->x - box_w < 0) {
144156
rect->width = box_w - rect->x;
145157
} else {
146158
rect->width = 0;
147159
}
148160
}
149161
if (rect->y + rect->height - box_h > 0) {
162+
overflow = TRUE;
150163
if (rect->y - box_h < 0) {
151164
rect->height = box_h - rect->y;
152165
} else {
153166
rect->height = 0;
154167
}
155168
}
169+
return overflow;
156170
}
157171

158172
/* FIXME: need new shorter name */

0 commit comments

Comments
 (0)