Skip to content

Commit

Permalink
Fix checkbox for uneven dpi scales
Browse files Browse the repository at this point in the history
  • Loading branch information
dpjudas committed May 25, 2024
1 parent 1431770 commit 1004383
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/widgets/checkboxlabel/checkboxlabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,24 @@ double CheckboxLabel::GetPreferredHeight() const

void CheckboxLabel::OnPaint(Canvas* canvas)
{
// To do: add and use GetStyleImage for the checkbox

double center = GridFitPoint(GetHeight() * 0.5);
double borderwidth = GridFitSize(1.0);
double outerboxsize = GridFitSize(10.0);
double innerboxsize = outerboxsize - 2.0 * borderwidth;
double checkedsize = innerboxsize - 2.0 * borderwidth;

if (checked)
{
canvas->fillRect(Rect::xywh(0.0, GetHeight() * 0.5 - 6.0, 10.0, 10.0), GetStyleColor("checked-outer-border-color"));
canvas->fillRect(Rect::xywh(1.0, GetHeight() * 0.5 - 5.0, 8.0, 8.0), GetStyleColor("checked-inner-border-color"));
canvas->fillRect(Rect::xywh(2.0, GetHeight() * 0.5 - 4.0, 6.0, 6.0), GetStyleColor("checked-color"));
canvas->fillRect(Rect::xywh(0.0, center - 6.0 * borderwidth, outerboxsize, outerboxsize), GetStyleColor("checked-outer-border-color"));
canvas->fillRect(Rect::xywh(1.0 * borderwidth, center - 5.0 * borderwidth, innerboxsize, innerboxsize), GetStyleColor("checked-inner-border-color"));
canvas->fillRect(Rect::xywh(2.0 * borderwidth, center - 4.0 * borderwidth, checkedsize, checkedsize), GetStyleColor("checked-color"));
}
else
{
canvas->fillRect(Rect::xywh(0.0, GetHeight() * 0.5 - 6.0, 10.0, 10.0), GetStyleColor("unchecked-outer-border-color"));
canvas->fillRect(Rect::xywh(1.0, GetHeight() * 0.5 - 5.0, 8.0, 8.0), GetStyleColor("unchecked-inner-border-color"));
canvas->fillRect(Rect::xywh(0.0, center - 6.0 * borderwidth, outerboxsize, outerboxsize), GetStyleColor("unchecked-outer-border-color"));
canvas->fillRect(Rect::xywh(1.0 * borderwidth, center - 5.0 * borderwidth, innerboxsize, innerboxsize), GetStyleColor("unchecked-inner-border-color"));
}

canvas->drawText(Point(14.0, GetHeight() - 5.0), GetStyleColor("color"), text);
Expand Down

0 comments on commit 1004383

Please sign in to comment.