commit df5bff7440b04ad5b89c3ce82bc4f285f97c97c3
parent 919f18973ac4ec270bb2f4028517336ae2ec0ce8
Author: falkTX <falktx@falktx.com>
Date: Fri, 28 May 2021 13:36:53 +0100
More special handling for resize
Signed-off-by: falkTX <falktx@falktx.com>
Diffstat:
6 files changed, 69 insertions(+), 4 deletions(-)
diff --git 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<uint>& 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
@@ -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
@@ -96,8 +96,7 @@ void SubWidget::setAbsolutePos(const Point<int>& 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
@@ -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<uint>& 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
@@ -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
@@ -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