aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/internal.c15
-rw-r--r--src/internal.h7
-rw-r--r--src/mac.m7
-rw-r--r--src/win.c6
-rw-r--r--src/x11.c11
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);
diff --git a/src/mac.m b/src/mac.m
index ef0a730..1683a05 100644
--- a/src/mac.m
+++ b/src/mac.m
@@ -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,
diff --git a/src/win.c b/src/win.c
index 75e0d71..53f7142 100644
--- a/src/win.c
+++ b/src/win.c
@@ -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;
}
diff --git a/src/x11.c b/src/x11.c
index e4c0aab..1c34e92 100644
--- a/src/x11.c
+++ b/src/x11.c
@@ -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;