diff --git a/dgl/TopLevelWidget.hpp b/dgl/TopLevelWidget.hpp index 165f41bd..4b0de992 100644 --- a/dgl/TopLevelWidget.hpp +++ b/dgl/TopLevelWidget.hpp @@ -66,6 +66,37 @@ public: */ Window& getWindow() const noexcept; + /** + Check if this top-level widget's window is resizable (by the user or window manager). + For situations where this top-level widget is an embed plugin UI and the plugin host does not support resizing, + this function can return false where it normally returns true. + + You might want to add a resize handle for such cases, so the user is still allowed to resize the window. + (programatically resizing a window is always possible, but the same is not true for the window manager) + */ + bool isResizable() const noexcept; + + /** + Set width of this widget's window. + @note This will not change the widget's size right away, but be pending on OS resizing the window + */ + void setWidth(uint width); + + /** + Set height of this widget's window. + */ + void setHeight(uint height); + + /** + Set size of this widget's window, using @a width and @a height values. + */ + void setSize(uint width, uint height); + + /** + Set size of this widget's window. + */ + void setSize(const Size& size); + // TODO group stuff after here, convenience functions present in Window class bool addIdleCallback(IdleCallback* callback, uint timerFrequencyInMs = 0); bool removeIdleCallback(IdleCallback* callback); diff --git a/dgl/Window.hpp b/dgl/Window.hpp index d0a6b34d..bd6c0b29 100644 --- a/dgl/Window.hpp +++ b/dgl/Window.hpp @@ -185,7 +185,7 @@ public: void close(); /** - Check if this window is resizable. + Check if this window is resizable (by the user or window manager). @see setResizable */ bool isResizable() const noexcept; diff --git a/dgl/src/SubWidget.cpp b/dgl/src/SubWidget.cpp index 3e0ef59d..40b34a11 100644 --- a/dgl/src/SubWidget.cpp +++ b/dgl/src/SubWidget.cpp @@ -96,8 +96,7 @@ void SubWidget::setAbsolutePos(const Point& pos) noexcept pData->absolutePos = pos; onPositionChanged(ev); - // repaint the bounds of parent - pData->parentWidget->repaint(); + repaint(); } Widget* SubWidget::getParentWidget() const noexcept diff --git a/dgl/src/TopLevelWidget.cpp b/dgl/src/TopLevelWidget.cpp index 9f68360e..ffd227dd 100644 --- a/dgl/src/TopLevelWidget.cpp +++ b/dgl/src/TopLevelWidget.cpp @@ -40,6 +40,31 @@ Window& TopLevelWidget::getWindow() const noexcept return pData->window; } +bool TopLevelWidget::isResizable() const noexcept +{ + return pData->window.isResizable(); +} + +void TopLevelWidget::setWidth(const uint width) +{ + pData->window.setWidth(width); +} + +void TopLevelWidget::setHeight(const uint height) +{ + pData->window.setHeight(height); +} + +void TopLevelWidget::setSize(const uint width, const uint height) +{ + pData->window.setSize(width, height); +} + +void TopLevelWidget::setSize(const Size& size) +{ + pData->window.setSize(size); +} + bool TopLevelWidget::addIdleCallback(IdleCallback* const callback, const uint timerFrequencyInMs) { return pData->window.addIdleCallback(callback, timerFrequencyInMs); diff --git a/dgl/src/Widget.cpp b/dgl/src/Widget.cpp index 31095002..0a393572 100644 --- a/dgl/src/Widget.cpp +++ b/dgl/src/Widget.cpp @@ -46,6 +46,8 @@ void Widget::setVisible(bool visible) pData->visible = visible; repaint(); + + // FIXME check case of hiding a previously visible widget, does it trigger a repaint? } void Widget::show() diff --git a/dgl/src/WindowPrivateData.cpp b/dgl/src/WindowPrivateData.cpp index 57ea9977..33fe82dd 100644 --- a/dgl/src/WindowPrivateData.cpp +++ b/dgl/src/WindowPrivateData.cpp @@ -652,7 +652,15 @@ void Window::PrivateData::onPuglConfigure(const double width, const double heigh { TopLevelWidget* const widget(*it); - widget->setSize(uwidth, uheight); + /* Some special care here, we call Widget::setSize instead of the TopLevelWidget one. + * This is because we want TopLevelWidget::setSize to handle both window and widget size, + * but we dont want to change window size here, because we are the window.. + * + * So we just call the Widget specific method manually. + * Alternatively, we could expose a resize function on the pData, like done with the display function. + * But there is nothing extra we need to do in there, so this works fine. + */ + ((Widget*)widget)->setSize(uwidth, uheight); } #endif