shithub: microui

Download patch

ref: 5826f4cbc4057ebba3d1b6d5004d0079c715d489
parent: 4fd28b3c945e170a4e67ffb2dac95aa60b0633db
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Mon May 31 11:04:17 EDT 2021

mu_draw_rect: set draw position when clipping, fixes images not clipped correctly

--- a/microui.c
+++ b/microui.c
@@ -516,10 +516,12 @@
 mu_draw_rect(mu_Rect rect, Image *color)
 {
 	mu_Command *cmd;
-	rect = clip_rect(rect, mu_get_clip_rect());
+	mu_Rect clipped;
+	clipped = clip_rect(rect, mu_get_clip_rect());
 	if (rect.w > 0 && rect.h > 0) {
 		cmd = mu_push_command(MU_COMMAND_RECT);
-		cmd->rect.rect = rect;
+		cmd->rect.rect = clipped;
+		cmd->rect.position = subpt(Pt(clipped.x, clipped.y), Pt(rect.x, rect.y));
 		cmd->rect.color = color;
 	}
 }
@@ -1470,7 +1472,7 @@
 
 		case MU_COMMAND_RECT:
 			if (cmd->rect.color != nil)
-				draw(screen, screenrect(cmd->rect.rect), cmd->rect.color, nil, ZP);
+				draw(screen, screenrect(cmd->rect.rect), cmd->rect.color, nil, cmd->rect.position);
 			break;
 
 		case MU_COMMAND_ICON:
--- a/microui.h
+++ b/microui.h
@@ -133,6 +133,7 @@
 		struct
 		{
 			Image *color;
+			Point position;
 			mu_Rect rect;
 		}rect;
 
@@ -278,8 +279,8 @@
 
 mu_Command *mu_push_command(int type);
 void mu_set_clip(mu_Rect rect);
-void mu_draw_rect(mu_Rect rect, Image *color);
-void mu_draw_box(mu_Rect rect, Image *color);
+void mu_draw_rect(mu_Rect rect, Image *image);
+void mu_draw_box(mu_Rect rect, Image *image);
 void mu_draw_text(Font *font, const char *str, int len, Point pos, Image *color);
 void mu_draw_icon(int id, mu_Rect rect);