mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:07:35 +00:00
More hacking on Widgets.
This commit is contained in:
parent
aee66e0119
commit
f337616741
15 changed files with 135 additions and 19 deletions
39
Widgets/Button.cpp
Normal file
39
Widgets/Button.cpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
#include "Button.h"
|
||||
#include "Painter.h"
|
||||
#include <cstdio>
|
||||
|
||||
Button::Button(Widget* parent)
|
||||
: Widget(parent)
|
||||
{
|
||||
}
|
||||
|
||||
Button::~Button()
|
||||
{
|
||||
}
|
||||
|
||||
void Button::setCaption(String&& caption)
|
||||
{
|
||||
if (caption == m_caption)
|
||||
return;
|
||||
m_caption = std::move(caption);
|
||||
update();
|
||||
}
|
||||
|
||||
void Button::onPaint(PaintEvent&)
|
||||
{
|
||||
Painter painter(*this);
|
||||
painter.fillRect({ 0, 0, width(), height() }, backgroundColor());
|
||||
if (!caption().isEmpty()) {
|
||||
painter.drawText({ 0, 0, width(), height() }, caption(), Painter::TextAlignment::Center, Color(0, 0, 0));
|
||||
}
|
||||
}
|
||||
|
||||
void Button::onMouseDown(MouseEvent& event)
|
||||
{
|
||||
printf("Button::onMouseDown: x=%d, y=%d, button=%u\n", event.x(), event.y(), (unsigned)event.button());
|
||||
|
||||
setBackgroundColor(Color(0xff, 0xc0, 0xc0));
|
||||
update();
|
||||
Widget::onMouseDown(event);
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue