From 3f040300a76b2a4549a977b35c056d2509e20851 Mon Sep 17 00:00:00 2001 From: Tim Ebbeke Date: Thu, 27 Jul 2023 15:03:11 +0200 Subject: [PATCH 1/6] Unmade dependency code change. --- cmake/backend/emscripten.cmake | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmake/backend/emscripten.cmake b/cmake/backend/emscripten.cmake index 6f91554..b4f6966 100644 --- a/cmake/backend/emscripten.cmake +++ b/cmake/backend/emscripten.cmake @@ -110,6 +110,10 @@ function(nui_add_emscripten_target) ${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}-prejs ALL DEPENDS ${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_PREJS} ) + add_custom_target( + ${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}-parcel-dep + DEPENDS "${CMAKE_BINARY_DIR}/module_${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}/bin/index.html" + ) add_dependencies( ${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}-emscripten ${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}-prejs @@ -117,9 +121,9 @@ function(nui_add_emscripten_target) ) add_dependencies( ${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET} + ${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}-parcel-dep emscripten-setup ) - set_property(TARGET ${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET} PROPERTY OBJECT_DEPENDS "${CMAKE_BINARY_DIR}/module_${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}/bin/index.html") if (${TARGET_TYPE} STREQUAL "INTERFACE_LIBRARY") target_include_directories(${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET} INTERFACE ${CMAKE_BINARY_DIR}/include) From 5a8d8926302661b9bbcb37457eae4801198af1a8 Mon Sep 17 00:00:00 2001 From: Tim Ebbeke Date: Sat, 19 Aug 2023 11:50:31 +0200 Subject: [PATCH 2/6] Added navigate to files option. --- nui/include/nui/window.hpp | 9 +++++++++ nui/src/nui/backend/window.cpp | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/nui/include/nui/window.hpp b/nui/include/nui/window.hpp index 1023b5e..568e364 100644 --- a/nui/include/nui/window.hpp +++ b/nui/include/nui/window.hpp @@ -101,6 +101,15 @@ namespace Nui */ void navigate(const std::string& url); +#ifdef NUI_BACKEND + /** + * @brief Navigate to file. + * + * @param file path to an html file. + */ + void navigate(const std::filesystem::path& file); +#endif + /** * @brief Close the window and exit run. */ diff --git a/nui/src/nui/backend/window.cpp b/nui/src/nui/backend/window.cpp index debe334..64f4fa3 100644 --- a/nui/src/nui/backend/window.cpp +++ b/nui/src/nui/backend/window.cpp @@ -249,6 +249,13 @@ namespace Nui impl_->view.navigate(url); } //--------------------------------------------------------------------------------------------------------------------- + void Window::navigate(const std::filesystem::path& file) + { + using namespace std::string_literals; + std::scoped_lock lock{impl_->viewGuard}; + impl_->view.navigate("file://"s + file.string()); + } + //--------------------------------------------------------------------------------------------------------------------- void Window::run() { #ifdef _WIN32 From 0677cd7c88f03d3491a779704b006f5c85661b6d Mon Sep 17 00:00:00 2001 From: Tim Ebbeke Date: Sat, 19 Aug 2023 12:17:42 +0200 Subject: [PATCH 3/6] Removed problematic project statement in dependency files. --- cmake/dependencies/boostpp.cmake | 2 -- cmake/dependencies/describe.cmake | 2 -- cmake/dependencies/fmt.cmake | 2 -- cmake/dependencies/gtest.cmake | 2 -- cmake/dependencies/interval_tree.cmake | 2 -- cmake/dependencies/libcpppre.cmake | 2 -- cmake/dependencies/mp11.cmake | 2 -- cmake/dependencies/mplex.cmake | 2 -- cmake/dependencies/nlohmann_json.cmake | 2 -- cmake/dependencies/portable_file_dialog.cmake | 2 -- cmake/dependencies/roar.cmake | 2 -- cmake/dependencies/webview.cmake | 2 -- cmake/frontend/emscripten.cmake | 1 + 13 files changed, 1 insertion(+), 24 deletions(-) diff --git a/cmake/dependencies/boostpp.cmake b/cmake/dependencies/boostpp.cmake index f487c9b..e9f46ef 100644 --- a/cmake/dependencies/boostpp.cmake +++ b/cmake/dependencies/boostpp.cmake @@ -1,5 +1,3 @@ -project(boost_preprocessor-git NONE) - include(FetchContent) FetchContent_Declare( boost_preprocessor diff --git a/cmake/dependencies/describe.cmake b/cmake/dependencies/describe.cmake index 7f62a57..88b0fd4 100644 --- a/cmake/dependencies/describe.cmake +++ b/cmake/dependencies/describe.cmake @@ -1,5 +1,3 @@ -project(boost_describe-git NONE) - include(FetchContent) FetchContent_Declare( boost_describe diff --git a/cmake/dependencies/fmt.cmake b/cmake/dependencies/fmt.cmake index 3e29537..5da0e12 100644 --- a/cmake/dependencies/fmt.cmake +++ b/cmake/dependencies/fmt.cmake @@ -1,5 +1,3 @@ -project(fmt-git NONE) - include(FetchContent) FetchContent_Declare( fmt diff --git a/cmake/dependencies/gtest.cmake b/cmake/dependencies/gtest.cmake index caaee00..1e8e7a1 100644 --- a/cmake/dependencies/gtest.cmake +++ b/cmake/dependencies/gtest.cmake @@ -1,5 +1,3 @@ -project(fmt-git NONE) - include(FetchContent) FetchContent_Declare( gtest diff --git a/cmake/dependencies/interval_tree.cmake b/cmake/dependencies/interval_tree.cmake index c2f275e..28f85a9 100644 --- a/cmake/dependencies/interval_tree.cmake +++ b/cmake/dependencies/interval_tree.cmake @@ -1,5 +1,3 @@ -project(interval-tree-git NONE) - include(FetchContent) FetchContent_Declare( interval-tree diff --git a/cmake/dependencies/libcpppre.cmake b/cmake/dependencies/libcpppre.cmake index 40b3b9c..e9da49d 100644 --- a/cmake/dependencies/libcpppre.cmake +++ b/cmake/dependencies/libcpppre.cmake @@ -1,5 +1,3 @@ -project(libcpppre-git NONE) - include(FetchContent) FetchContent_Declare( libcpppre diff --git a/cmake/dependencies/mp11.cmake b/cmake/dependencies/mp11.cmake index 635c7eb..8bccd33 100644 --- a/cmake/dependencies/mp11.cmake +++ b/cmake/dependencies/mp11.cmake @@ -1,5 +1,3 @@ -project(boost_mp11-git NONE) - include(FetchContent) FetchContent_Declare( boost_mp11 diff --git a/cmake/dependencies/mplex.cmake b/cmake/dependencies/mplex.cmake index f103682..fe40a6f 100644 --- a/cmake/dependencies/mplex.cmake +++ b/cmake/dependencies/mplex.cmake @@ -1,5 +1,3 @@ -project(mplex-git NONE) - include(FetchContent) FetchContent_Declare( mplex diff --git a/cmake/dependencies/nlohmann_json.cmake b/cmake/dependencies/nlohmann_json.cmake index 640538d..eb7cb50 100644 --- a/cmake/dependencies/nlohmann_json.cmake +++ b/cmake/dependencies/nlohmann_json.cmake @@ -1,5 +1,3 @@ -project(nlohmann_json-git NONE) - include(FetchContent) FetchContent_Declare( nlohmann_json diff --git a/cmake/dependencies/portable_file_dialog.cmake b/cmake/dependencies/portable_file_dialog.cmake index becf9a7..37b7c69 100644 --- a/cmake/dependencies/portable_file_dialog.cmake +++ b/cmake/dependencies/portable_file_dialog.cmake @@ -1,5 +1,3 @@ -project(portable_file_dialogs-git NONE) - # TODO: fork not necessary i think include(FetchContent) FetchContent_Declare( diff --git a/cmake/dependencies/roar.cmake b/cmake/dependencies/roar.cmake index 2db5201..fc06904 100644 --- a/cmake/dependencies/roar.cmake +++ b/cmake/dependencies/roar.cmake @@ -1,5 +1,3 @@ -project(roar-git NONE) - include(FetchContent) FetchContent_Declare( roar diff --git a/cmake/dependencies/webview.cmake b/cmake/dependencies/webview.cmake index e3c13b7..d265331 100644 --- a/cmake/dependencies/webview.cmake +++ b/cmake/dependencies/webview.cmake @@ -1,5 +1,3 @@ -project(webview-git NONE) - if (UNIX) find_package(PkgConfig REQUIRED) pkg_check_modules( diff --git a/cmake/frontend/emscripten.cmake b/cmake/frontend/emscripten.cmake index 64aead5..033974e 100644 --- a/cmake/frontend/emscripten.cmake +++ b/cmake/frontend/emscripten.cmake @@ -23,6 +23,7 @@ function(nui_prepare_emscripten_target) add_custom_target( ${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_TARGET}-parcel COMMAND ${CMAKE_COMMAND} -E copy_directory ${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_STATIC} ${CMAKE_BINARY_DIR}/static + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_LIST_DIR}/../../nui/js ${CMAKE_BINARY_DIR}/node_modules/nui COMMAND ${CMAKE_BINARY_DIR}/node_modules/.bin/parcel build --dist-dir ${CMAKE_BINARY_DIR}/bin ${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_PARCEL_ARGS} WORKING_DIRECTORY ${CMAKE_BINARY_DIR} BYPRODUCTS ${CMAKE_BINARY_DIR}/bin/index.html From b3dc62202221ed134b0f6b3fdbad1b71b8aa05f1 Mon Sep 17 00:00:00 2001 From: Tim Ebbeke Date: Sat, 19 Aug 2023 12:24:17 +0200 Subject: [PATCH 4/6] Fixed dependency line for make. --- cmake/backend/emscripten.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/backend/emscripten.cmake b/cmake/backend/emscripten.cmake index b4f6966..7820f8e 100644 --- a/cmake/backend/emscripten.cmake +++ b/cmake/backend/emscripten.cmake @@ -112,7 +112,7 @@ function(nui_add_emscripten_target) ) add_custom_target( ${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}-parcel-dep - DEPENDS "${CMAKE_BINARY_DIR}/module_${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}/bin/index.html" + DEPENDS ${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}-emscripten ) add_dependencies( ${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}-emscripten From fb414c78d5b716ab6c2697bb9aa77b8f571fcf22 Mon Sep 17 00:00:00 2001 From: Tim Ebbeke Date: Sat, 19 Aug 2023 14:57:50 +0200 Subject: [PATCH 5/6] Added more path quotations. --- cmake/backend/emscripten.cmake | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cmake/backend/emscripten.cmake b/cmake/backend/emscripten.cmake index 7820f8e..500ffe9 100644 --- a/cmake/backend/emscripten.cmake +++ b/cmake/backend/emscripten.cmake @@ -31,7 +31,7 @@ else() "${CMAKE_BINARY_DIR}/_deps/emscripten-src/java/bin/java.exe" # not setting node, because global installed node might be preferred # "${CMAKE_BINARY_DIR}/_deps/emscripten-src/node/bin/node.exe" - WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/_deps/emscripten-src + WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/_deps/emscripten-src" ) endif() add_custom_target( @@ -92,13 +92,13 @@ function(nui_add_emscripten_target) -DCMAKE_CXX_STANDARD=23 -DCMAKE_EXPORT_COMPILE_COMMANDS=1 ${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_CMAKE_OPTIONS} - ${SOURCE_DIR} + "${SOURCE_DIR}" # copy over package.json and fill parcel options that do not exist on it - BUILD_COMMAND $ ${SOURCE_DIR}/package.json ${CMAKE_BINARY_DIR}/module_${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}/package.json "${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}" + BUILD_COMMAND $ "${SOURCE_DIR}/package.json" "${CMAKE_BINARY_DIR}/module_${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}/package.json" "${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}" # emscripten make COMMAND cmake --build "${CMAKE_BINARY_DIR}/module_${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}" --target ${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET} ${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}-parcel # convert result to header file containing the page - COMMAND $ ${ENABLE_BIN2HPP} ${CMAKE_BINARY_DIR}/module_${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}/bin/index.html ${CMAKE_BINARY_DIR}/include/index.hpp index + COMMAND $ ${ENABLE_BIN2HPP} "${CMAKE_BINARY_DIR}/module_${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}/bin/index.html" "${CMAKE_BINARY_DIR}/include/index.hpp" index BINARY_DIR "${CMAKE_BINARY_DIR}/module_${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}" BUILD_ALWAYS 1 BUILD_BYPRODUCTS "${CMAKE_BINARY_DIR}/module_${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}/bin/index.html" @@ -126,8 +126,8 @@ function(nui_add_emscripten_target) ) if (${TARGET_TYPE} STREQUAL "INTERFACE_LIBRARY") - target_include_directories(${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET} INTERFACE ${CMAKE_BINARY_DIR}/include) + target_include_directories(${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET} INTERFACE "${CMAKE_BINARY_DIR}/include") else() - target_include_directories(${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET} PRIVATE ${CMAKE_BINARY_DIR}/include) + target_include_directories(${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET} PRIVATE "${CMAKE_BINARY_DIR}/include") endif() endfunction() From a87260fd710b49e6735204bb2424cb99b11b3b9f Mon Sep 17 00:00:00 2001 From: Tim Ebbeke Date: Sat, 19 Aug 2023 14:58:33 +0200 Subject: [PATCH 6/6] Nui can now ship supporting javascript libraries. --- cmake/frontend/emscripten.cmake | 16 ++++++------ nui/js/make_resizeable.js | 46 +++++++++++++++++++++++++++++++++ tools/parcel_adapter/main.cpp | 7 +++++ 3 files changed, 61 insertions(+), 8 deletions(-) create mode 100644 nui/js/make_resizeable.js diff --git a/cmake/frontend/emscripten.cmake b/cmake/frontend/emscripten.cmake index 033974e..a674442 100644 --- a/cmake/frontend/emscripten.cmake +++ b/cmake/frontend/emscripten.cmake @@ -9,7 +9,7 @@ function(nui_prepare_emscripten_target) if (NOT NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_STATIC) get_target_property(NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_SOURCE_DIR ${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_TARGET} SOURCE_DIR) - set(NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_STATIC ${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_SOURCE_DIR}/static) + set(NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_STATIC "${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_SOURCE_DIR}/static") endif() nui_set_target_output_directories(${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_TARGET}) @@ -22,12 +22,12 @@ function(nui_prepare_emscripten_target) add_custom_target( ${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_TARGET}-parcel - COMMAND ${CMAKE_COMMAND} -E copy_directory ${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_STATIC} ${CMAKE_BINARY_DIR}/static - COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_LIST_DIR}/../../nui/js ${CMAKE_BINARY_DIR}/node_modules/nui - COMMAND ${CMAKE_BINARY_DIR}/node_modules/.bin/parcel build --dist-dir ${CMAKE_BINARY_DIR}/bin ${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_PARCEL_ARGS} - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - BYPRODUCTS ${CMAKE_BINARY_DIR}/bin/index.html - DEPENDS ${CMAKE_BINARY_DIR}/bin/index.js + COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../../nui/js" "${CMAKE_BINARY_DIR}/nui-js" + COMMAND ${CMAKE_COMMAND} -E copy_directory ${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_STATIC} "${CMAKE_BINARY_DIR}/static" + COMMAND "${CMAKE_BINARY_DIR}/node_modules/.bin/parcel" build --dist-dir "${CMAKE_BINARY_DIR}/bin" ${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_PARCEL_ARGS} + WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" + BYPRODUCTS "${CMAKE_BINARY_DIR}/bin/index.html" + DEPENDS "${CMAKE_BINARY_DIR}/bin/index.js" ) if (NOT NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_UNPACKED_MODE) @@ -38,7 +38,7 @@ function(nui_prepare_emscripten_target) set(SINGLE_FILE_STRING "") add_custom_target( ${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_TARGET}-copy-wasm - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/bin/index.wasm ${CMAKE_BINARY_DIR}/../bin/index.wasm + COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_BINARY_DIR}/bin/index.wasm" "${CMAKE_BINARY_DIR}/../bin/index.wasm" ) add_dependencies(${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_TARGET}-parcel ${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_TARGET}-copy-wasm) else() diff --git a/nui/js/make_resizeable.js b/nui/js/make_resizeable.js new file mode 100644 index 0000000..c3be30c --- /dev/null +++ b/nui/js/make_resizeable.js @@ -0,0 +1,46 @@ +// TODO: improve: + +const makeResizable = (element, borderSize, edge) => { + edge = edge || "right"; + + let pos; + const resize = (e) => { + const w = parseInt(getComputedStyle(element, '').width); + const h = parseInt(getComputedStyle(element, '').height); + + if (edge === "right") { + const dx = -(pos - e.x); + pos = e.x; + element.style.width = (w + dx) + "px"; + } + if (edge === "bottom") { + const dy = -(pos - e.y); + pos = e.y; + element.style.height = (h + dy) + "px"; + } + } + + element.addEventListener("mousedown", (e) => { + const w = parseInt(getComputedStyle(e.target, '').width); + const h = parseInt(getComputedStyle(e.target, '').height); + + if (edge == "right") { + if (w - e.x < borderSize + 1 /*rounding tolerance*/) { + pos = e.x; + document.addEventListener("mousemove", resize, false); + } + } + if (edge == "bottom") { + if (h - e.y < borderSize + 1 /*rounding tolerance*/) { + pos = e.y; + document.addEventListener("mousemove", resize, false); + } + } + }, false); + + document.addEventListener("mouseup", () => { + document.removeEventListener("mousemove", resize, false); + }, false); +} + +export default makeResizable; \ No newline at end of file diff --git a/tools/parcel_adapter/main.cpp b/tools/parcel_adapter/main.cpp index 0ef8071..badc0da 100644 --- a/tools/parcel_adapter/main.cpp +++ b/tools/parcel_adapter/main.cpp @@ -24,6 +24,11 @@ void disablePolyfillIfNotSet(nlohmann::json& alias, std::string_view aliasName) alias[aliasName] = false; } +void addNuiAlias(nlohmann::json& alias) +{ + alias["nui"] = "./nui-js"; +} + void createPackageJsonIfMissing(std::filesystem::path const& where, std::string const& targetName) { using nlohmann::json; @@ -88,6 +93,8 @@ int main(int argc, char** argv) if (!package.contains("alias")) package["alias"] = json::object(); + addNuiAlias(package["alias"]); + disablePolyfillIfNotSet(package["alias"], "assert"); disablePolyfillIfNotSet(package["alias"], "fs"); disablePolyfillIfNotSet(package["alias"], "buffer");