diff --git a/.github/workflows/ubuntu_20.yml b/.github/workflows/ubuntu_20.yml index 20404849..5259c8b6 100644 --- a/.github/workflows/ubuntu_20.yml +++ b/.github/workflows/ubuntu_20.yml @@ -16,7 +16,7 @@ jobs: steps: - uses: actions/checkout@v3 - - uses: awalsh128/cache-apt-pkgs-action@v1.3.0 + - uses: awalsh128/cache-apt-pkgs-action@latest with: packages: libwebkit2gtk-4.0-dev libcurl4-openssl-dev libcrypto++-dev ninja-build diff --git a/.github/workflows/ubuntu_22.yml b/.github/workflows/ubuntu_22.yml index 7c7077d9..21e62901 100644 --- a/.github/workflows/ubuntu_22.yml +++ b/.github/workflows/ubuntu_22.yml @@ -19,7 +19,7 @@ jobs: steps: - uses: actions/checkout@v3 - - uses: awalsh128/cache-apt-pkgs-action@v1.3.0 + - uses: awalsh128/cache-apt-pkgs-action@latest with: packages: libwebkit2gtk-4.0-dev libcurl4-openssl-dev libcrypto++-dev ninja-build diff --git a/cmake/backend/emscripten.cmake b/cmake/backend/emscripten.cmake index cf6986bb..c13496a2 100644 --- a/cmake/backend/emscripten.cmake +++ b/cmake/backend/emscripten.cmake @@ -130,6 +130,9 @@ function(nui_add_emscripten_target) set(PATCH_DOTENV_COMMAND COMMAND cmake -E true) endif() + get_target_property(TARGET_CXX_STANDARD ${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET} CXX_STANDARD) + message(STATUS "C++ standard of frontend subproject: ${TARGET_CXX_STANDARD}") + include(ExternalProject) ExternalProject_Add( "${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}-emscripten" @@ -137,6 +140,7 @@ function(nui_add_emscripten_target) # emscripten cmake with passed down Release/Debug build type CONFIGURE_COMMAND ${EMCMAKE} cmake + "-DCMAKE_CXX_STANDARD=${TARGET_CXX_STANDARD}" ${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_CMAKE_OPTIONS} "-DNUI_NPM=${NUI_NPM}" "-DNUI_NODE=${NUI_NODE}" diff --git a/cmake/frontend/emscripten.cmake b/cmake/frontend/emscripten.cmake index c1cd356d..f6b13933 100644 --- a/cmake/frontend/emscripten.cmake +++ b/cmake/frontend/emscripten.cmake @@ -2,7 +2,7 @@ function(nui_prepare_emscripten_target) cmake_parse_arguments( NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS "NO_INLINE;NO_INLINE_INJECT;LEAN_INDEX_HTML" - "TARGET;PREJS;STATIC;UNPACKED_MODE" + "TARGET;PREJS;STATIC;UNPACKED_MODE;CXX_STANDARD" "EMSCRIPTEN_LINK_OPTIONS;EMSCRIPTEN_COMPILE_OPTIONS;PARCEL_ARGS;NPM_INSTALL_ARGS;OBSERVED_BUNDLE_FILES" ${ARGN} ) @@ -28,9 +28,13 @@ function(nui_prepare_emscripten_target) set(NUI_LEAN_HTML "lean") endif() + if (NOT NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_CXX_STANDARD) + get_target_property(NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_CXX_STANDARD ${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_TARGET} CXX_STANDARD) + endif() + set(INLINER_COMMAND "") if (NOT NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_NO_INLINE) - nui_enable_inline(TARGET ${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_TARGET} RELATIVE_TO ${CMAKE_CURRENT_SOURCE_DIR}) + nui_enable_inline(TARGET ${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_TARGET} RELATIVE_TO ${CMAKE_CURRENT_SOURCE_DIR} CXX_STANDARD ${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_CXX_STANDARD}) if (NOT NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_NO_INLINE_INJECT) set(INLINER_COMMAND COMMAND ${NUI_INLINE_INJECTOR_TARGET_FILE} "${CMAKE_BINARY_DIR}/static/index.html" "${CMAKE_BINARY_DIR}/nui-inline/inline_imports.js" "${CMAKE_BINARY_DIR}/nui-inline/inline_imports.css" ${NUI_DEFER_INLINE_SCRIPTS_TAG} ${NUI_LEAN_HTML}) endif() diff --git a/nui/include/nui/event_system/listen.hpp b/nui/include/nui/event_system/listen.hpp index c87c2818..26b961c0 100644 --- a/nui/include/nui/event_system/listen.hpp +++ b/nui/include/nui/event_system/listen.hpp @@ -6,9 +6,20 @@ #include #include #include +#include namespace Nui { + namespace Detail + { + template + struct IsStdFunction : std::false_type + {}; + template + struct IsStdFunction> : std::true_type + {}; + } + template void listen(EventContext& eventContext, Observed const& obs, std::function onEvent) { @@ -22,6 +33,20 @@ namespace Nui obs.attachEvent(eventId); } + template + requires std::is_scalar_v + void listen(EventContext& eventContext, Observed const& obs, std::function onEvent) + { + const auto eventId = eventContext.registerEvent(Event{ + [obs = Detail::CopyableObservedWrap{obs}, onEvent = std::move(onEvent)](auto) { + return onEvent(obs.value()); + }, + []() { + return true; + }}); + obs.attachEvent(eventId); + } + template void listen(EventContext& eventContext, Observed const& obs, std::function onEvent) { @@ -31,10 +56,23 @@ namespace Nui }); } + template + requires std::is_scalar_v + void listen(EventContext& eventContext, Observed const& obs, std::function onEvent) + { + return listen(eventContext, obs, [onEvent = std::move(onEvent)](ValueT value) { + onEvent(value); + return true; + }); + } + template - void listen(EventContext& eventContext, Observed const& obs, FunctionT onEvent) + requires( + (std::invocable || std::invocable) && + !Detail::IsStdFunction::value) + void listen(EventContext& eventContext, Observed const& obs, FunctionT&& onEvent) { - return listen(eventContext, obs, std::function(std::move(onEvent))); + return listen(eventContext, obs, std::function(std::forward(onEvent))); } template @@ -55,6 +93,25 @@ namespace Nui obs->attachEvent(eventId); } + template + requires std::is_scalar_v + void listen( + EventContext& eventContext, + std::shared_ptr> const& obs, + std::function onEvent) + { + const auto eventId = eventContext.registerEvent(Event{ + [weak = std::weak_ptr>{obs}, onEvent = std::move(onEvent)](auto) { + if (auto obs = weak.lock(); obs) + return onEvent(obs->value()); + return false; + }, + [weak = std::weak_ptr>{obs}]() { + return !weak.expired(); + }}); + obs->attachEvent(eventId); + } + template void listen( EventContext& eventContext, @@ -67,21 +124,43 @@ namespace Nui }); } + template + requires std::is_scalar_v + void listen( + EventContext& eventContext, + std::shared_ptr> const& obs, + std::function onEvent) + { + return listen(eventContext, obs, [onEvent = std::move(onEvent)](ValueT value) { + onEvent(value); + return true; + }); + } + template - void listen(EventContext& eventContext, std::shared_ptr> const& obs, FunctionT onEvent) + requires( + (std::invocable || std::invocable) && + !Detail::IsStdFunction::value) + void listen(EventContext& eventContext, std::shared_ptr> const& obs, FunctionT&& onEvent) { - return listen(eventContext, obs, std::function(std::move(onEvent))); + return listen(eventContext, obs, std::function(std::forward(onEvent))); } template - void listen(std::shared_ptr> const& obs, FunctionT onEvent) + requires( + (std::invocable || std::invocable) && + !Detail::IsStdFunction::value) + void listen(std::shared_ptr> const& obs, FunctionT&& onEvent) { - return listen(globalEventContext, obs, std::function(std::move(onEvent))); + return listen(globalEventContext, obs, std::function(std::forward(onEvent))); } template - void listen(Observed const& obs, FunctionT onEvent) + requires( + (std::invocable || std::invocable) && + !Detail::IsStdFunction::value) + void listen(Observed const& obs, FunctionT&& onEvent) { - return listen(globalEventContext, obs, std::function(std::move(onEvent))); + return listen(globalEventContext, obs, std::function(std::forward(onEvent))); } } \ No newline at end of file diff --git a/nui/include/nui/frontend/utility/val_conversion.hpp b/nui/include/nui/frontend/utility/val_conversion.hpp index 8ddce54f..3db5b503 100644 --- a/nui/include/nui/frontend/utility/val_conversion.hpp +++ b/nui/include/nui/frontend/utility/val_conversion.hpp @@ -57,9 +57,9 @@ namespace Nui template Nui::val convertToVal(std::map const& map); template - Nui::val convertToVal(std::unique_ptr const& map); + Nui::val convertToVal(std::unique_ptr const& ptr); template - Nui::val convertToVal(std::shared_ptr const& map); + Nui::val convertToVal(std::shared_ptr const& ptr); inline Nui::val convertToVal(long long) { throw std::runtime_error("Cannot convert long long to val"); diff --git a/tools/inline_parser/test/CMakeLists.txt b/tools/inline_parser/test/CMakeLists.txt index 0a4091e4..b7681562 100644 --- a/tools/inline_parser/test/CMakeLists.txt +++ b/tools/inline_parser/test/CMakeLists.txt @@ -1,6 +1,6 @@ include(GoogleTest) -find_package(Boost REQUIRED) +find_package(Boost CONFIG REQUIRED) add_executable(inline_parser-tests tests.cpp