Skip to content

Commit

Permalink
Merge pull request #86 from NuiCpp/devel
Browse files Browse the repository at this point in the history
Basic MacOS Support
  • Loading branch information
5cript authored Oct 22, 2023
2 parents 8eb1237 + 1c7fd6a commit aaa7f4f
Show file tree
Hide file tree
Showing 21 changed files with 488 additions and 91 deletions.
9 changes: 3 additions & 6 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
#AlignAfterOpenBracket: BlockIndent
AlignAfterOpenBracket: AlwaysBreak
AlignEscapedNewlines: DontAlign
AlignOperands: true
AlignTrailingComments: false
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: Empty
AllowShortLoopsOnASingleLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
BasedOnStyle: LLVM
Expand All @@ -36,7 +34,6 @@ BraceWrapping:
SplitEmptyFunction: false
SplitEmptyNamespace: true
SplitEmptyRecord: false
AlignEscapedNewlines: DontAlign
BreakConstructorInitializers: BeforeComma
BreakInheritanceList: BeforeComma
BreakStringLiterals: true
Expand All @@ -50,7 +47,7 @@ IndentCaseLabels: true
IndentPPDirectives: AfterHash
IndentWidth: 4
Language: Cpp
NamespaceIndentation: All
NamespaceIndentation: All
PointerAlignment: Left
ReflowComments: true
SortIncludes: false
Expand All @@ -69,4 +66,4 @@ UseTab: Never
EmptyLineBeforeAccessModifier: Always
IndentExternBlock: Indent
IndentRequires: false
AlignOperands: DontAlign
AlignOperands: DontAlign
43 changes: 43 additions & 0 deletions .github/workflows/macos_13.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: MacOS 13

on:
push:
branches: ["main", "devel", "macos"]
pull_request:
branches: ["main"]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Debug

jobs:
macos-13:
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: macos-13

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.10"
- uses: actions/setup-node@v3
with:
node-version: "20"

- name: Install Brew Dependencies
run: brew install cmake llvm@16 boost git openssl@3 cryptopp curl ninja make

- name: Configure CMake
run: cmake -B ${{github.workspace}}/build/clang_${{env.BUILD_TYPE}} -G"Ninja" -DNUI_ENABLE_TESTS=on -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DNUI_BUILD_EXAMPLES=on -DCMAKE_CXX_EXTENSIONS=on -DCMAKE_CXX_COMPILER=/usr/local/opt/llvm@16/bin/clang++ -DCMAKE_C_COMPILER=/usr/local/opt/llvm@16/bin/clang -DNUI_NPM=npm -DNUI_NODE=node -DCMAKE_CXX_STANDARD=20
env:
LDFLAGS: "-L/usr/local/opt/llvm@16/lib"
CPPFLAGS: "-I/usr/local/opt/llvm@16/include -I/opt/homebrew/include"

- name: Build
run: cmake --build ${{github.workspace}}/build/clang_${{env.BUILD_TYPE}} --config ${{env.BUILD_TYPE}}

- name: Test
working-directory: ${{github.workspace}}/build/clang_${{env.BUILD_TYPE}}
run: ./tests/nui-tests
12 changes: 9 additions & 3 deletions cmake/backend/emscripten.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ else()
"${CMAKE_BINARY_DIR}/_deps/emscripten-src/upstream/emscripten/.emscripten"
"${CMAKE_BINARY_DIR}/_deps/binaryen_release-src"
"${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"
# Not patching node
# "${NUI_NODE}"
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/_deps/emscripten-src"
)
endif()
Expand Down Expand Up @@ -89,13 +89,17 @@ function(nui_add_emscripten_target)

message(STATUS "emcmake: ${EMCMAKE}")

if (${TARGET_TYPE} STREQUAL "INTERFACE_LIBRARY")
set(ENABLE_BIN2HPP "no")
endif()

if (ENABLE_PARCEL_ADAPTER)
set(BUILD_COMMAND BUILD_COMMAND $<TARGET_FILE:parcel-adapter> "${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)
if (ENABLE_BIN2HPP AND ${ENABLE_BIN2HPP})
set(BIN2HPP_COMMAND COMMAND $<TARGET_FILE:bin2hpp> "on" "${CMAKE_BINARY_DIR}/module_${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}/bin/index.html" "${CMAKE_BINARY_DIR}/include/index.hpp" index)
else()
set(BIN2HPP_COMMAND COMMAND cmake -E true)
Expand All @@ -109,6 +113,8 @@ function(nui_add_emscripten_target)
CONFIGURE_COMMAND
${EMCMAKE} cmake
${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_CMAKE_OPTIONS}
"-DNUI_NPM=${NUI_NPM}"
"-DNUI_NODE=${NUI_NODE}"
-DNUI_INLINE_EXTRACTOR_TARGET_FILE=$<TARGET_FILE:inline-parser>
-DNUI_INLINE_INJECTOR_TARGET_FILE=$<TARGET_FILE:inline-injector>
-DNUI_MODULE_BUILD_DIR=${CMAKE_BINARY_DIR}/module_${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}
Expand Down
10 changes: 9 additions & 1 deletion cmake/dependencies/webview.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
if (UNIX)
if (APPLE)
elseif (UNIX)
find_package(PkgConfig REQUIRED)
pkg_search_module(
webkit2 REQUIRED webkit2gtk-4.0 webkit2gtk-4.1 webkit2gtk
Expand Down Expand Up @@ -47,6 +48,13 @@ if (NUI_FETCH_WEBVIEW)
WebView2Loader.lib
>
)
target_link_libraries(
webview
INTERFACE
$<$<PLATFORM_ID:Darwin>:
"-framework WebKit"
>
)

if (WIN32)
option(NUI_FETCH_WEBVIEW_BINARY "Fetch webview binary" ON)
Expand Down
2 changes: 1 addition & 1 deletion cmake/frontend/emscripten.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function(nui_prepare_emscripten_target)

add_custom_target(
${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_TARGET}-npm-install
COMMAND npm install
COMMAND ${NUI_NPM} install
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)

Expand Down
3 changes: 2 additions & 1 deletion cmake/options.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +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)
set(NUI_NPM "npm" CACHE STRING "Path to npm (node package manager)")
set(NUI_NODE "node" CACHE STRING "Path to node")
option(NUI_BUILD_EXAMPLES "Build examples" off)
option(NUI_ENABLE_CLANG_TIDY "Enable clang-tidy" off)

Expand Down
18 changes: 15 additions & 3 deletions nui/include/nui/data_structures/selectables_registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,13 @@ namespace Nui
auto const id = selected.id;
if (callback(selected))
{
++itemCount_;
++result;
auto entry = findItem(id);
if (entry != std::end(items_))
{
++itemCount_;
++result;
entry->item = std::move(const_cast<ItemWithId&>(selected).item);
}
}
}
selected_.clear();
Expand All @@ -423,10 +425,12 @@ namespace Nui

if (callback(*iter))
{
++itemCount_;
auto entry = findItem(id);
if (entry != std::end(items_))
{
++itemCount_;
entry->item = std::move(const_cast<ItemWithId&>(*iter).item);
}
return true;
}
selected_.erase(iter);
Expand All @@ -435,6 +439,14 @@ namespace Nui
return false;
}

void clear()
{
items_.clear();
selected_.clear();
itemCount_ = 0;
id_ = 0;
}

/**
* @brief Get iterator to item with id.
*
Expand Down
50 changes: 50 additions & 0 deletions nui/include/nui/frontend/attributes/impl/attribute_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,52 @@ namespace Nui::Attributes
char const* name_;
};

class EventFactory
{
public:
explicit constexpr EventFactory(char const* name)
: name_{name}
{}

// Dont use this class like a value
EventFactory(EventFactory const&) = delete;
EventFactory(EventFactory&&) = delete;
EventFactory& operator=(EventFactory const&) = delete;
EventFactory& operator=(EventFactory&&) = delete;

constexpr char const* name() const
{
return name_;
};

Attribute operator=(std::function<void()> func) const
{
return Attribute{
[name = name(), func = std::move(func)](Dom::ChildlessElement& element) {
element.addEventListener(name, [func](Nui::val) {
func();
globalEventContext.executeActiveEventsImmediately();
});
},
};
}

Attribute operator=(std::function<void(Nui::val)> func) const
{
return Attribute{
[name = name(), func = std::move(func)](Dom::ChildlessElement& element) {
element.addEventListener(name, [func](Nui::val val) {
func(std::move(val));
globalEventContext.executeActiveEventsImmediately();
});
},
};
}

private:
char const* name_;
};

inline namespace Literals
{
constexpr AttributeFactory operator""_attr(char const* name, std::size_t)
Expand All @@ -346,6 +392,10 @@ namespace Nui::Attributes
{
return PropertyFactory{name};
}
constexpr EventFactory operator""_event(char const* name, std::size_t)
{
return EventFactory{name};
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions nui/include/nui/frontend/dom/childless_element.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ namespace Nui::Dom
element_.set(Nui::val{std::string{key}}, Nui::val{static_cast<double>(value)});
}

void addEventListener(std::string_view event, std::invocable<Nui::val> auto&& callback)
{
element_.call<void>(
"addEventListener", Nui::val{std::string{event}}, Nui::bind(callback, std::placeholders::_1));
}

// TODO: more overloads?
void setAttribute(std::string_view key, std::string const& value)
{
Expand Down
4 changes: 4 additions & 0 deletions nui/include/nui/frontend/event_system/event_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ namespace Nui
{
impl_->eventRegistry().cleanInvalidEvents();
}
void reset()
{
impl_->eventRegistry().clear();
}

private:
std::shared_ptr<EventEngine> impl_;
Expand Down
6 changes: 6 additions & 0 deletions nui/include/nui/frontend/event_system/event_registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ namespace Nui
registry_.erase(id);
}

void clear()
{
registry_.clear();
afterEffects_.clear();
}

private:
RegistryType registry_;
RegistryType afterEffects_;
Expand Down
9 changes: 9 additions & 0 deletions nui/include/nui/rpc.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include <nui/core.hpp>

#ifdef NUI_BACKEND
# include <nui/backend/rpc_hub.hpp>
#elif defined(NUI_FRONTEND)
# include <nui/frontend/rpc_client.hpp>
#endif
16 changes: 16 additions & 0 deletions nui/include/nui/utility/scope_exit.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <nui/utility/unique_identifier.hpp>

#include <functional>
#include <utility>

Expand All @@ -26,4 +28,18 @@ namespace Nui
};
template <typename T>
ScopeExit(T) -> ScopeExit<T>;

namespace Detail
{
struct MakeScopeExitImpl
{
template <typename FunctionT>
auto operator->*(FunctionT&& fn) const
{
return ScopeExit<FunctionT>(std::forward<FunctionT>(fn));
}
};
}

#define NUI_ON_SCOPE_EXIT auto NUI_UNIQUE_IDENTIFIER = ::Nui::Detail::MakeScopeExitImpl{}->*[&]
}
5 changes: 5 additions & 0 deletions nui/include/nui/utility/unique_identifier.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#include <boost/preprocessor/cat.hpp>

#define NUI_UNIQUE_IDENTIFIER BOOST_PP_CAT(nui_unique_identifier_, __COUNTER__)
Loading

0 comments on commit aaa7f4f

Please sign in to comment.