diff options
author | David Robillard <d@drobilla.net> | 2025-02-08 16:48:20 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2025-02-08 18:02:30 -0500 |
commit | 494932c79800698bcd30a506c6abe7f43c59d2bd (patch) | |
tree | 7095aee3fba8a832007a98acad0ea1894aad85fa | |
parent | 1004888ac9ace7cc2c1955c30ac449f8112f90f0 (diff) | |
download | pugl-494932c79800698bcd30a506c6abe7f43c59d2bd.tar.gz pugl-494932c79800698bcd30a506c6abe7f43c59d2bd.tar.bz2 pugl-494932c79800698bcd30a506c6abe7f43c59d2bd.zip |
Remove puglSetFrame()
Towards fully separating position from size.
-rw-r--r-- | bindings/cpp/include/pugl/pugl.hpp | 6 | ||||
-rw-r--r-- | examples/pugl_embed_demo.c | 22 | ||||
-rw-r--r-- | include/pugl/pugl.h | 11 | ||||
-rw-r--r-- | src/mac.m | 47 | ||||
-rw-r--r-- | src/win.c | 25 | ||||
-rw-r--r-- | src/x11.c | 20 |
6 files changed, 7 insertions, 124 deletions
diff --git a/bindings/cpp/include/pugl/pugl.hpp b/bindings/cpp/include/pugl/pugl.hpp index 0082fe2..f6e82bc 100644 --- a/bindings/cpp/include/pugl/pugl.hpp +++ b/bindings/cpp/include/pugl/pugl.hpp @@ -546,12 +546,6 @@ public: /// @copydoc puglGetFrame Rect frame() const noexcept { return puglGetFrame(cobj()); } - /// @copydoc puglSetFrame - Status setFrame(const Rect& frame) noexcept - { - return static_cast<Status>(puglSetFrame(cobj(), frame)); - } - /// @copydoc puglSetSizeHint Status setSizeHint(SizeHint hint, unsigned width, unsigned height) noexcept { diff --git a/examples/pugl_embed_demo.c b/examples/pugl_embed_demo.c index 61adf5c..9f0028a 100644 --- a/examples/pugl_embed_demo.c +++ b/examples/pugl_embed_demo.c @@ -51,18 +51,6 @@ static const float backgroundColorVertices[] = { // clang-format on -static PuglRect -getChildFrame(const PuglRect parentFrame) -{ - const PuglRect childFrame = { - borderWidth, - borderWidth, - (PuglSpan)(parentFrame.width - (2 * borderWidth)), - (PuglSpan)(parentFrame.height - (2 * borderWidth))}; - - return childFrame; -} - static void onDisplay(PuglView* view) { @@ -142,8 +130,9 @@ onParentEvent(PuglView* view, const PuglEvent* event) switch (event->type) { case PUGL_CONFIGURE: reshapeCube((float)event->configure.width, (float)event->configure.height); - - puglSetFrame(app->child, getChildFrame(parentFrame)); + puglSetSize(app->child, + parentFrame.width - (2 * borderWidth), + parentFrame.height - (2 * borderWidth)); break; case PUGL_UPDATE: if (app->continuous) { @@ -289,8 +278,11 @@ main(int argc, char** argv) return logError("Failed to create parent window (%s)\n", puglStrerror(st)); } - puglSetFrame(app.child, getChildFrame(parentFrame)); puglSetParent(app.child, puglGetNativeView(app.parent)); + puglSetPosition(app.child, borderWidth, borderWidth); + puglSetSize(app.child, + parentFrame.width - (2 * borderWidth), + parentFrame.height - (2 * borderWidth)); puglSetViewHint(app.child, PUGL_CONTEXT_DEBUG, opts.errorChecking); puglSetViewHint(app.child, PUGL_SAMPLES, opts.samples); diff --git a/include/pugl/pugl.h b/include/pugl/pugl.h index 43697fb..8ecea0e 100644 --- a/include/pugl/pugl.h +++ b/include/pugl/pugl.h @@ -1163,17 +1163,6 @@ PUGL_API PuglRect puglGetFrame(const PuglView* view); /** - Set the current position and size of the view. - - The position is in screen coordinates with an upper left origin. - - @return #PUGL_UNKNOWN_ERROR on failure, in which case the view frame is - unchanged. -*/ -PUGL_API PuglStatus -puglSetFrame(PuglView* view, PuglRect frame); - -/** Set the current position of the view. @return #PUGL_UNKNOWN_ERROR on failure, in which case the view frame is @@ -151,12 +151,6 @@ nsPointFromPoints(const PuglView* view, const NSPoint point) return NSMakePoint(point.x * scaleFactor, point.y * scaleFactor); } -static NSRect -rectToNsRect(const PuglRect rect) -{ - return NSMakeRect(rect.x, rect.y, rect.width, rect.height); -} - static NSSize sizePoints(PuglView* view, const PuglSpan width, const PuglSpan height) { @@ -1713,47 +1707,6 @@ puglGetScaleFactor(const PuglView* const view) } PuglStatus -puglSetFrame(PuglView* view, const PuglRect frame) -{ - PuglInternals* const impl = view->impl; - const NSRect framePx = rectToNsRect(frame); - const NSRect framePt = nsRectToPoints(view, framePx); - - if (!impl->wrapperView) { - // Set defaults to be used when realized - view->defaultX = frame.x; - view->defaultY = frame.y; - view->sizeHints[PUGL_DEFAULT_SIZE].width = (PuglSpan)frame.width; - view->sizeHints[PUGL_DEFAULT_SIZE].height = (PuglSpan)frame.height; - return PUGL_SUCCESS; - } - - if (impl->window) { - const NSRect screenPt = rectToScreen(viewScreen(view), framePt); - - // Move and resize window to fit new content rect - const NSRect winFrame = [impl->window frameRectForContentRect:screenPt]; - [impl->window setFrame:winFrame display:NO]; - - // Resize views - const NSRect sizePx = NSMakeRect(0, 0, frame.width, frame.height); - const NSRect sizePt = [impl->drawView convertRectFromBacking:sizePx]; - [impl->wrapperView setFrame:sizePt]; - [impl->drawView setFrame:sizePt]; - [impl->window dispatchCurrentConfiguration]; - return PUGL_SUCCESS; - } - - // Resize view - const NSRect sizePx = NSMakeRect(0, 0, frame.width, frame.height); - const NSRect sizePt = [impl->drawView convertRectFromBacking:sizePx]; - - [impl->wrapperView setFrame:framePt]; - [impl->drawView setFrame:sizePt]; - return dispatchCurrentChildViewConfiguration(view); -} - -PuglStatus puglSetPosition(PuglView* const view, const int x, const int y) { if (!puglIsValidPosition(x, y)) { @@ -1245,31 +1245,6 @@ puglGetScaleFactor(const PuglView* const view) } PuglStatus -puglSetFrame(PuglView* view, const PuglRect frame) -{ - if (!view->impl->hwnd) { - // Set defaults to be used when realized - view->defaultX = frame.x; - view->defaultY = frame.y; - view->sizeHints[PUGL_DEFAULT_SIZE].width = frame.width; - view->sizeHints[PUGL_DEFAULT_SIZE].height = frame.height; - return PUGL_SUCCESS; - } - - const RECT rect = - adjustedWindowRect(view, frame.x, frame.y, frame.width, frame.height); - - return puglWinStatus( - SetWindowPos(view->impl->hwnd, - HWND_TOP, - rect.left, - rect.top, - rect.right - rect.left, - rect.bottom - rect.top, - SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER)); -} - -PuglStatus puglSetPosition(PuglView* const view, const int x, const int y) { if (!puglIsValidPosition(x, y)) { @@ -1946,26 +1946,6 @@ puglGetScaleFactor(const PuglView* const view) } PuglStatus -puglSetFrame(PuglView* const view, const PuglRect frame) -{ - if (!view->impl->win) { - // Set defaults to be used when realized - view->defaultX = frame.x; - view->defaultY = frame.y; - view->sizeHints[PUGL_DEFAULT_SIZE].width = frame.width; - view->sizeHints[PUGL_DEFAULT_SIZE].height = frame.height; - return PUGL_SUCCESS; - } - - return puglX11Status(XMoveResizeWindow(view->world->impl->display, - view->impl->win, - frame.x, - frame.y, - frame.width, - frame.height)); -} - -PuglStatus puglSetPosition(PuglView* const view, const int x, const int y) { Display* const display = view->world->impl->display; |