aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/internal.c16
-rw-r--r--src/internal.h7
-rw-r--r--src/mac.m13
-rw-r--r--src/win.c12
-rw-r--r--src/x11.c12
5 files changed, 34 insertions, 26 deletions
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
diff --git a/src/mac.m b/src/mac.m
index d68816a..26048a8 100644
--- a/src/mac.m
+++ b/src/mac.m
@@ -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
diff --git a/src/win.c b/src/win.c
index bc13a0f..de648c7 100644
--- a/src/win.c
+++ b/src/win.c
@@ -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
diff --git a/src/x11.c b/src/x11.c
index 0513280..eabb715 100644
--- a/src/x11.c
+++ b/src/x11.c
@@ -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