Skip to content

Commit

Permalink
fix: checkbox odd alignment issues
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilyV99 committed Aug 20, 2023
1 parent 82aee4b commit 0a39e13
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
5 changes: 3 additions & 2 deletions src/gui/checkbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
28 changes: 13 additions & 15 deletions src/jwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
}
}
Expand All @@ -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);
}
}
}
Expand All @@ -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);
Expand Down

0 comments on commit 0a39e13

Please sign in to comment.