diff --git a/engine/breeze/ui/ui.c b/engine/breeze/ui/ui.c index 6d1b053..811bc1c 100644 --- a/engine/breeze/ui/ui.c +++ b/engine/breeze/ui/ui.c @@ -177,6 +177,9 @@ static void calculateSizes(BzUINode *node) { } calculateAxisSizePostorder(BZ_UI_AXIS_X, node); calculateAxisSizePostorder(BZ_UI_AXIS_Y, node); + + node->computedSize[BZ_UI_AXIS_X] += node->padding[BZ_UI_AXIS_X] + node->padding[BZ_UI_AXIS_X + 2]; + node->computedSize[BZ_UI_AXIS_Y] += node->padding[BZ_UI_AXIS_Y] + node->padding[BZ_UI_AXIS_Y + 2]; } static void calculatePositions(BzUINode *node, f32 x, f32 y); @@ -308,24 +311,37 @@ static void renderNode(BzUI *ui, BzUINode *node) { BzUIInteraction *inter = &node->interaction; Rectangle rect = getNodeRect(node); + // Adjust for padding + Rectangle drawRect = rect; + drawRect.x += node->padding[BZ_UI_AXIS_X]; + drawRect.y += node->padding[BZ_UI_AXIS_Y]; + drawRect.width -= (node->padding[BZ_UI_AXIS_X] + node->padding[BZ_UI_AXIS_X + 2]); + drawRect.height -= (node->padding[BZ_UI_AXIS_Y] + node->padding[BZ_UI_AXIS_Y + 2]); if (node->flags & BZ_UI_DRAW_BACKGROUND) { Color color = style->bgColor; if (inter->hovering) color = style->bgHoverColor; if (inter->down) color = style->bgActiveColor; - DrawRectangle(rect.x, rect.y, rect.width, rect.height, color); + Rectangle bgRect = rect; + if (style->roundness > 0) { + bgRect.x -= 1; + bgRect.y -= 1; + bgRect.width += 2; + bgRect.height += 2; + } + DrawRectangleRounded(bgRect, style->roundness, 0, color); } - if (node->flags & BZ_UI_DRAW_BORDER && style->borderWidth > 0) { + if (node->flags & BZ_UI_DRAW_BORDER && style->borderThickness > 0) { Color color = style->borderColor; if (inter->hovering) color = style->borderHoverColor; if (inter->down) color = style->borderActiveColor; - DrawRectangleLinesEx(rect, style->borderWidth, color); + DrawRectangleRoundedLines(rect, style->roundness, 0, style->borderThickness, color); } if (node->flags & BZ_UI_DRAW_TEXT) { Color color = style->textColor; if (inter->hovering) color = style->textHoverColor; if (inter->down) color = style->textActiveColor; - DrawTextEx(GetFontDefault(), node->string, (Vector2){rect.x, rect.y}, style->fontSize, 1, color); + DrawTextEx(GetFontDefault(), node->string, (Vector2){drawRect.x, drawRect.y}, style->fontSize, 1, color); } node->changed = false; @@ -411,8 +427,11 @@ BzUIInteraction bzUIGetInteraction(BzUI *ui, BzUINode *node) { } bool bzUIButton(BzUI *ui, const char *string, BzUIStyle *style) { BzUIStyle s = { + .font = GetFontDefault(), .fontSize = 24, - .borderWidth = 1, + .borderThickness = 2.0f, + .roundness = 1.0f, + .bgColor = GRAY, .borderColor = BLACK, .borderHoverColor = BLACK, .borderActiveColor = GRAY, @@ -425,6 +444,7 @@ bool bzUIButton(BzUI *ui, const char *string, BzUIStyle *style) { } BzUINode *node = bzUINodeMake(ui, bzUIKeyFromString(string), BZ_UI_CLICKABLE | BZ_UI_DRAW_TEXT | + BZ_UI_DRAW_BACKGROUND | BZ_UI_DRAW_BORDER | BZ_UI_ALIGN_CENTER); node->string = string; node->semanticSize[BZ_UI_AXIS_X] = (BzUISize) { @@ -433,5 +453,10 @@ bool bzUIButton(BzUI *ui, const char *string, BzUIStyle *style) { node->semanticSize[BZ_UI_AXIS_Y] = node->semanticSize[BZ_UI_AXIS_X]; node->style = s; + for (i32 i = 0; i < 4; i++) { + node->padding[i] = 2; + node->margin[i] = 4; + } + return bzUIGetInteraction(ui, node).clicked; } diff --git a/engine/breeze/ui/ui.h b/engine/breeze/ui/ui.h index 5bd6d85..d4cc4cd 100644 --- a/engine/breeze/ui/ui.h +++ b/engine/breeze/ui/ui.h @@ -52,8 +52,11 @@ typedef struct BzUILayout { } BzUILayout; typedef struct BzUIStyle { - i32 fontSize; - i32 borderWidth; + Font font; + f32 fontSize; + f32 fontSpacing; + f32 borderThickness; + f32 roundness; Color textColor; Color textHoverColor; Color textActiveColor;