Skip to content

Commit aaa7f4f

Browse files
authored
Merge pull request #86 from NuiCpp/devel
Basic MacOS Support
2 parents 8eb1237 + 1c7fd6a commit aaa7f4f

File tree

21 files changed

+488
-91
lines changed

21 files changed

+488
-91
lines changed

.clang-format

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
#AlignAfterOpenBracket: BlockIndent
22
AlignAfterOpenBracket: AlwaysBreak
33
AlignEscapedNewlines: DontAlign
4-
AlignOperands: true
54
AlignTrailingComments: false
65
AllowAllArgumentsOnNextLine: true
76
AllowAllConstructorInitializersOnNextLine: false
8-
AllowAllParametersOfDeclarationOnNextLine: true
7+
AllowAllParametersOfDeclarationOnNextLine: false
98
AllowShortBlocksOnASingleLine: Empty
109
AllowShortCaseLabelsOnASingleLine: false
1110
AllowShortFunctionsOnASingleLine: None
1211
AllowShortIfStatementsOnASingleLine: Never
1312
AllowShortLambdasOnASingleLine: Empty
1413
AllowShortLoopsOnASingleLine: false
15-
AllowAllParametersOfDeclarationOnNextLine: false
1614
AlwaysBreakBeforeMultilineStrings: true
1715
AlwaysBreakTemplateDeclarations: Yes
1816
BasedOnStyle: LLVM
@@ -36,7 +34,6 @@ BraceWrapping:
3634
SplitEmptyFunction: false
3735
SplitEmptyNamespace: true
3836
SplitEmptyRecord: false
39-
AlignEscapedNewlines: DontAlign
4037
BreakConstructorInitializers: BeforeComma
4138
BreakInheritanceList: BeforeComma
4239
BreakStringLiterals: true
@@ -50,7 +47,7 @@ IndentCaseLabels: true
5047
IndentPPDirectives: AfterHash
5148
IndentWidth: 4
5249
Language: Cpp
53-
NamespaceIndentation: All
50+
NamespaceIndentation: All
5451
PointerAlignment: Left
5552
ReflowComments: true
5653
SortIncludes: false
@@ -69,4 +66,4 @@ UseTab: Never
6966
EmptyLineBeforeAccessModifier: Always
7067
IndentExternBlock: Indent
7168
IndentRequires: false
72-
AlignOperands: DontAlign
69+
AlignOperands: DontAlign

.github/workflows/macos_13.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: MacOS 13
2+
3+
on:
4+
push:
5+
branches: ["main", "devel", "macos"]
6+
pull_request:
7+
branches: ["main"]
8+
9+
env:
10+
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
11+
BUILD_TYPE: Debug
12+
13+
jobs:
14+
macos-13:
15+
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
16+
# You can convert this to a matrix build if you need cross-platform coverage.
17+
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
18+
runs-on: macos-13
19+
20+
steps:
21+
- uses: actions/checkout@v3
22+
- uses: actions/setup-python@v4
23+
with:
24+
python-version: "3.10"
25+
- uses: actions/setup-node@v3
26+
with:
27+
node-version: "20"
28+
29+
- name: Install Brew Dependencies
30+
run: brew install cmake llvm@16 boost git openssl@3 cryptopp curl ninja make
31+
32+
- name: Configure CMake
33+
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
34+
env:
35+
LDFLAGS: "-L/usr/local/opt/llvm@16/lib"
36+
CPPFLAGS: "-I/usr/local/opt/llvm@16/include -I/opt/homebrew/include"
37+
38+
- name: Build
39+
run: cmake --build ${{github.workspace}}/build/clang_${{env.BUILD_TYPE}} --config ${{env.BUILD_TYPE}}
40+
41+
- name: Test
42+
working-directory: ${{github.workspace}}/build/clang_${{env.BUILD_TYPE}}
43+
run: ./tests/nui-tests

cmake/backend/emscripten.cmake

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ else()
1616
"${CMAKE_BINARY_DIR}/_deps/emscripten-src/upstream/emscripten/.emscripten"
1717
"${CMAKE_BINARY_DIR}/_deps/binaryen_release-src"
1818
"${CMAKE_BINARY_DIR}/_deps/emscripten-src/java/bin/java.exe"
19-
# not setting node, because global installed node might be preferred
20-
# "${CMAKE_BINARY_DIR}/_deps/emscripten-src/node/bin/node.exe"
19+
# Not patching node
20+
# "${NUI_NODE}"
2121
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/_deps/emscripten-src"
2222
)
2323
endif()
@@ -89,13 +89,17 @@ function(nui_add_emscripten_target)
8989

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

92+
if (${TARGET_TYPE} STREQUAL "INTERFACE_LIBRARY")
93+
set(ENABLE_BIN2HPP "no")
94+
endif()
95+
9296
if (ENABLE_PARCEL_ADAPTER)
9397
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}")
9498
else()
9599
set(BUILD_COMMAND BUILD_COMMAND cmake -E copy "${SOURCE_DIR}/package.json" "${CMAKE_BINARY_DIR}/module_${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}/package.json")
96100
endif()
97101

98-
if (ENABLE_BIN2HPP)
102+
if (ENABLE_BIN2HPP AND ${ENABLE_BIN2HPP})
99103
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)
100104
else()
101105
set(BIN2HPP_COMMAND COMMAND cmake -E true)
@@ -109,6 +113,8 @@ function(nui_add_emscripten_target)
109113
CONFIGURE_COMMAND
110114
${EMCMAKE} cmake
111115
${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_CMAKE_OPTIONS}
116+
"-DNUI_NPM=${NUI_NPM}"
117+
"-DNUI_NODE=${NUI_NODE}"
112118
-DNUI_INLINE_EXTRACTOR_TARGET_FILE=$<TARGET_FILE:inline-parser>
113119
-DNUI_INLINE_INJECTOR_TARGET_FILE=$<TARGET_FILE:inline-injector>
114120
-DNUI_MODULE_BUILD_DIR=${CMAKE_BINARY_DIR}/module_${NUI_ADD_EMSCRIPTEN_TARGET_ARGS_TARGET}

cmake/dependencies/webview.cmake

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
if (UNIX)
1+
if (APPLE)
2+
elseif (UNIX)
23
find_package(PkgConfig REQUIRED)
34
pkg_search_module(
45
webkit2 REQUIRED webkit2gtk-4.0 webkit2gtk-4.1 webkit2gtk
@@ -47,6 +48,13 @@ if (NUI_FETCH_WEBVIEW)
4748
WebView2Loader.lib
4849
>
4950
)
51+
target_link_libraries(
52+
webview
53+
INTERFACE
54+
$<$<PLATFORM_ID:Darwin>:
55+
"-framework WebKit"
56+
>
57+
)
5058

5159
if (WIN32)
5260
option(NUI_FETCH_WEBVIEW_BINARY "Fetch webview binary" ON)

cmake/frontend/emscripten.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function(nui_prepare_emscripten_target)
2828

2929
add_custom_target(
3030
${NUI_PREPARE_EMSCRIPTEN_TARGET_ARGS_TARGET}-npm-install
31-
COMMAND npm install
31+
COMMAND ${NUI_NPM} install
3232
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
3333
)
3434

cmake/options.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
option(NUI_USE_EXTERNAL_EMSCRIPTEN "Use external emscripten?" off)
2-
option(NUI_NPM "set npm" "npm")
32

43
option(NUI_ENABLE_TESTS "Enable test target" off)
4+
set(NUI_NPM "npm" CACHE STRING "Path to npm (node package manager)")
5+
set(NUI_NODE "node" CACHE STRING "Path to node")
56
option(NUI_BUILD_EXAMPLES "Build examples" off)
67
option(NUI_ENABLE_CLANG_TIDY "Enable clang-tidy" off)
78

nui/include/nui/data_structures/selectables_registry.hpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,11 +395,13 @@ namespace Nui
395395
auto const id = selected.id;
396396
if (callback(selected))
397397
{
398-
++itemCount_;
399-
++result;
400398
auto entry = findItem(id);
401399
if (entry != std::end(items_))
400+
{
401+
++itemCount_;
402+
++result;
402403
entry->item = std::move(const_cast<ItemWithId&>(selected).item);
404+
}
403405
}
404406
}
405407
selected_.clear();
@@ -423,10 +425,12 @@ namespace Nui
423425

424426
if (callback(*iter))
425427
{
426-
++itemCount_;
427428
auto entry = findItem(id);
428429
if (entry != std::end(items_))
430+
{
431+
++itemCount_;
429432
entry->item = std::move(const_cast<ItemWithId&>(*iter).item);
433+
}
430434
return true;
431435
}
432436
selected_.erase(iter);
@@ -435,6 +439,14 @@ namespace Nui
435439
return false;
436440
}
437441

442+
void clear()
443+
{
444+
items_.clear();
445+
selected_.clear();
446+
itemCount_ = 0;
447+
id_ = 0;
448+
}
449+
438450
/**
439451
* @brief Get iterator to item with id.
440452
*

nui/include/nui/frontend/attributes/impl/attribute_factory.hpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,52 @@ namespace Nui::Attributes
336336
char const* name_;
337337
};
338338

339+
class EventFactory
340+
{
341+
public:
342+
explicit constexpr EventFactory(char const* name)
343+
: name_{name}
344+
{}
345+
346+
// Dont use this class like a value
347+
EventFactory(EventFactory const&) = delete;
348+
EventFactory(EventFactory&&) = delete;
349+
EventFactory& operator=(EventFactory const&) = delete;
350+
EventFactory& operator=(EventFactory&&) = delete;
351+
352+
constexpr char const* name() const
353+
{
354+
return name_;
355+
};
356+
357+
Attribute operator=(std::function<void()> func) const
358+
{
359+
return Attribute{
360+
[name = name(), func = std::move(func)](Dom::ChildlessElement& element) {
361+
element.addEventListener(name, [func](Nui::val) {
362+
func();
363+
globalEventContext.executeActiveEventsImmediately();
364+
});
365+
},
366+
};
367+
}
368+
369+
Attribute operator=(std::function<void(Nui::val)> func) const
370+
{
371+
return Attribute{
372+
[name = name(), func = std::move(func)](Dom::ChildlessElement& element) {
373+
element.addEventListener(name, [func](Nui::val val) {
374+
func(std::move(val));
375+
globalEventContext.executeActiveEventsImmediately();
376+
});
377+
},
378+
};
379+
}
380+
381+
private:
382+
char const* name_;
383+
};
384+
339385
inline namespace Literals
340386
{
341387
constexpr AttributeFactory operator""_attr(char const* name, std::size_t)
@@ -346,6 +392,10 @@ namespace Nui::Attributes
346392
{
347393
return PropertyFactory{name};
348394
}
395+
constexpr EventFactory operator""_event(char const* name, std::size_t)
396+
{
397+
return EventFactory{name};
398+
}
349399
}
350400
}
351401

nui/include/nui/frontend/dom/childless_element.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ namespace Nui::Dom
7878
element_.set(Nui::val{std::string{key}}, Nui::val{static_cast<double>(value)});
7979
}
8080

81+
void addEventListener(std::string_view event, std::invocable<Nui::val> auto&& callback)
82+
{
83+
element_.call<void>(
84+
"addEventListener", Nui::val{std::string{event}}, Nui::bind(callback, std::placeholders::_1));
85+
}
86+
8187
// TODO: more overloads?
8288
void setAttribute(std::string_view key, std::string const& value)
8389
{

nui/include/nui/frontend/event_system/event_context.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ namespace Nui
7272
{
7373
impl_->eventRegistry().cleanInvalidEvents();
7474
}
75+
void reset()
76+
{
77+
impl_->eventRegistry().clear();
78+
}
7579

7680
private:
7781
std::shared_ptr<EventEngine> impl_;

nui/include/nui/frontend/event_system/event_registry.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ namespace Nui
8585
registry_.erase(id);
8686
}
8787

88+
void clear()
89+
{
90+
registry_.clear();
91+
afterEffects_.clear();
92+
}
93+
8894
private:
8995
RegistryType registry_;
9096
RegistryType afterEffects_;

nui/include/nui/rpc.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#pragma once
2+
3+
#include <nui/core.hpp>
4+
5+
#ifdef NUI_BACKEND
6+
# include <nui/backend/rpc_hub.hpp>
7+
#elif defined(NUI_FRONTEND)
8+
# include <nui/frontend/rpc_client.hpp>
9+
#endif

nui/include/nui/utility/scope_exit.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#pragma once
22

3+
#include <nui/utility/unique_identifier.hpp>
4+
35
#include <functional>
46
#include <utility>
57

@@ -26,4 +28,18 @@ namespace Nui
2628
};
2729
template <typename T>
2830
ScopeExit(T) -> ScopeExit<T>;
31+
32+
namespace Detail
33+
{
34+
struct MakeScopeExitImpl
35+
{
36+
template <typename FunctionT>
37+
auto operator->*(FunctionT&& fn) const
38+
{
39+
return ScopeExit<FunctionT>(std::forward<FunctionT>(fn));
40+
}
41+
};
42+
}
43+
44+
#define NUI_ON_SCOPE_EXIT auto NUI_UNIQUE_IDENTIFIER = ::Nui::Detail::MakeScopeExitImpl{}->*[&]
2945
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#pragma once
2+
3+
#include <boost/preprocessor/cat.hpp>
4+
5+
#define NUI_UNIQUE_IDENTIFIER BOOST_PP_CAT(nui_unique_identifier_, __COUNTER__)

0 commit comments

Comments
 (0)