From 0a39e13ea40d9b1a1df3864e5238e517c152315f Mon Sep 17 00:00:00 2001 From: EmilyV99 Date: Fri, 18 Aug 2023 14:49:19 -0400 Subject: [PATCH] fix: checkbox odd alignment issues --- src/gui/checkbox.cpp | 5 +++-- src/jwin.cpp | 28 +++++++++++++--------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/gui/checkbox.cpp b/src/gui/checkbox.cpp index bc401c9f19..6ecc076b53 100644 --- a/src/gui/checkbox.cpp +++ b/src/gui/checkbox.cpp @@ -86,8 +86,9 @@ void Checkbox::realize(DialogRunner& runner) void Checkbox::calculateSize() { - setPreferredWidth(14_px+12_px+Size::pixels(gui_text_width(widgFont, text.c_str()))); - setPreferredHeight(Size::pixels(std::max(text_height(widgFont)+4, 14))); + auto prefh = Size::pixels(std::max(text_height(widgFont)+4, 14)); + setPreferredWidth(prefh+4_px+Size::pixels(gui_text_width(widgFont, text.c_str()))); + setPreferredHeight(prefh); Widget::calculateSize(); } diff --git a/src/jwin.cpp b/src/jwin.cpp index 6c981424f8..3143a8c3e9 100644 --- a/src/jwin.cpp +++ b/src/jwin.cpp @@ -7870,8 +7870,10 @@ int32_t new_check_proc(int32_t msg, DIALOG *d, int32_t) { case MSG_DRAW: { - int32_t tx = 2, ty = 2, tx2 = 0; + const int box_spacing = 4; + int32_t tx = 2, ty = 2, tx2 = 2; int fh = text_height(font); + auto txt_y = ty+(d->h-fh)/2; BITMAP* tmp = create_bitmap_ex(8, d->w+4, d->h+4); clear_bitmap(tmp); set_clip_rect(tmp, tx, ty, tmp->w-tx, tmp->h-ty); @@ -7881,14 +7883,14 @@ int32_t new_check_proc(int32_t msg, DIALOG *d, int32_t) { if(d->flags & D_DISABLED) { - gui_textout_ln(tmp, str, tx+1, ty+1+(d->h-(fh-gui_font_baseline))/2, scheme[jcLIGHT], scheme[jcBOX], 0); - tl=gui_textout_ln(tmp, str, tx, ty+(d->h-(fh-gui_font_baseline))/2, scheme[jcDISABLED_FG], -1, 0); - bx=tl+fh/2; + gui_textout_ln(tmp, str, tx+1, txt_y+1, scheme[jcLIGHT], scheme[jcBOX], 0); + tl=gui_textout_ln(tmp, str, tx, txt_y, scheme[jcDISABLED_FG], -1, 0); + bx=tl+box_spacing; } else { - tl=gui_textout_ln(tmp, str, tx, ty+(d->h-(fh-gui_font_baseline))/2, scheme[jcBOXFG], scheme[jcBOX], 0); - bx=tl+fh/2; + tl=gui_textout_ln(tmp, str, tx, txt_y, scheme[jcBOXFG], scheme[jcBOX], 0); + bx=tl+box_spacing; } } } @@ -7902,22 +7904,18 @@ int32_t new_check_proc(int32_t msg, DIALOG *d, int32_t) if(d->d1) { - tx2=tx+bx+d->h-1+(fh/2); + tx2=tx+bx+d->h-1+box_spacing; if(has_text) { - int txty = ty+(d->h-(fh-gui_font_baseline))/2; - int __min = 2, __max = (d->h - 2 - fh) - ((d->flags & D_DISABLED) ? 1 : 0); - if (__max < __min) __max = __min; - txty = vbound(txty, __min, __max); if(d->flags & D_DISABLED) { - gui_textout_ln(tmp, str, tx2+1, txty+1, scheme[jcLIGHT], scheme[jcBOX], 0); - tl=gui_textout_ln(tmp, str, tx2, txty, scheme[jcDISABLED_FG], -1, 0); + gui_textout_ln(tmp, str, tx2+1, txt_y+1, scheme[jcLIGHT], scheme[jcBOX], 0); + tl=gui_textout_ln(tmp, str, tx2, txt_y, scheme[jcDISABLED_FG], -1, 0); } else { - tl=gui_textout_ln(tmp, str, tx2, txty, scheme[jcBOXFG], scheme[jcBOX], 0); + tl=gui_textout_ln(tmp, str, tx2, txt_y, scheme[jcBOXFG], scheme[jcBOX], 0); } } } @@ -7931,7 +7929,7 @@ int32_t new_check_proc(int32_t msg, DIALOG *d, int32_t) set_clip_rect(tmp, 0, 0, tmp->w, tmp->h); if(has_text) { - dotted_rect(tmp, tx2-1, ty-1, tx2+tl, ty+fh, (d->flags & D_GOTFOCUS)?scheme[jcDARK]:scheme[jcBOX], scheme[jcBOX]); + dotted_rect(tmp, tx2-1, txt_y-1, tx2+tl, txt_y+fh, (d->flags & D_GOTFOCUS)?scheme[jcDARK]:scheme[jcBOX], scheme[jcBOX]); } masked_blit(tmp, screen, 0, 0, d->x-tx, d->y-ty, d->w+tx+tx, d->h+ty+ty);