diff options
-rw-r--r-- | pugl/pugl.h | 6 | ||||
-rw-r--r-- | pugl/pugl_internal.h | 9 | ||||
-rw-r--r-- | pugl/pugl_osx.m | 3 | ||||
-rw-r--r-- | pugl/pugl_win.cpp | 17 | ||||
-rw-r--r-- | pugl/pugl_x11.c | 5 | ||||
-rw-r--r-- | pugl_test.c | 1 |
6 files changed, 39 insertions, 2 deletions
diff --git a/pugl/pugl.h b/pugl/pugl.h index 68ecc19..54b4c78 100644 --- a/pugl/pugl.h +++ b/pugl/pugl.h @@ -165,6 +165,12 @@ PUGL_API void puglInitWindowSize(PuglView* view, int width, int height); /** + Set the minimum window size before creating a window. +*/ +PUGL_API void +puglInitWindowMinSize(PuglView* view, int width, int height); + +/** Enable or disable resizing before creating a window. */ PUGL_API void diff --git a/pugl/pugl_internal.h b/pugl/pugl_internal.h index 32d31bf..8a193d6 100644 --- a/pugl/pugl_internal.h +++ b/pugl/pugl_internal.h @@ -52,6 +52,8 @@ struct PuglViewImpl { int width; int height; + int min_width; + int min_height; int mods; bool mouse_in_view; bool ignoreKeyRepeat; @@ -90,6 +92,13 @@ puglInitWindowSize(PuglView* view, int width, int height) } void +puglInitWindowMinSize(PuglView* view, int width, int height) +{ + view->min_width = width; + view->min_height = height; +} + +void puglInitWindowParent(PuglView* view, PuglNativeWindow parent) { view->parent = parent; diff --git a/pugl/pugl_osx.m b/pugl/pugl_osx.m index 464a8a2..3b62fae 100644 --- a/pugl/pugl_osx.m +++ b/pugl/pugl_osx.m @@ -459,6 +459,9 @@ puglCreateWindow(PuglView* view, const char* title) [window setPuglview:view]; [window setTitle:titleString]; + if (view->min_width || view->min_height) { + [window setContentMinSize:NSMakeSize(view->min_width, view->min_height)]; + } impl->glview = [PuglOpenGLView new]; impl->window = window; diff --git a/pugl/pugl_win.cpp b/pugl/pugl_win.cpp index ead0236..2040b98 100644 --- a/pugl/pugl_win.cpp +++ b/pugl/pugl_win.cpp @@ -128,9 +128,16 @@ puglCreateWindow(PuglView* view, const char* title) int winFlags = WS_POPUPWINDOW | WS_CAPTION; if (view->resizable) { winFlags |= WS_SIZEBOX; + if (view->min_width || view->min_height) { + // Adjust the minimum window size to accomodate requested view size + RECT mr = { 0, 0, view->min_width, view->min_height }; + AdjustWindowRectEx(&mr, winFlags, FALSE, WS_EX_TOPMOST); + view->min_width = mr.right - mr.left; + view->min_height = wr.bottom - mr.top; + } } - // Adjust the overall window size to accomodate our requested client size + // Adjust the window size to accomodate requested view size RECT wr = { 0, 0, view->width, view->height }; AdjustWindowRectEx(&wr, winFlags, FALSE, WS_EX_TOPMOST); @@ -305,18 +312,24 @@ handleMessage(PuglView* view, UINT message, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; PuglKey key; + RECT rect; + MINMAXINFO* mmi; setModifiers(view); switch (message) { case WM_CREATE: case WM_SHOWWINDOW: case WM_SIZE: - RECT rect; GetClientRect(view->impl->hwnd, &rect); puglReshape(view, rect.right, rect.bottom); view->width = rect.right; view->height = rect.bottom; break; + case WM_GETMINMAXINFO: + mmi = (MINMAXINFO*)lParam; + mmi->ptMinTrackSize.x = view->min_width; + mmi->ptMinTrackSize.y = view->min_height; + break; case WM_PAINT: BeginPaint(view->impl->hwnd, &ps); puglDisplay(view); diff --git a/pugl/pugl_x11.c b/pugl/pugl_x11.c index e0852be..e3325cd 100644 --- a/pugl/pugl_x11.c +++ b/pugl/pugl_x11.c @@ -210,6 +210,11 @@ puglCreateWindow(PuglView* view, const char* title) sizeHints.max_width = view->width; sizeHints.max_height = view->height; XSetNormalHints(impl->display, impl->win, &sizeHints); + } else if (view->min_width || view->min_height) { + sizeHints.flags = PMinSize; + sizeHints.min_width = view->min_width; + sizeHints.min_height = view->min_height; + XSetNormalHints(impl->display, impl->win, &sizeHints); } if (title) { diff --git a/pugl_test.c b/pugl_test.c index aa7997d..9b942f4 100644 --- a/pugl_test.c +++ b/pugl_test.c @@ -170,6 +170,7 @@ main(int argc, char** argv) PuglView* view = puglInit(NULL, NULL); puglInitWindowSize(view, 512, 512); + puglInitWindowMinSize(view, 256, 256); puglInitResizable(view, resizable); puglIgnoreKeyRepeat(view, ignoreKeyRepeat); |