Skip to content

Commit 26ef436

Browse files
committed
Implement minimum size for wasm
Signed-off-by: falkTX <[email protected]>
1 parent de3e72a commit 26ef436

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

dgl/src/pugl-extra/wasm.c

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -729,8 +729,8 @@ puglRealize(PuglView* const view)
729729
const char* const className = view->world->strings[PUGL_CLASS_NAME];
730730
d_stdout("className is %s", className);
731731

732-
PuglPoint defaultPos = view->positionHints[PUGL_DEFAULT_POSITION];
733-
PuglArea defaultSize = view->sizeHints[PUGL_DEFAULT_SIZE];
732+
const PuglPoint defaultPos = view->positionHints[PUGL_DEFAULT_POSITION];
733+
const PuglArea defaultSize = view->sizeHints[PUGL_DEFAULT_SIZE];
734734
if (!defaultSize.width || !defaultSize.height) {
735735
return PUGL_BAD_CONFIGURATION;
736736
}
@@ -761,6 +761,15 @@ puglRealize(PuglView* const view)
761761
canvasWrapper.style.setProperty("--device-pixel-ratio", window.devicePixelRatio);
762762
}, className);
763763

764+
const PuglArea minSize = view->sizeHints[PUGL_MIN_SIZE];
765+
if (minSize.width && minSize.height) {
766+
EM_ASM({
767+
var canvasWrapper = document.getElementById(UTF8ToString($0)).parentElement;
768+
canvasWrapper.style.setProperty("min-width", parseInt($1 / window.devicePixelRatio) + 'px');
769+
canvasWrapper.style.setProperty("min-height", parseInt($2 / window.devicePixelRatio) + 'px');
770+
}, className, minSize.width, minSize.height);
771+
}
772+
764773
emscripten_set_canvas_element_size(className, defaultSize.width, defaultSize.height);
765774
#ifndef PUGL_WASM_NO_KEYBOARD_INPUT
766775
// emscripten_set_keypress_callback(className, view, false, puglKeyCallback);
@@ -932,7 +941,30 @@ puglSetSizeHint(PuglView* const view,
932941
const unsigned width,
933942
const unsigned height)
934943
{
935-
return puglStoreSizeHint(view, hint, width, height);
944+
const PuglStatus st = puglStoreSizeHint(view, hint, width, height);
945+
if (st != PUGL_SUCCESS)
946+
return st;
947+
if (!view->impl->created)
948+
return PUGL_SUCCESS;
949+
950+
const char* const className = view->world->strings[PUGL_CLASS_NAME];
951+
952+
switch (hint) {
953+
case PUGL_MIN_SIZE:
954+
EM_ASM({
955+
var canvasWrapper = document.getElementById(UTF8ToString($0)).parentElement;
956+
canvasWrapper.style.setProperty("min-width", parseInt($1 / window.devicePixelRatio) + 'px');
957+
canvasWrapper.style.setProperty("min-height", parseInt($2 / window.devicePixelRatio) + 'px');
958+
}, className, width, height);
959+
break;
960+
case PUGL_CURRENT_SIZE:
961+
emscripten_set_canvas_element_size(className, width, height);
962+
break;
963+
default:
964+
break;
965+
}
966+
967+
return PUGL_SUCCESS;
936968
}
937969

938970
static EM_BOOL

dgl/src/pugl.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,12 @@ PuglStatus puglSetGeometryConstraints(PuglView* const view, const uint width, co
320320
return status;
321321
}
322322
#elif defined(DISTRHO_OS_WASM)
323-
// nothing
323+
const char* const className = view->world->strings[PUGL_CLASS_NAME];
324+
EM_ASM({
325+
var canvasWrapper = document.getElementById(UTF8ToString($0)).parentElement;
326+
canvasWrapper.style.setProperty("min-width", parseInt($1 / window.devicePixelRatio) + 'px');
327+
canvasWrapper.style.setProperty("min-height", parseInt($2 / window.devicePixelRatio) + 'px');
328+
}, className, width, height);
324329
#elif defined(DISTRHO_OS_WINDOWS)
325330
// nothing
326331
#elif defined(HAVE_X11)
@@ -386,7 +391,6 @@ PuglStatus puglSetSizeAndDefault(PuglView* const view, const uint width, const u
386391
return status;
387392
}
388393
#elif defined(DISTRHO_OS_WASM)
389-
d_stdout("className is %s", view->world->strings[PUGL_CLASS_NAME]);
390394
emscripten_set_canvas_element_size(view->world->strings[PUGL_CLASS_NAME], width, height);
391395
#elif defined(DISTRHO_OS_WINDOWS)
392396
// matches upstream pugl, except we re-enter context after resize

0 commit comments

Comments
 (0)