Skip to content

Commit

Permalink
AppWindowParams: add EmscriptenKeyboardElement
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed Nov 23, 2024
1 parent 0542026 commit 4cd918f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/hello_imgui/app_window_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ enum class WindowPositionMode
};


enum class EmscriptenKeyboardElement
{
Window,
Document,
Screen,
Canvas,
Default
};


enum class WindowSizeMeasureMode
{
// ScreenCoords: measure window size in screen coords.
Expand Down Expand Up @@ -215,6 +225,15 @@ struct AppWindowParams
// If true, HelloImGui will handle the edgeInsets on iOS.
bool handleEdgeInsets = true;


// --------------- Emscripten ------------------
// `emscriptenKeyboardElement`: _EmscriptenKeyboardElement, default=Default_. HTML element in which SDL will capture the keyboard events.
// (For Emscripten only)
// Choose between: Window, Document, Screen, Canvas, Default.
// If Default, the default behavior is used (which is to capture the keyboard events for the window).
EmscriptenKeyboardElement emscriptenKeyboardElement = EmscriptenKeyboardElement::Default;


// ----------------- repaint the window during resize -----------------
// Very advanced and reserved for advanced C++ users.
// If you set this to true, the window will be repainted during resize.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,21 @@ namespace HelloImGui { namespace BackendApi
SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1");
#endif

#ifdef __EMSCRIPTEN__
if (appWindowParams.emscriptenKeyboardElement == EmscriptenKeyboardElement::Window)
SDL_SetHint(SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT, "#window");
else if (appWindowParams.emscriptenKeyboardElement == EmscriptenKeyboardElement::Document)
SDL_SetHint(SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT, "#document");
else if (appWindowParams.emscriptenKeyboardElement == EmscriptenKeyboardElement::Screen)
SDL_SetHint(SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT, "#screen");
else if (appWindowParams.emscriptenKeyboardElement == EmscriptenKeyboardElement::Canvas)
SDL_SetHint(SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT, "#canvas");
else if (appWindowParams.emscriptenKeyboardElement == EmscriptenKeyboardElement::Default)
// Do nothing (default behavior, which is to capture the keyboard events for the window,
// except if the user has already set the hint manually in the javascript code)
{}
#endif // __EMSCRIPTEN__

// If the window is created with the SDL_WINDOW_ALLOW_HIGHDPI flag,
// its size in pixels may differ from its size in screen coordinates on platforms with high-DPI support
// (e.g. iOS and macOS).
Expand Down

0 comments on commit 4cd918f

Please sign in to comment.