diff options
Diffstat (limited to 'src/internal.c')
-rw-r--r-- | src/internal.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/internal.c b/src/internal.c index dd1b7f1..bc5080f 100644 --- a/src/internal.c +++ b/src/internal.c @@ -95,6 +95,34 @@ 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) +{ + // Ensure that a backend with at least a configure method has been set + if (!view->backend || !view->backend->configure) { + return PUGL_BAD_BACKEND; + } + + // Set the size to the default if it hasn't already been set + if (!isValidSize(view->frame.width, view->frame.height)) { + const PuglViewSize defaultSize = view->sizeHints[PUGL_DEFAULT_SIZE]; + if (!isValidSize(defaultSize.width, defaultSize.height)) { + return PUGL_BAD_CONFIGURATION; + } + + view->frame.width = defaultSize.width; + view->frame.height = defaultSize.height; + } + + return PUGL_SUCCESS; +} + PuglStatus puglDispatchSimpleEvent(PuglView* view, const PuglEventType type) { |