diff options
author | David Robillard <d@drobilla.net> | 2025-02-08 16:48:43 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2025-02-08 18:02:30 -0500 |
commit | 23b0774862b79543b93a9b50b4f085c2c396698a (patch) | |
tree | d389c9950c0c55c29addab14702f796d97ade25b | |
parent | 494932c79800698bcd30a506c6abe7f43c59d2bd (diff) | |
download | pugl-23b0774862b79543b93a9b50b4f085c2c396698a.tar.gz pugl-23b0774862b79543b93a9b50b4f085c2c396698a.tar.bz2 pugl-23b0774862b79543b93a9b50b4f085c2c396698a.zip |
Add PUGL_CURRENT_SIZE hint and make size hints dynamic
-rw-r--r-- | include/pugl/pugl.h | 20 | ||||
-rw-r--r-- | src/common.c | 55 | ||||
-rw-r--r-- | src/mac.m | 5 | ||||
-rw-r--r-- | src/win.c | 5 | ||||
-rw-r--r-- | src/x11.c | 4 |
5 files changed, 55 insertions, 34 deletions
diff --git a/include/pugl/pugl.h b/include/pugl/pugl.h index 8ecea0e..6aaca58 100644 --- a/include/pugl/pugl.h +++ b/include/pugl/pugl.h @@ -983,6 +983,15 @@ typedef enum { PUGL_DEFAULT_SIZE, /** + Current size. + + This reflects the current size of the view, which may be different from + the default size if the view is resizable. Typically, it overrides the + default size. + */ + PUGL_CURRENT_SIZE, + + /** Minimum size. If set, the view's size should be constrained to be at least this large. @@ -1183,14 +1192,15 @@ puglSetSize(PuglView* view, unsigned width, unsigned height); /** Set a size hint for the view. - This can be used to set the default, minimum, and maximum size of a view, - as well as the supported range of aspect ratios. + This can be used to set the default, current, minimum, and maximum size of a + view, as well as the supported range of aspect ratios. This should be called before puglRealize() so the initial window for the - view can be configured correctly. + view can be configured correctly. It may also be used dynamically after the + window is realized, for some hints. - @return #PUGL_UNKNOWN_ERROR on failure, but always succeeds if the view is - not yet realized. + @return An error code on failure, but always succeeds if the view is not yet + realized. */ PUGL_API PuglStatus puglSetSizeHint(PuglView* view, diff --git a/src/common.c b/src/common.c index 3206a96..b28b4d6 100644 --- a/src/common.c +++ b/src/common.c @@ -105,27 +105,32 @@ puglGetWorldString(const PuglWorld* const world, const PuglStringHint key) } static void -puglSetDefaultHints(PuglHints hints) +puglSetDefaultHints(PuglView* const view) { - hints[PUGL_CONTEXT_API] = PUGL_OPENGL_API; - hints[PUGL_CONTEXT_VERSION_MAJOR] = 2; - hints[PUGL_CONTEXT_VERSION_MINOR] = 0; - hints[PUGL_CONTEXT_PROFILE] = PUGL_OPENGL_CORE_PROFILE; - hints[PUGL_CONTEXT_DEBUG] = PUGL_FALSE; - hints[PUGL_RED_BITS] = 8; - hints[PUGL_GREEN_BITS] = 8; - hints[PUGL_BLUE_BITS] = 8; - hints[PUGL_ALPHA_BITS] = 8; - hints[PUGL_DEPTH_BITS] = 0; - hints[PUGL_STENCIL_BITS] = 0; - hints[PUGL_SAMPLE_BUFFERS] = PUGL_DONT_CARE; - hints[PUGL_SAMPLES] = 0; - hints[PUGL_DOUBLE_BUFFER] = PUGL_TRUE; - hints[PUGL_SWAP_INTERVAL] = PUGL_DONT_CARE; - hints[PUGL_RESIZABLE] = PUGL_FALSE; - hints[PUGL_IGNORE_KEY_REPEAT] = PUGL_FALSE; - hints[PUGL_REFRESH_RATE] = PUGL_DONT_CARE; - hints[PUGL_VIEW_TYPE] = PUGL_DONT_CARE; + view->hints[PUGL_CONTEXT_API] = PUGL_OPENGL_API; + view->hints[PUGL_CONTEXT_VERSION_MAJOR] = 2; + view->hints[PUGL_CONTEXT_VERSION_MINOR] = 0; + view->hints[PUGL_CONTEXT_PROFILE] = PUGL_OPENGL_CORE_PROFILE; + view->hints[PUGL_CONTEXT_DEBUG] = PUGL_FALSE; + view->hints[PUGL_RED_BITS] = 8; + view->hints[PUGL_GREEN_BITS] = 8; + view->hints[PUGL_BLUE_BITS] = 8; + view->hints[PUGL_ALPHA_BITS] = 8; + view->hints[PUGL_DEPTH_BITS] = 0; + view->hints[PUGL_STENCIL_BITS] = 0; + view->hints[PUGL_SAMPLE_BUFFERS] = PUGL_DONT_CARE; + view->hints[PUGL_SAMPLES] = 0; + view->hints[PUGL_DOUBLE_BUFFER] = PUGL_TRUE; + view->hints[PUGL_SWAP_INTERVAL] = PUGL_DONT_CARE; + view->hints[PUGL_RESIZABLE] = PUGL_FALSE; + view->hints[PUGL_IGNORE_KEY_REPEAT] = PUGL_FALSE; + view->hints[PUGL_REFRESH_RATE] = PUGL_DONT_CARE; + view->hints[PUGL_VIEW_TYPE] = PUGL_DONT_CARE; + + for (unsigned i = 0U; i < PUGL_NUM_SIZE_HINTS; ++i) { + view->sizeHints[i].width = 0U; + view->sizeHints[i].height = 0U; + } } PuglView* @@ -137,13 +142,11 @@ puglNewView(PuglWorld* const world) return NULL; } - view->world = world; - view->sizeHints[PUGL_MIN_SIZE].width = 1; - view->sizeHints[PUGL_MIN_SIZE].height = 1; - view->defaultX = INT_MIN; - view->defaultY = INT_MIN; + view->world = world; + view->defaultX = INT_MIN; + view->defaultY = INT_MIN; - puglSetDefaultHints(view->hints); + puglSetDefaultHints(view); // Enlarge world view list const size_t newNumViews = world->numViews + 1U; @@ -1118,6 +1118,7 @@ updateSizeHint(PuglView* const view, const PuglSizeHint hint) switch (hint) { case PUGL_DEFAULT_SIZE: + case PUGL_CURRENT_SIZE: break; case PUGL_MIN_SIZE: @@ -1789,7 +1790,9 @@ puglSetSizeHint(PuglView* const view, { const PuglStatus st = puglStoreSizeHint(view, hint, width, height); - return (!st && view->impl->window) ? updateSizeHint(view, hint) : st; + return st ? st + : (hint == PUGL_CURRENT_SIZE) ? puglSetSize(view, width, height) + : updateSizeHint(view, hint); } PuglStatus @@ -1306,7 +1306,10 @@ puglSetSizeHint(PuglView* const view, const unsigned width, const unsigned height) { - return puglStoreSizeHint(view, hint, width, height); + const PuglStatus st = puglStoreSizeHint(view, hint, width, height); + + return (!st && hint == PUGL_CURRENT_SIZE) ? puglSetSize(view, width, height) + : st; } PuglStatus @@ -1994,7 +1994,9 @@ puglSetSizeHint(PuglView* const view, { const PuglStatus st = puglStoreSizeHint(view, hint, width, height); - return st ? st : updateSizeHints(view); + return st ? st + : (hint == PUGL_CURRENT_SIZE) ? puglSetSize(view, width, height) + : updateSizeHints(view); } PuglStatus |