diff --git a/Widgets/Painter.cpp b/Widgets/Painter.cpp index 5257c04286..c5c8d7adbd 100644 --- a/Widgets/Painter.cpp +++ b/Widgets/Painter.cpp @@ -12,8 +12,8 @@ Painter::Painter(Widget& widget) { if (auto* window = widget.window()) { printf("window :: %s\n", window->title().characters()); - m_translation.setX(window->x()); - m_translation.setY(window->y()); + m_translation = window->position(); + m_translation.moveBy(widget.position()); } else { m_translation.setX(widget.x()); m_translation.setY(widget.y()); diff --git a/Widgets/Widget.h b/Widgets/Widget.h index 230267fc16..dff665c4ac 100644 --- a/Widgets/Widget.h +++ b/Widgets/Widget.h @@ -24,6 +24,8 @@ public: virtual void onMouseUp(MouseEvent&); Rect rect() const { return m_rect; } + Point position() const { return m_rect.location(); } + int x() const { return rect().x(); } int y() const { return rect().y(); } int width() const { return rect().width(); } diff --git a/Widgets/test.cpp b/Widgets/test.cpp index e010d69e9c..0b2bad48ab 100644 --- a/Widgets/test.cpp +++ b/Widgets/test.cpp @@ -18,20 +18,28 @@ int main(int c, char** v) RootWidget w; WindowManager::the().setRootWidget(&w); - auto* l1 = new Label(&w); - l1->setRect(Rect(100, 100, 300, 20)); + auto* fontTestWindow = new Window; + fontTestWindow->setTitle("Font test"); + fontTestWindow->setRect({100, 100, 300, 80 }); + + auto* fontTestWindowWidget = new Widget; + fontTestWindow->setMainWidget(fontTestWindowWidget); + fontTestWindowWidget->setRect({0, 0, 300, 80 }); + + auto* l1 = new Label(fontTestWindowWidget); + l1->setRect(Rect(0, 0, 300, 20)); l1->setText("0123456789"); - auto* l2 = new Label(&w); - l2->setRect(Rect(100, 120, 300, 20)); + auto* l2 = new Label(fontTestWindowWidget); + l2->setRect(Rect(0, 20, 300, 20)); l2->setText("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); - auto* l3 = new Label(&w); - l3->setRect(Rect(100, 140, 300, 20)); + auto* l3 = new Label(fontTestWindowWidget); + l3->setRect(Rect(0, 40, 300, 20)); l3->setText("abcdefghijklmnopqrstuvwxyz"); - auto* l4 = new Label(&w); - l4->setRect(Rect(100, 160, 300, 20)); + auto* l4 = new Label(fontTestWindowWidget); + l4->setRect(Rect(0, 60, 300, 20)); l4->setText("!\"#$%&'()*+,-./:;<=>?@[\\]^_{|}~"); auto* b = new Button(&w);