diff options
-rw-r--r-- | bindings/cpp/include/pugl/pugl.hpp | 2 | ||||
-rw-r--r-- | include/pugl/pugl.h | 20 | ||||
-rw-r--r-- | src/internal.c | 16 | ||||
-rw-r--r-- | src/internal.h | 7 | ||||
-rw-r--r-- | src/mac.m | 13 | ||||
-rw-r--r-- | src/win.c | 12 | ||||
-rw-r--r-- | src/x11.c | 12 |
7 files changed, 45 insertions, 37 deletions
diff --git a/bindings/cpp/include/pugl/pugl.hpp b/bindings/cpp/include/pugl/pugl.hpp index 5a97079..a4ee273 100644 --- a/bindings/cpp/include/pugl/pugl.hpp +++ b/bindings/cpp/include/pugl/pugl.hpp @@ -545,7 +545,7 @@ public: } /// @copydoc puglSetSizeHint - Status setSizeHint(SizeHint hint, PuglSpan width, PuglSpan height) noexcept + Status setSizeHint(SizeHint hint, unsigned width, unsigned height) noexcept { return static_cast<Status>( puglSetSizeHint(cobj(), static_cast<PuglSizeHint>(hint), width, height)); diff --git a/include/pugl/pugl.h b/include/pugl/pugl.h index e3ab504..b70b91d 100644 --- a/include/pugl/pugl.h +++ b/include/pugl/pugl.h @@ -1234,8 +1234,8 @@ PUGL_API PuglStatus puglSetSizeHint(PuglView* view, PuglSizeHint hint, - PuglSpan width, - PuglSpan height); + unsigned width, + unsigned height); /** @} @@ -1820,7 +1820,7 @@ static inline PUGL_DEPRECATED_BY("puglSetSizeHint") void puglInitWindowMinSize(PuglView* view, int width, int height) { - puglSetSizeHint(view, PUGL_MIN_SIZE, (PuglSpan)width, (PuglSpan)height); + puglSetSizeHint(view, PUGL_MIN_SIZE, (unsigned)width, (unsigned)height); } /** @@ -1841,8 +1841,8 @@ puglInitWindowAspectRatio(PuglView* view, int maxX, int maxY) { - puglSetSizeHint(view, PUGL_MIN_ASPECT, (PuglSpan)minX, (PuglSpan)minY); - puglSetSizeHint(view, PUGL_MAX_ASPECT, (PuglSpan)maxX, (PuglSpan)maxY); + puglSetSizeHint(view, PUGL_MIN_ASPECT, (unsigned)minX, (unsigned)minY); + puglSetSizeHint(view, PUGL_MAX_ASPECT, (unsigned)maxX, (unsigned)maxY); } /** @@ -2081,7 +2081,7 @@ PuglStatus puglSetDefaultSize(PuglView* view, int width, int height) { return puglSetSizeHint( - view, PUGL_DEFAULT_SIZE, (PuglSpan)width, (PuglSpan)height); + view, PUGL_DEFAULT_SIZE, (unsigned)width, (unsigned)height); } /** @@ -2098,7 +2098,7 @@ PuglStatus puglSetMinSize(PuglView* view, int width, int height) { return puglSetSizeHint( - view, PUGL_MIN_SIZE, (PuglSpan)width, (PuglSpan)height); + view, PUGL_MIN_SIZE, (unsigned)width, (unsigned)height); } /** @@ -2115,7 +2115,7 @@ PuglStatus puglSetMaxSize(PuglView* view, int width, int height) { return puglSetSizeHint( - view, PUGL_MAX_SIZE, (PuglSpan)width, (PuglSpan)height); + view, PUGL_MAX_SIZE, (unsigned)width, (unsigned)height); } /** @@ -2139,10 +2139,10 @@ PuglStatus puglSetAspectRatio(PuglView* view, int minX, int minY, int maxX, int maxY) { const PuglStatus st0 = - puglSetSizeHint(view, PUGL_MIN_ASPECT, (PuglSpan)minX, (PuglSpan)minY); + puglSetSizeHint(view, PUGL_MIN_ASPECT, (unsigned)minX, (unsigned)minY); const PuglStatus st1 = - puglSetSizeHint(view, PUGL_MAX_ASPECT, (PuglSpan)maxX, (PuglSpan)maxY); + puglSetSizeHint(view, PUGL_MAX_ASPECT, (unsigned)maxX, (unsigned)maxY); return st0 ? st0 : st1; } diff --git a/src/internal.c b/src/internal.c index 3c4d304..dfea0ca 100644 --- a/src/internal.c +++ b/src/internal.c @@ -68,6 +68,22 @@ puglSetString(char** dest, const char* string) } } +PuglStatus +puglStoreSizeHint(PuglView* const view, + const PuglSizeHint hint, + const unsigned width, + const unsigned height) +{ + if (width > INT16_MAX || height > INT16_MAX || + (unsigned)hint >= PUGL_NUM_SIZE_HINTS) { + return PUGL_BAD_PARAMETER; + } + + view->sizeHints[hint].width = (PuglSpan)width; + view->sizeHints[hint].height = (PuglSpan)height; + return PUGL_SUCCESS; +} + uint32_t puglDecodeUTF8(const uint8_t* buf) { diff --git a/src/internal.h b/src/internal.h index 3721c10..f978074 100644 --- a/src/internal.h +++ b/src/internal.h @@ -34,6 +34,13 @@ puglSetBlob(PuglBlob* dest, const void* data, size_t len); void puglSetString(char** dest, const char* string); +/// Store `width` and `height` as the current value of a size `hint` +PuglStatus +puglStoreSizeHint(PuglView* view, + PuglSizeHint hint, + unsigned width, + unsigned height); + /// Handle a changed string property PUGL_API PuglStatus @@ -1849,17 +1849,12 @@ puglSetSize(PuglView* const view, const unsigned width, const unsigned height) PuglStatus puglSetSizeHint(PuglView* const view, const PuglSizeHint hint, - const PuglSpan width, - const PuglSpan height) + const unsigned width, + const unsigned height) { - if ((unsigned)hint >= PUGL_NUM_SIZE_HINTS) { - return PUGL_BAD_PARAMETER; - } - - view->sizeHints[hint].width = width; - view->sizeHints[hint].height = height; + const PuglStatus st = puglStoreSizeHint(view, hint, width, height); - return view->impl->window ? updateSizeHint(view, hint) : PUGL_SUCCESS; + return (!st && view->impl->window) ? updateSizeHint(view, hint) : st; } PuglStatus @@ -1358,16 +1358,10 @@ puglSetSize(PuglView* const view, const unsigned width, const unsigned height) PuglStatus puglSetSizeHint(PuglView* const view, const PuglSizeHint hint, - const PuglSpan width, - const PuglSpan height) + const unsigned width, + const unsigned height) { - if ((unsigned)hint >= PUGL_NUM_SIZE_HINTS) { - return PUGL_BAD_PARAMETER; - } - - view->sizeHints[hint].width = width; - view->sizeHints[hint].height = height; - return PUGL_SUCCESS; + return puglStoreSizeHint(view, hint, width, height); } PuglStatus @@ -2038,16 +2038,12 @@ puglSetSize(PuglView* const view, const unsigned width, const unsigned height) PuglStatus puglSetSizeHint(PuglView* const view, const PuglSizeHint hint, - const PuglSpan width, - const PuglSpan height) + const unsigned width, + const unsigned height) { - if ((unsigned)hint >= PUGL_NUM_SIZE_HINTS) { - return PUGL_BAD_PARAMETER; - } + const PuglStatus st = puglStoreSizeHint(view, hint, width, height); - view->sizeHints[hint].width = width; - view->sizeHints[hint].height = height; - return updateSizeHints(view); + return st ? st : updateSizeHints(view); } PuglStatus |