From c2861def8f13c647bdd5c970ef7568d15821e0e2 Mon Sep 17 00:00:00 2001 From: iamcheeseman Date: Thu, 21 May 2026 20:52:19 -0400 Subject: clip all ui elements --- teensy/teensy_math.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'teensy/teensy_math.c') diff --git a/teensy/teensy_math.c b/teensy/teensy_math.c index 5da800c..9247bd0 100644 --- a/teensy/teensy_math.c +++ b/teensy/teensy_math.c @@ -36,3 +36,22 @@ ty_Recti ty_recti_grow(ty_Recti rect, int p) rect.h += p * 2; return rect; } + +ty_Recti ty_recti_clamp(ty_Recti rect, ty_Recti minmax) +{ + ty_Vec2i start = ty_recti_start(rect); + ty_Vec2i end = ty_recti_end(rect); + + ty_Vec2i min = ty_recti_start(minmax); + ty_Vec2i max = ty_recti_end(minmax); + + start.x = ty_clamp(start.x, min.x, max.x); + start.y = ty_clamp(start.y, min.y, max.y); + end.x = ty_clamp(end.x, min.x, max.x); + end.y = ty_clamp(end.y, min.y, max.y); + + return ty_recti( + start.x, start.y, + end.x - start.x, end.y - start.y + ); +} -- cgit v1.3-2-g0d8e