Browse Source

Fix button text alignment error.

When calculating the width and height of the content rect of a button,
only the border of one side is being taken into account. Instead the
border width needs to be multiplied by two before subtracting from the
bounds. This is being done for padding and rounding, but not border,
which is resulting in text being misaligned, most notably when using
buttons with thick borders.
David Reid 1 year ago
parent
commit
a668105390
2 changed files with 4 additions and 4 deletions
  1. 2 2
      nuklear.h
  2. 2 2
      src/nuklear_button.c

+ 2 - 2
nuklear.h

@@ -23892,8 +23892,8 @@ nk_do_button(nk_flags *state, struct nk_command_buffer *out, struct nk_rect r,
     /* calculate button content space */
     /* calculate button content space */
     content->x = r.x + style->padding.x + style->border + style->rounding;
     content->x = r.x + style->padding.x + style->border + style->rounding;
     content->y = r.y + style->padding.y + style->border + style->rounding;
     content->y = r.y + style->padding.y + style->border + style->rounding;
-    content->w = r.w - (2 * style->padding.x + style->border + style->rounding*2);
-    content->h = r.h - (2 * style->padding.y + style->border + style->rounding*2);
+    content->w = r.w - (2 * (style->padding.x + style->border + style->rounding));
+    content->h = r.h - (2 * (style->padding.y + style->border + style->rounding));
 
 
     /* execute button behavior */
     /* execute button behavior */
     bounds.x = r.x - style->touch_padding.x;
     bounds.x = r.x - style->touch_padding.x;

+ 2 - 2
src/nuklear_button.c

@@ -127,8 +127,8 @@ nk_do_button(nk_flags *state, struct nk_command_buffer *out, struct nk_rect r,
     /* calculate button content space */
     /* calculate button content space */
     content->x = r.x + style->padding.x + style->border + style->rounding;
     content->x = r.x + style->padding.x + style->border + style->rounding;
     content->y = r.y + style->padding.y + style->border + style->rounding;
     content->y = r.y + style->padding.y + style->border + style->rounding;
-    content->w = r.w - (2 * style->padding.x + style->border + style->rounding*2);
-    content->h = r.h - (2 * style->padding.y + style->border + style->rounding*2);
+    content->w = r.w - (2 * (style->padding.x + style->border + style->rounding));
+    content->h = r.h - (2 * (style->padding.y + style->border + style->rounding));
 
 
     /* execute button behavior */
     /* execute button behavior */
     bounds.x = r.x - style->touch_padding.x;
     bounds.x = r.x - style->touch_padding.x;