#include "stdlib.h"
#include "microui.h"

// Microui

typedef struct mu_Renderer {
	void (*draw_rect) (mu_Rect* rect, mu_Color* color);
	void (*draw_text) (mu_Vec2* pos, mu_Color* color, const char* str);
	void (*draw_icon) (int id, mu_Rect* rect, mu_Color* color);
	void (*clip_rect) (mu_Rect* rect);
} mu_Renderer;


int _mu_begin_window_ex(mu_Context* ctx, const char *title, mu_Rect *rect, int opt) {
	return mu_begin_window_ex(ctx, title, *rect, opt);
}

int mu_process_commands(mu_Context *ctx, mu_Renderer *renderer) {	
	mu_Command *cmd = NULL;
	while (mu_next_command(ctx, &cmd)) {
      switch (cmd->type) {
        case MU_COMMAND_TEXT: 
			renderer->draw_text(&cmd->text.pos, &cmd->text.color, cmd->text.str); 
			break;
        case MU_COMMAND_RECT: 
			renderer->draw_rect(&cmd->rect.rect, &cmd->rect.color);
			break;
        case MU_COMMAND_ICON: 
			renderer->draw_icon(cmd->icon.id, &cmd->icon.rect, &cmd->icon.color); 
			break;
        case MU_COMMAND_CLIP: 
			renderer->clip_rect(&cmd->clip.rect);
			break;
      }
    }
    return 0;
}
