diff --git a/CMakeLists.txt b/CMakeLists.txt index d8cb41b..eadc581 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.16) -project(nui VERSION 0.1.0) +project(nui VERSION 0.9.0) set(NUI_SOURCE_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} CACHE INTERNAL "NUI source directory") diff --git a/cmake/backend/emscripten.cmake b/cmake/backend/emscripten.cmake index 74a2bfa..69c0272 100644 --- a/cmake/backend/emscripten.cmake +++ b/cmake/backend/emscripten.cmake @@ -21,6 +21,7 @@ else() WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/_deps/emscripten-src" ) endif() + add_custom_target( emscripten-setup DEPENDS ${CMAKE_BINARY_DIR}/_deps/emscripten-src/upstream/emscripten/.emscripten @@ -38,11 +39,35 @@ function(nui_add_emscripten_target) cmake_parse_arguments( NUI_ADD_EMSCRIPTEN_TARGET_ARGS - "" + "DISABLE_BIN2HPP;DISABLE_PARCEL_ADAPTER" "TARGET;PREJS;SOURCE_DIR" "CMAKE_OPTIONS" ${ARGN} - ) + ) + + if (NOT NUI_ADD_EMSCRIPTEN_TARGET_ARGS_DISABLE_BIN2HPP) + set(ENABLE_BIN2HPP ON) + else() + if (NUI_ADD_EMSCRIPTEN_TARGET_ARGS_DISABLE_BIN2HPP) + set(ENABLE_BIN2HPP OFF) + else() + if (${TARGET_TYPE} STREQUAL "INTERFACE_LIBRARY") + set(ENABLE_BIN2HPP OFF) + else() + set(ENABLE_BIN2HPP ON) + endif() + endif() + endif() + + if (NOT NUI_ADD_EMSCRIPTEN_TARGET_ARGS_DISABLE_PARCEL_ADAPTER) + set(ENABLE_PARCEL_ADAPTER ON) + else() + if (NUI_ADD_EMSCRIPTEN_TARGET_ARGS_DISABLE_PARCEL_ADAPTER) + set(ENABLE_PARCEL_ADAPTER OFF) + else() + set(ENABLE_PARCEL_ADAPTER ON) + endif() + endif() if (NOT NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET) message(FATAL_ERROR "You must provide a target to create a frontend pendant of.") @@ -63,11 +88,17 @@ function(nui_add_emscripten_target) string(REPLACE "-" "_" targetNormalized ${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}) message(STATUS "emcmake: ${EMCMAKE}") - - if (${TARGET_TYPE} STREQUAL "INTERFACE_LIBRARY") - set(ENABLE_BIN2HPP "no") + + if (ENABLE_PARCEL_ADAPTER) + set(BUILD_COMMAND BUILD_COMMAND $ "${SOURCE_DIR}/package.json" "${CMAKE_BINARY_DIR}/module_${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}/package.json" "${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}") + else() + set(BUILD_COMMAND BUILD_COMMAND cmake -E copy "${SOURCE_DIR}/package.json" "${CMAKE_BINARY_DIR}/module_${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}/package.json") + endif() + + if (ENABLE_BIN2HPP) + set(BIN2HPP_COMMAND COMMAND $ "on" "${CMAKE_BINARY_DIR}/module_${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}/bin/index.html" "${CMAKE_BINARY_DIR}/include/index.hpp" index) else() - set(ENABLE_BIN2HPP "yes") + set(BIN2HPP_COMMAND COMMAND cmake -E true) endif() include(ExternalProject) @@ -80,11 +111,11 @@ function(nui_add_emscripten_target) ${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_CMAKE_OPTIONS} "${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} # 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 + ${BIN2HPP_COMMAND} 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" diff --git a/cmake/dependencies/fmt.cmake b/cmake/dependencies/fmt.cmake index fc866bc..de31954 100644 --- a/cmake/dependencies/fmt.cmake +++ b/cmake/dependencies/fmt.cmake @@ -2,11 +2,13 @@ option(NUI_FETCH_FMT "Fetch fmt" ON) set(NUI_FMT_GIT_REPOSITORY "https://github.com/fmtlib/fmt.git" CACHE STRING "fmt git repository") set(NUI_FMT_GIT_TAG "5f774c0aed4af6494b412cd3883e0f09295bd79d" CACHE STRING "fmt git tag") -include(FetchContent) -FetchContent_Declare( - fmt - GIT_REPOSITORY ${NUI_FMT_GIT_REPOSITORY} - GIT_TAG ${NUI_FMT_GIT_TAG} -) +if (NUI_FETCH_FMT) + include(FetchContent) + FetchContent_Declare( + fmt + GIT_REPOSITORY ${NUI_FMT_GIT_REPOSITORY} + GIT_TAG ${NUI_FMT_GIT_TAG} + ) -FetchContent_MakeAvailable(fmt) \ No newline at end of file + FetchContent_MakeAvailable(fmt) +endif() \ No newline at end of file diff --git a/cmake/dependencies/webview.cmake b/cmake/dependencies/webview.cmake index 8713483..38cc2b7 100644 --- a/cmake/dependencies/webview.cmake +++ b/cmake/dependencies/webview.cmake @@ -8,7 +8,7 @@ endif() option(NUI_FETCH_WEBVIEW "Fetch webview" ON) set(NUI_WEBVIEW_REPOSITORY "https://github.com/5cript/webview.git" CACHE STRING "Webview repository") -set(NUI_WEBVIEW_TAG "c3e57c164a0751e5adb2ea45e1b5c308c3dbe716" CACHE STRING "Webview tag") +set(NUI_WEBVIEW_TAG "749f9dfbe140f5fd0be1cd53abcec7f05496cbc3" CACHE STRING "Webview tag") if (NUI_FETCH_WEBVIEW) include(FetchContent) @@ -21,8 +21,8 @@ if (NUI_FETCH_WEBVIEW) add_library(webview INTERFACE) add_custom_target( - webview-prep - COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/include" + webview-prep + COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/include" COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_BINARY_DIR}/_deps/webview_raw-src/webview.h" "${CMAKE_BINARY_DIR}/include/webview.h" COMMAND_EXPAND_LISTS ) @@ -73,8 +73,8 @@ if (NUI_FETCH_WEBVIEW) target_include_directories(webview INTERFACE "${CMAKE_BINARY_DIR}/_deps/webview_binary-src/build/native/include") target_link_directories( - webview - INTERFACE + webview + INTERFACE "${CMAKE_BINARY_DIR}/_deps/webview_binary-src/build/native/${WEBVIEW_DLL_SUBDIRECTORY}" "${CMAKE_BINARY_DIR}/lib" ) diff --git a/cmake/options.cmake b/cmake/options.cmake index b98253f..e4cf54a 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -1,6 +1,8 @@ option(NUI_USE_EXTERNAL_EMSCRIPTEN "Use external emscripten?" off) +option(NUI_NPM "set npm" "npm") option(NUI_ENABLE_TESTS "Enable test target" off) -option(NUI_NPM "set npm" "npm") option(NUI_BUILD_EXAMPLES "Build examples" off) -option(NUI_ENABLE_CLANG_TIDY "Enable clang-tidy" off) \ No newline at end of file +option(NUI_ENABLE_CLANG_TIDY "Enable clang-tidy" off) + +option(NUI_ENABLE_TOOLING_CONFIGURE "Enable patching and configuring of acorn and emscription? (default on)" on) \ No newline at end of file diff --git a/nui/include/nui/frontend/extensions/make_resizeable.hpp b/nui/include/nui/frontend/extensions/make_resizeable.hpp index 399bc5f..ece71e3 100644 --- a/nui/include/nui/frontend/extensions/make_resizeable.hpp +++ b/nui/include/nui/frontend/extensions/make_resizeable.hpp @@ -7,7 +7,8 @@ namespace Nui enum class ResizeableEdge { Right, - Bottom + Bottom, + Top }; void makeResizeable(Nui::val const& element, ResizeableEdge edge = ResizeableEdge::Right); diff --git a/nui/js/make_resizeable.ts b/nui/js/make_resizeable.ts index 35ee10d..1214b72 100644 --- a/nui/js/make_resizeable.ts +++ b/nui/js/make_resizeable.ts @@ -1,4 +1,4 @@ -const makeResizeable = (element: HTMLElement, borderSize: number, edge?: "right" | "bottom") => { +const makeResizeable = (element: HTMLElement, borderSize: number, edge?: "right" | "bottom" | "top") => { edge = edge || "right"; let pos: number; @@ -7,7 +7,7 @@ const makeResizeable = (element: HTMLElement, borderSize: number, edge?: "right" return (x: number, y: number, w: number, h: number) => { const dx = -(pos - x); pos = x; - element.style.width = (w + dx) + "px"; + element.style.width = (w + dx) + "px"; }; } else if (edge === "bottom") { @@ -17,6 +17,14 @@ const makeResizeable = (element: HTMLElement, borderSize: number, edge?: "right" element.style.height = (h + dy) + "px"; }; } + else if (edge === "top") { + // Assuming that the previous elements auto resize + return (x: number, y: number, w: number, h: number) => { + const dy = (pos - y); + pos = y; + element.style.height = (h + dy) + "px"; + } + } else { throw new Error("Invalid edge"); } @@ -50,6 +58,13 @@ const makeResizeable = (element: HTMLElement, borderSize: number, edge?: "right" document.addEventListener("mousemove", resize, false); } } + else if (edge == "top") { + const t = (e.target as HTMLElement).getBoundingClientRect().top; + if (e.y <= t + borderSize + 1 /*rounding tolerance*/) { + pos = e.y; + document.addEventListener("mousemove", resize, false); + } + } }, false); document.addEventListener("mouseup", () => { diff --git a/nui/src/nui/frontend/extensions/make_resizeable.cpp b/nui/src/nui/frontend/extensions/make_resizeable.cpp index 7420e70..4c0a971 100644 --- a/nui/src/nui/frontend/extensions/make_resizeable.cpp +++ b/nui/src/nui/frontend/extensions/make_resizeable.cpp @@ -4,9 +4,17 @@ namespace Nui { void makeResizeable(Nui::val const& element, ResizeableEdge edge) { - Nui::val::global("nui_lib")["makeResizeable"]( - element, - Nui::val{5}, - Nui::val{edge == ResizeableEdge::Right ? std::string{"right"} : std::string{"bottom"}}); + const auto edgeString = [&edge]() -> std::string { + if (edge == ResizeableEdge::Right) + return "right"; + else if (edge == ResizeableEdge::Bottom) + return "bottom"; + else if (edge == ResizeableEdge::Top) + return "top"; + else + return "right"; + }(); + + Nui::val::global("nui_lib")["makeResizeable"](element, Nui::val{5}, Nui::val{edgeString}); } } \ No newline at end of file