Add a bit more functionality to the controls

This commit is contained in:
Magnus Norddahl 2023-12-27 04:46:14 +01:00 committed by Christoph Oelckers
commit b7362aa3f2
7 changed files with 164 additions and 6 deletions

View file

@ -41,7 +41,48 @@ double CheckboxLabel::GetPreferredHeight() const
void CheckboxLabel::OnPaint(Canvas* canvas)
{
if (checked)
canvas->drawText(Point(0.0, GetHeight() - 5.0), Colorf::fromRgba8(255, 255, 255), "[x] " + text);
{
canvas->fillRect(Rect::xywh(0.0, GetHeight() * 0.5 - 5.0, 10.0, 10.0), Colorf::fromRgba8(100, 100, 100));
canvas->fillRect(Rect::xywh(1.0, GetHeight() * 0.5 - 4.0, 8.0, 8.0), Colorf::fromRgba8(51, 51, 51));
canvas->fillRect(Rect::xywh(2.0, GetHeight() * 0.5 - 3.0, 6.0, 6.0), Colorf::fromRgba8(226, 223, 219));
}
else
canvas->drawText(Point(0.0, GetHeight() - 5.0), Colorf::fromRgba8(255, 255, 255), "[ ] " + text);
{
canvas->fillRect(Rect::xywh(0.0, GetHeight() * 0.5 - 5.0, 10.0, 10.0), Colorf::fromRgba8(68, 68, 68));
canvas->fillRect(Rect::xywh(1.0, GetHeight() * 0.5 - 4.0, 8.0, 8.0), Colorf::fromRgba8(51, 51, 51));
}
canvas->drawText(Point(14.0, GetHeight() - 5.0), Colorf::fromRgba8(255, 255, 255), text);
}
void CheckboxLabel::OnMouseDown(const Point& pos, int key)
{
mouseDownActive = true;
SetFocus();
}
void CheckboxLabel::OnMouseUp(const Point& pos, int key)
{
if (mouseDownActive)
{
Toggle();
}
mouseDownActive = false;
}
void CheckboxLabel::OnMouseLeave()
{
mouseDownActive = false;
}
void CheckboxLabel::OnKeyUp(EInputKey key)
{
if (key == IK_Space)
Toggle();
}
void CheckboxLabel::Toggle()
{
checked = !checked;
Update();
}