From ca7b9ca3d5cf98d9b30a5bf49ca20ae0c0f4c1e8 Mon Sep 17 00:00:00 2001 From: SlowRiot Date: Fri, 4 Sep 2026 12:42:22 +0100 Subject: [PATCH] Backends: Emscripten: Align enum and comment style --- backends/imgui_impl_emscripten.cpp | 165 ++++++++++++++--------------- 1 file changed, 80 insertions(+), 85 deletions(-) diff --git a/backends/imgui_impl_emscripten.cpp b/backends/imgui_impl_emscripten.cpp index 25c4e5f50..a23864768 100644 --- a/backends/imgui_impl_emscripten.cpp +++ b/backends/imgui_impl_emscripten.cpp @@ -32,75 +32,70 @@ float ImGui_ImplEmscripten_TargetDevicePixelRatio = 1.0f; static ImGuiKey ImGui_ImplEmscripten_TranslateKey(char const* emscripten_key); static constexpr ImGuiMouseButton ImGui_ImplEmscripten_TranslateMouseButton(unsigned short emscripten_button) __attribute__((__const__)); -namespace emscripten_browser_cursor_internal -{ - // Browser cursor helpers, adapted from https://github.com/Armchair-Software/emscripten-browser-cursor -enum class cursor +enum ImGui_ImplEmscripten_Cursor { // General - cursor_auto, // The UA will determine the cursor to display based on the current context. E.g., equivalent to text when hovering text. - cursor_default, // The platform-dependent default cursor. Typically an arrow. - none, // No cursor is rendered. + ImGui_ImplEmscripten_Cursor_Auto, // The UA will determine the cursor to display based on the current context. E.g., equivalent to text when hovering text. + ImGui_ImplEmscripten_Cursor_Default, // The platform-dependent default cursor. Typically an arrow. + ImGui_ImplEmscripten_Cursor_None, // No cursor is rendered. // Links & status - context_menu, // cursor slightly obscuring a menu icon - A context menu is available. - help, // cursor next to a question mark - Help information is available. - pointer, // right hand with an index finger pointing up - The cursor is a pointer that indicates a link. Typically an image of a pointing hand. - progress, // cursor and hour glass - The program is busy in the background, but the user can still interact with the interface (in contrast to wait). - wait, // hour glass - The program is busy, and the user can't interact with the interface (in contrast to progress). Sometimes an image of an hourglass or a watch. + ImGui_ImplEmscripten_Cursor_ContextMenu, // cursor slightly obscuring a menu icon - A context menu is available. + ImGui_ImplEmscripten_Cursor_Help, // cursor next to a question mark - Help information is available. + ImGui_ImplEmscripten_Cursor_Pointer, // right hand with an index finger pointing up - The cursor is a pointer that indicates a link. Typically an image of a pointing hand. + ImGui_ImplEmscripten_Cursor_Progress, // cursor and hour glass - The program is busy in the background, but the user can still interact with the interface (in contrast to wait). + ImGui_ImplEmscripten_Cursor_Wait, // hour glass - The program is busy, and the user can't interact with the interface (in contrast to progress). Sometimes an image of an hourglass or a watch. // Selection - cell, // plus symbol - The table cell or set of cells can be selected. - crosshair, // crosshair - Cross cursor, often used to indicate selection in a bitmap. - text, // vertical i-beam - The text can be selected. Typically the shape of an I-beam. - vertical_text, // horizontal i-beam - The vertical text can be selected. Typically the shape of a sideways I-beam. + ImGui_ImplEmscripten_Cursor_Cell, // plus symbol - The table cell or set of cells can be selected. + ImGui_ImplEmscripten_Cursor_Crosshair, // crosshair - Cross cursor, often used to indicate selection in a bitmap. + ImGui_ImplEmscripten_Cursor_Text, // vertical i-beam - The text can be selected. Typically the shape of an I-beam. + ImGui_ImplEmscripten_Cursor_VerticalText, // horizontal i-beam - The vertical text can be selected. Typically the shape of a sideways I-beam. // Drag & drop - alias, // cursor next to a folder icon with a curved arrow pointing up and to the right - An alias or shortcut is to be created. - copy, // cursor next to a smaller folder icon with a plus sign - Something is to be copied. - move, // plus sign made of two thin lines, with small arrows facing out - Something is to be moved. - no_drop, // cursor next to circle with a line through it - An item may not be dropped at the current location. - not_allowed, // circle with a line through it - The requested action will not be carried out. - grab, // fully opened hand - Something can be grabbed (dragged to be moved). - grabbing, // closed hand - Something is being grabbed (dragged to be moved). + ImGui_ImplEmscripten_Cursor_Alias, // cursor next to a folder icon with a curved arrow pointing up and to the right - An alias or shortcut is to be created. + ImGui_ImplEmscripten_Cursor_Copy, // cursor next to a smaller folder icon with a plus sign - Something is to be copied. + ImGui_ImplEmscripten_Cursor_Move, // plus sign made of two thin lines, with small arrows facing out - Something is to be moved. + ImGui_ImplEmscripten_Cursor_NoDrop, // cursor next to circle with a line through it - An item may not be dropped at the current location. + ImGui_ImplEmscripten_Cursor_NotAllowed, // circle with a line through it - The requested action will not be carried out. + ImGui_ImplEmscripten_Cursor_Grab, // fully opened hand - Something can be grabbed (dragged to be moved). + ImGui_ImplEmscripten_Cursor_Grabbing, // closed hand - Something is being grabbed (dragged to be moved). // Resizing & scrolling - all_scroll, // dot with four triangles around it - Something can be scrolled in any direction (panned). - col_resize, // The item/column can be resized horizontally. Often rendered as arrows pointing left and right with a vertical bar separating them. - row_resize, // The item/row can be resized vertically. Often rendered as arrows pointing up and down with a horizontal bar separating them. - n_resize, // arrow pointing up - Some edge is to be moved. For example, the se-resize cursor is used when the movement starts from the south-east corner of the box. - e_resize, // arrow pointing right - s_resize, // arrow pointing down - w_resize, // arrow pointing left - ne_resize, // arrow pointing top-right - nw_resize, // arrow pointing top-left - se_resize, // arrow pointing bottom-right - sw_resize, // arrow pointing bottom-left - ew_resize, // arrow pointing left and right - Bidirectional resize cursor. - ns_resize, // arrow pointing up and down - nesw_resize, // arrow pointing both to the top-right and bottom-left - nwse_resize, // arrow pointing both to the top-left and bottom-right + ImGui_ImplEmscripten_Cursor_AllScroll, // dot with four triangles around it - Something can be scrolled in any direction (panned). + ImGui_ImplEmscripten_Cursor_ColResize, // The item/column can be resized horizontally. Often rendered as arrows pointing left and right with a vertical bar separating them. + ImGui_ImplEmscripten_Cursor_RowResize, // The item/row can be resized vertically. Often rendered as arrows pointing up and down with a horizontal bar separating them. + ImGui_ImplEmscripten_Cursor_NResize, // arrow pointing up - Some edge is to be moved. For example, the se-resize cursor is used when the movement starts from the south-east corner of the box. + ImGui_ImplEmscripten_Cursor_EResize, // arrow pointing right + ImGui_ImplEmscripten_Cursor_SResize, // arrow pointing down + ImGui_ImplEmscripten_Cursor_WResize, // arrow pointing left + ImGui_ImplEmscripten_Cursor_NEResize, // arrow pointing top-right + ImGui_ImplEmscripten_Cursor_NWResize, // arrow pointing top-left + ImGui_ImplEmscripten_Cursor_SEResize, // arrow pointing bottom-right + ImGui_ImplEmscripten_Cursor_SWResize, // arrow pointing bottom-left + ImGui_ImplEmscripten_Cursor_EWResize, // arrow pointing left and right - Bidirectional resize cursor. + ImGui_ImplEmscripten_Cursor_NSResize, // arrow pointing up and down + ImGui_ImplEmscripten_Cursor_NESWResize, // arrow pointing both to the top-right and bottom-left + ImGui_ImplEmscripten_Cursor_NWSEResize, // arrow pointing both to the top-left and bottom-right // Zooming - zoom_in, // magnifying glass with a plus sign - Something can be zoomed (magnified) in or out. - zoom_out, + ImGui_ImplEmscripten_Cursor_ZoomIn, // magnifying glass with a plus sign - Something can be zoomed (magnified) in or out. + ImGui_ImplEmscripten_Cursor_ZoomOut, // Special invalid value - invalid + ImGui_ImplEmscripten_Cursor_Invalid }; -} // namespace emscripten_browser_cursor_internal - -static void ImGui_ImplEmscripten_SetBrowserCursor(emscripten_browser_cursor_internal::cursor new_cursor); // set a new cursor from a cursor enum +static void ImGui_ImplEmscripten_SetBrowserCursor(ImGui_ImplEmscripten_Cursor new_cursor); // set a new cursor from a cursor enum static char* ImGui_ImplEmscripten_GetBrowserCursor(); // read the current cursor setting as an owned string, caller must free() static void ImGui_ImplEmscripten_SetBrowserCursor(char const* new_cursor); // set the cursor from an arbitrary string struct ImGui_ImplEmscripten_Data { float CssToImGuiScale = 1.0f; - emscripten_browser_cursor_internal::cursor CurrentCursor = emscripten_browser_cursor_internal::cursor::invalid; + ImGui_ImplEmscripten_Cursor CurrentCursor = ImGui_ImplEmscripten_Cursor_Invalid; char* CursorToRestore = nullptr; bool LastMouseDrawCursor = false; bool LastNoMouseCursorChange = false; @@ -139,7 +134,7 @@ void ImGui_ImplEmscripten_Init() io.BackendPlatformName = "imgui_impl_emscripten"; io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; - // set up initial display size values + // Set up initial display size values ImGui_ImplEmscripten_UpdateDisplayProperties( io, bd, @@ -228,7 +223,7 @@ void ImGui_ImplEmscripten_Init() scale = 80.0f; break; } - // TODO: make scrolling speeds configurable + // TODO: Make scrolling speeds configurable ImGuiIO& io = ImGui::GetIO(); io.AddMouseWheelEvent( -(float)wheel_event->deltaX * scale, @@ -264,7 +259,7 @@ void ImGui_ImplEmscripten_Init() case ImGuiKey_RightSuper: io.AddKeyEvent(ImGuiMod_Super, true); break; - // TODO: case ImGuiKey_Menu: do we want to do anything with this? + // TODO: case ImGuiKey_Menu: Do we want to do anything with this? case ImGuiKey_Tab: // consuming tab prevents the user tabbing to other parts of the browser interface outside the window content return io.WantCaptureKeyboard; // the event was consumed only if imgui wants to capture the keyboard case ImGuiKey_Enter: // consuming enter prevents the word "Enter" appearing in text input via the keypress callback @@ -381,7 +376,7 @@ void ImGui_ImplEmscripten_Init() } ); - // TODO: touch events + // TODO: Touch events } void ImGui_ImplEmscripten_Shutdown() @@ -404,7 +399,7 @@ void ImGui_ImplEmscripten_Shutdown() emscripten_set_focus_callback( EMSCRIPTEN_EVENT_TARGET_WINDOW, nullptr, false, nullptr); emscripten_set_focusin_callback( EMSCRIPTEN_EVENT_TARGET_WINDOW, nullptr, false, nullptr); emscripten_set_focusout_callback( EMSCRIPTEN_EVENT_TARGET_WINDOW, nullptr, false, nullptr); - // TODO: touch events + // TODO: Touch events if (bd->CursorToRestore != nullptr) { @@ -425,10 +420,10 @@ static void ImGui_ImplEmscripten_RestoreMouseCursor(ImGui_ImplEmscripten_Data* b ImGui_ImplEmscripten_SetBrowserCursor(bd->CursorToRestore); // restore the previous cursor state when leaving imgui cursor ownership free(bd->CursorToRestore); bd->CursorToRestore = nullptr; - bd->CurrentCursor = emscripten_browser_cursor_internal::cursor::invalid; // select an unused value for current cursor to force a set next time + bd->CurrentCursor = ImGui_ImplEmscripten_Cursor_Invalid; // select an unused value for current cursor to force a set next time } -static void ImGui_ImplEmscripten_SetMouseCursor(ImGui_ImplEmscripten_Data* bd, emscripten_browser_cursor_internal::cursor new_cursor) +static void ImGui_ImplEmscripten_SetMouseCursor(ImGui_ImplEmscripten_Data* bd, ImGui_ImplEmscripten_Cursor new_cursor) { if (new_cursor == bd->CurrentCursor) return; // don't do anything if the current cursor is already set if (bd->CursorToRestore == nullptr) bd->CursorToRestore = ImGui_ImplEmscripten_GetBrowserCursor(); // back up the existing cursor state when first taking cursor ownership @@ -446,7 +441,7 @@ static void ImGui_ImplEmscripten_UpdateMouseCursor(ImGui_ImplEmscripten_Data* bd { free(bd->CursorToRestore); bd->CursorToRestore = nullptr; - bd->CurrentCursor = emscripten_browser_cursor_internal::cursor::invalid; + bd->CurrentCursor = ImGui_ImplEmscripten_Cursor_Invalid; bd->LastMouseDrawCursor = false; bd->LastNoMouseCursorChange = true; } @@ -458,7 +453,7 @@ static void ImGui_ImplEmscripten_UpdateMouseCursor(ImGui_ImplEmscripten_Data* bd { if (bd->LastMouseDrawCursor) return; - ImGui_ImplEmscripten_SetMouseCursor(bd, emscripten_browser_cursor_internal::cursor::none); // hide the cursor for the entire window if imgui is handling cursor drawing - not just when imgui wants to capture the mouse + ImGui_ImplEmscripten_SetMouseCursor(bd, ImGui_ImplEmscripten_Cursor_None); // hide the cursor for the entire window if imgui is handling cursor drawing - not just when imgui wants to capture the mouse bd->LastMouseDrawCursor = true; } else @@ -475,34 +470,34 @@ static void ImGui_ImplEmscripten_UpdateMouseCursor(ImGui_ImplEmscripten_Data* bd switch (ImGui::GetMouseCursor()) { case ImGuiMouseCursor_None: - ImGui_ImplEmscripten_SetMouseCursor(bd, emscripten_browser_cursor_internal::cursor::none); + ImGui_ImplEmscripten_SetMouseCursor(bd, ImGui_ImplEmscripten_Cursor_None); break; case ImGuiMouseCursor_Arrow: - ImGui_ImplEmscripten_SetMouseCursor(bd, emscripten_browser_cursor_internal::cursor::cursor_default); + ImGui_ImplEmscripten_SetMouseCursor(bd, ImGui_ImplEmscripten_Cursor_Default); break; case ImGuiMouseCursor_TextInput: // When hovering over InputText, etc. - ImGui_ImplEmscripten_SetMouseCursor(bd, emscripten_browser_cursor_internal::cursor::text); + ImGui_ImplEmscripten_SetMouseCursor(bd, ImGui_ImplEmscripten_Cursor_Text); break; case ImGuiMouseCursor_ResizeAll: // (Unused by Dear ImGui functions) - ImGui_ImplEmscripten_SetMouseCursor(bd, emscripten_browser_cursor_internal::cursor::move); + ImGui_ImplEmscripten_SetMouseCursor(bd, ImGui_ImplEmscripten_Cursor_Move); break; case ImGuiMouseCursor_ResizeNS: // When hovering over a horizontal border - ImGui_ImplEmscripten_SetMouseCursor(bd, emscripten_browser_cursor_internal::cursor::ns_resize); + ImGui_ImplEmscripten_SetMouseCursor(bd, ImGui_ImplEmscripten_Cursor_NSResize); break; case ImGuiMouseCursor_ResizeEW: // When hovering over a vertical border or a column - ImGui_ImplEmscripten_SetMouseCursor(bd, emscripten_browser_cursor_internal::cursor::ew_resize); + ImGui_ImplEmscripten_SetMouseCursor(bd, ImGui_ImplEmscripten_Cursor_EWResize); break; case ImGuiMouseCursor_ResizeNESW: // When hovering over the bottom-left corner of a window - ImGui_ImplEmscripten_SetMouseCursor(bd, emscripten_browser_cursor_internal::cursor::nesw_resize); + ImGui_ImplEmscripten_SetMouseCursor(bd, ImGui_ImplEmscripten_Cursor_NESWResize); break; case ImGuiMouseCursor_ResizeNWSE: // When hovering over the bottom-right corner of a window - ImGui_ImplEmscripten_SetMouseCursor(bd, emscripten_browser_cursor_internal::cursor::nwse_resize); + ImGui_ImplEmscripten_SetMouseCursor(bd, ImGui_ImplEmscripten_Cursor_NWSEResize); break; case ImGuiMouseCursor_Hand: // (Unused by Dear ImGui functions. Use for e.g. hyperlinks) - ImGui_ImplEmscripten_SetMouseCursor(bd, emscripten_browser_cursor_internal::cursor::pointer); + ImGui_ImplEmscripten_SetMouseCursor(bd, ImGui_ImplEmscripten_Cursor_Pointer); break; case ImGuiMouseCursor_NotAllowed: // When hovering something with disallowed interaction. Usually a crossed circle. - ImGui_ImplEmscripten_SetMouseCursor(bd, emscripten_browser_cursor_internal::cursor::not_allowed); + ImGui_ImplEmscripten_SetMouseCursor(bd, ImGui_ImplEmscripten_Cursor_NotAllowed); break; } } @@ -529,41 +524,41 @@ static char* ImGui_ImplEmscripten_GetBrowserCursor() ); } -static void ImGui_ImplEmscripten_SetBrowserCursor(emscripten_browser_cursor_internal::cursor new_cursor) +static void ImGui_ImplEmscripten_SetBrowserCursor(ImGui_ImplEmscripten_Cursor new_cursor) { // Set the cursor according to the given enum // Note, implementations omitted for cursors not used by imgui. For full implementation, use https://github.com/Armchair-Software/emscripten-browser-cursor switch (new_cursor) { - case emscripten_browser_cursor_internal::cursor::none: + case ImGui_ImplEmscripten_Cursor_None: EM_ASM(document.body.style.cursor = 'none';); break; - case emscripten_browser_cursor_internal::cursor::cursor_default: + case ImGui_ImplEmscripten_Cursor_Default: default: EM_ASM(document.body.style.cursor = 'default';); break; - case emscripten_browser_cursor_internal::cursor::pointer: + case ImGui_ImplEmscripten_Cursor_Pointer: EM_ASM(document.body.style.cursor = 'pointer';); break; - case emscripten_browser_cursor_internal::cursor::text: + case ImGui_ImplEmscripten_Cursor_Text: EM_ASM(document.body.style.cursor = 'text';); break; - case emscripten_browser_cursor_internal::cursor::move: + case ImGui_ImplEmscripten_Cursor_Move: EM_ASM(document.body.style.cursor = 'move';); break; - case emscripten_browser_cursor_internal::cursor::not_allowed: + case ImGui_ImplEmscripten_Cursor_NotAllowed: EM_ASM(document.body.style.cursor = 'not-allowed';); break; - case emscripten_browser_cursor_internal::cursor::ew_resize: + case ImGui_ImplEmscripten_Cursor_EWResize: EM_ASM(document.body.style.cursor = 'ew-resize';); break; - case emscripten_browser_cursor_internal::cursor::ns_resize: + case ImGui_ImplEmscripten_Cursor_NSResize: EM_ASM(document.body.style.cursor = 'ns-resize';); break; - case emscripten_browser_cursor_internal::cursor::nesw_resize: + case ImGui_ImplEmscripten_Cursor_NESWResize: EM_ASM(document.body.style.cursor = 'nesw-resize';); break; - case emscripten_browser_cursor_internal::cursor::nwse_resize: + case ImGui_ImplEmscripten_Cursor_NWSEResize: EM_ASM(document.body.style.cursor = 'nwse-resize';); break; } @@ -595,7 +590,7 @@ static ImGuiStorage const& ImGui_ImplEmscripten_GetKeyTranslationStorage() }; static const ImGui_ImplEmscripten_KeyTranslation key_translations[] = { - // main character keys + // Main character keys { "Backquote", ImGuiKey_GraveAccent }, { "Backslash", ImGuiKey_Backslash }, { "BracketLeft", ImGuiKey_LeftBracket }, @@ -647,7 +642,7 @@ static ImGuiStorage const& ImGui_ImplEmscripten_GetKeyTranslationStorage() { "Semicolon", ImGuiKey_Semicolon }, { "Slash", ImGuiKey_Slash }, - // control keys + // Control keys { "AltLeft", ImGuiKey_LeftAlt }, { "AltRight", ImGuiKey_RightAlt }, { "Backspace", ImGuiKey_Backspace }, @@ -663,7 +658,7 @@ static ImGuiStorage const& ImGui_ImplEmscripten_GetKeyTranslationStorage() { "Space", ImGuiKey_Space }, { "Tab", ImGuiKey_Tab }, - // navigation key group + // Navigation key group { "Delete", ImGuiKey_Delete }, { "End", ImGuiKey_End }, //{ "Help", ImGuiKey_PrintScreen }, // Best approximation @@ -672,13 +667,13 @@ static ImGuiStorage const& ImGui_ImplEmscripten_GetKeyTranslationStorage() { "PageDown", ImGuiKey_PageDown }, { "PageUp", ImGuiKey_PageUp }, - // arrow key group + // Arrow key group { "ArrowDown", ImGuiKey_DownArrow }, { "ArrowLeft", ImGuiKey_LeftArrow }, { "ArrowRight", ImGuiKey_RightArrow }, { "ArrowUp", ImGuiKey_UpArrow }, - // browser key group + // Browser key group { "BrowserBack", ImGuiKey_AppBack }, // Pass through so the embedding app can decide //{ "BrowserFavorites", ImGuiKey_None }, // No direct mapping { "BrowserForward", ImGuiKey_AppForward }, // Pass through so the embedding app can decide @@ -687,7 +682,7 @@ static ImGuiStorage const& ImGui_ImplEmscripten_GetKeyTranslationStorage() //{ "BrowserSearch", ImGuiKey_None }, // No direct mapping //{ "BrowserStop", ImGuiKey_None }, // No direct mapping - // number pad group + // Number pad group { "NumLock", ImGuiKey_NumLock }, { "Numpad0", ImGuiKey_Keypad0 }, { "Numpad1", ImGuiKey_Keypad1 }, @@ -720,7 +715,7 @@ static ImGuiStorage const& ImGui_ImplEmscripten_GetKeyTranslationStorage() { "NumpadStar", ImGuiKey_KeypadMultiply }, // Same as multiply { "NumpadSubtract", ImGuiKey_KeypadSubtract }, - // top row key group + // Top row key group { "Escape", ImGuiKey_Escape }, { "F1", ImGuiKey_F1 }, { "F2", ImGuiKey_F2 }, @@ -752,7 +747,7 @@ static ImGuiStorage const& ImGui_ImplEmscripten_GetKeyTranslationStorage() { "ScrollLock", ImGuiKey_ScrollLock }, { "Pause", ImGuiKey_Pause }, - // clipboard/editing keys without direct mapping + // Clipboard/editing keys without direct mapping //{ "Abort", ImGuiKey_None }, //{ "Again", ImGuiKey_None }, //{ "Convert", ImGuiKey_None }, @@ -774,7 +769,7 @@ static ImGuiStorage const& ImGui_ImplEmscripten_GetKeyTranslationStorage() //{ "Lang2", ImGuiKey_None }, //{ "NonConvert", ImGuiKey_None }, - // media and launcher keys without direct mapping + // Media and launcher keys without direct mapping //{ "AudioVolumeDown", ImGuiKey_None }, //{ "AudioVolumeMute", ImGuiKey_None }, //{ "AudioVolumeUp", ImGuiKey_None }, @@ -787,7 +782,7 @@ static ImGuiStorage const& ImGui_ImplEmscripten_GetKeyTranslationStorage() //{ "MediaTrackNext", ImGuiKey_None }, //{ "MediaTrackPrevious", ImGuiKey_None }, - // system keys without direct mapping + // System keys without direct mapping //{ "Eject", ImGuiKey_None }, //{ "Hyper", ImGuiKey_None }, //{ "Power", ImGuiKey_None },