Skip to content

Commit

Permalink
Merge pull request #85 from NuiCpp/macos
Browse files Browse the repository at this point in the history
Basic Macos Support
  • Loading branch information
5cript authored Oct 22, 2023
2 parents d99b7ef + f527dcf commit 1c7fd6a
Show file tree
Hide file tree
Showing 19 changed files with 432 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
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__)
30 changes: 23 additions & 7 deletions nui/include/nui/window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ namespace Nui
*
* @param x xCoordinate
* @param y yCoordinate
* @param (MacOS only) use setFrameOrigin instead of setFrameTopLeftPoint (see apple doc)
*/
void setPosition(int x, int y);
void setPosition(int x, int y, bool useFrameOrigin = true);

/**
* @brief Center the window on the primary display. Requires size to be set first.
Expand Down Expand Up @@ -144,10 +145,14 @@ namespace Nui
*/
void terminate();

#ifndef APPLE
/**
* @brief Open the dev tools.
* @note This function is not available on MacOS.
*/
void openDevTools();
#endif

#ifdef NUI_BACKEND
/**
* @brief Bind a function into the web context. These will be available under globalThis.nui_rpc.backend.NAME
Expand Down Expand Up @@ -198,6 +203,13 @@ namespace Nui
*/
void eval(std::string const& js);

/**
* @brief Run javascript in the window.
*
* @param js
*/
void eval(char const* js);

/**
* @brief Run javascript in the window.
* @param file path to a javascript file.
Expand All @@ -218,32 +230,36 @@ namespace Nui
void init(std::filesystem::path const& file);

/**
* @brief Get a pointer to the underlying webview (ICoreWebView2* on windows and WEBKIT_WEB_VIEW on linux.
* @brief Get a pointer to the underlying webview (ICoreWebView2* on windows, WEBKIT_WEB_VIEW on linux, id on
* mac).
*
* @return void* Cast this pointer to the correct type depending on the OS.
*/
void* getNativeWebView();

/**
* @brief Get the Native Window object
* @brief Get a pointer to the underlying window (HWND on windows, GtkWidget* on linux, id on mac)
*
* @return void*
* @return void* Cast this pointer to the correct type depending on the OS.
*/
void* getNativeWindow();

/**
* @brief [LINUX ONLY] Enable/Disable console output from view in the console.
*/
void setConsoleOutput(bool active);

struct SchemeContext;
#endif

private:
void runInJavascriptThread(std::function<void()>&& func);

private:
public:
struct Implementation;
struct WindowsImplementation;
struct LinuxImplementation;
struct MacOsImplementation;

private:
std::shared_ptr<Implementation> impl_;
};
}
Loading

0 comments on commit 1c7fd6a

Please sign in to comment.