diff options
author | David Robillard <d@drobilla.net> | 2023-05-12 17:09:05 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2023-05-12 17:16:24 -0400 |
commit | 049a7254beb94d33e315930f42b434ded6e29fa5 (patch) | |
tree | 7e0695bf93d8e1602067f6391f1e1c4c3ffe4526 /src | |
parent | 70a01e11a5c7b6c47717eb4b324e30ee331a817a (diff) | |
download | pugl-049a7254beb94d33e315930f42b434ded6e29fa5.tar.gz pugl-049a7254beb94d33e315930f42b434ded6e29fa5.tar.bz2 pugl-049a7254beb94d33e315930f42b434ded6e29fa5.zip |
Factor out puglIsValidSize() and use consistent rules everywhere
Diffstat (limited to 'src')
-rw-r--r-- | src/internal.c | 15 | ||||
-rw-r--r-- | src/internal.h | 7 | ||||
-rw-r--r-- | src/mac.m | 7 | ||||
-rw-r--r-- | src/win.c | 6 | ||||
-rw-r--r-- | src/x11.c | 11 |
5 files changed, 24 insertions, 22 deletions
diff --git a/src/internal.c b/src/internal.c index d9f034e..cff66be 100644 --- a/src/internal.c +++ b/src/internal.c @@ -12,6 +12,12 @@ #include <stdlib.h> #include <string.h> +bool +puglIsValidSize(const PuglViewSize size) +{ + return size.width && size.height; +} + void puglEnsureHint(PuglView* const view, const PuglViewHint hint, const int value) { @@ -110,12 +116,6 @@ puglDecodeUTF8(const uint8_t* buf) return 0xFFFD; } -static inline bool -isValidSize(const double width, const double height) -{ - return width > 0.0 && height > 0.0; -} - PuglStatus puglPreRealize(PuglView* const view) { @@ -130,8 +130,7 @@ puglPreRealize(PuglView* const view) } // Ensure that the default size is set to a valid size - const PuglViewSize defaultSize = view->sizeHints[PUGL_DEFAULT_SIZE]; - if (!isValidSize(defaultSize.width, defaultSize.height)) { + if (!puglIsValidSize(view->sizeHints[PUGL_DEFAULT_SIZE])) { return PUGL_BAD_CONFIGURATION; } diff --git a/src/internal.h b/src/internal.h index 0c6f448..6c40dc2 100644 --- a/src/internal.h +++ b/src/internal.h @@ -1,4 +1,4 @@ -// Copyright 2012-2022 David Robillard <d@drobilla.net> +// Copyright 2012-2023 David Robillard <d@drobilla.net> // SPDX-License-Identifier: ISC // Internal utilities available to platform implementations @@ -12,11 +12,16 @@ #include "pugl/attributes.h" #include "pugl/pugl.h" +#include <stdbool.h> #include <stddef.h> #include <stdint.h> PUGL_BEGIN_DECLS +/// Return true if `size` is a valid view size +bool +puglIsValidSize(PuglViewSize size); + /// Set hint to a default value if it is unset (PUGL_DONT_CARE) void puglEnsureHint(PuglView* view, PuglViewHint hint, int value); @@ -343,7 +343,7 @@ dispatchCurrentChildViewConfiguration(PuglView* const view) { const PuglViewSize defaultSize = puglview->sizeHints[PUGL_DEFAULT_SIZE]; - return (defaultSize.width && defaultSize.height) + return puglIsValidSize(defaultSize) ? sizePoints(puglview, defaultSize.width, defaultSize.height) : NSMakeSize(NSViewNoInstrinsicMetric, NSViewNoInstrinsicMetric); } @@ -1083,7 +1083,7 @@ updateSizeHint(PuglView* const view, const PuglSizeHint hint) { const PuglSpan width = view->sizeHints[hint].width; const PuglSpan height = view->sizeHints[hint].height; - if (!width || !height) { + if (!puglIsValidSize(view->sizeHints[hint])) { return PUGL_FAILURE; } @@ -1238,8 +1238,7 @@ puglRealize(PuglView* view) NSLayoutRelationGreaterThanOrEqual, view->sizeHints[PUGL_MIN_SIZE].height)]; - if (view->sizeHints[PUGL_MAX_SIZE].width && - view->sizeHints[PUGL_MAX_SIZE].height) { + if (puglIsValidSize(view->sizeHints[PUGL_MAX_SIZE])) { [impl->wrapperView addConstraint:puglConstraint(impl->wrapperView, NSLayoutAttributeWidth, @@ -739,7 +739,8 @@ handleMessage(PuglView* view, UINT message, WPARAM wParam, LPARAM lParam) handleConfigure(view, &event); break; case WM_SIZING: - if (view->sizeHints[PUGL_MIN_ASPECT].width) { + if (puglIsValidSize(view->sizeHints[PUGL_MIN_ASPECT]) && + puglIsValidSize(view->sizeHints[PUGL_MAX_ASPECT])) { constrainAspect(view, (RECT*)lParam, wParam); return TRUE; } @@ -771,8 +772,7 @@ handleMessage(PuglView* view, UINT message, WPARAM wParam, LPARAM lParam) mmi = (MINMAXINFO*)lParam; mmi->ptMinTrackSize.x = view->sizeHints[PUGL_MIN_SIZE].width; mmi->ptMinTrackSize.y = view->sizeHints[PUGL_MIN_SIZE].height; - if (view->sizeHints[PUGL_MAX_SIZE].width && - view->sizeHints[PUGL_MAX_SIZE].height) { + if (puglIsValidSize(view->sizeHints[PUGL_MAX_SIZE])) { mmi->ptMaxTrackSize.x = view->sizeHints[PUGL_MAX_SIZE].width; mmi->ptMaxTrackSize.y = view->sizeHints[PUGL_MAX_SIZE].height; } @@ -402,21 +402,21 @@ updateSizeHints(const PuglView* const view) sizeHints.max_height = (int)frame.height; } else { const PuglViewSize defaultSize = view->sizeHints[PUGL_DEFAULT_SIZE]; - if (defaultSize.width && defaultSize.height) { + if (puglIsValidSize(defaultSize)) { sizeHints.flags |= PBaseSize; sizeHints.base_width = defaultSize.width; sizeHints.base_height = defaultSize.height; } const PuglViewSize minSize = view->sizeHints[PUGL_MIN_SIZE]; - if (minSize.width && minSize.height) { + if (puglIsValidSize(minSize)) { sizeHints.flags |= PMinSize; sizeHints.min_width = minSize.width; sizeHints.min_height = minSize.height; } const PuglViewSize maxSize = view->sizeHints[PUGL_MAX_SIZE]; - if (maxSize.width && maxSize.height) { + if (puglIsValidSize(maxSize)) { sizeHints.flags |= PMaxSize; sizeHints.max_width = maxSize.width; sizeHints.max_height = maxSize.height; @@ -424,8 +424,7 @@ updateSizeHints(const PuglView* const view) const PuglViewSize minAspect = view->sizeHints[PUGL_MIN_ASPECT]; const PuglViewSize maxAspect = view->sizeHints[PUGL_MAX_ASPECT]; - if (minAspect.width && minAspect.height && maxAspect.width && - maxAspect.height) { + if (puglIsValidSize(minAspect) && puglIsValidSize(maxAspect)) { sizeHints.flags |= PAspect; sizeHints.min_aspect.x = minAspect.width; sizeHints.min_aspect.y = minAspect.height; @@ -434,7 +433,7 @@ updateSizeHints(const PuglView* const view) } const PuglViewSize fixedAspect = view->sizeHints[PUGL_FIXED_ASPECT]; - if (fixedAspect.width && fixedAspect.height) { + if (puglIsValidSize(fixedAspect)) { sizeHints.flags |= PAspect; sizeHints.min_aspect.x = fixedAspect.width; sizeHints.min_aspect.y = fixedAspect.height; |