File tree Expand file tree Collapse file tree 8 files changed +221
-68
lines changed
include/sourcemeta/native Expand file tree Collapse file tree 8 files changed +221
-68
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ function(add_example)
27
27
add_custom_target (${EXAMPLE_NAME} _build
28
28
COMMAND "${CMAKE_COMMAND} "
29
29
--build "${EXAMPLE_BINARY_DIR} "
30
+ WORKING_DIRECTORY "${EXAMPLE_BINARY_DIR} "
30
31
COMMENT "Building ${EXAMPLE_NAME} example"
31
32
)
32
33
add_dependencies (${EXAMPLE_NAME} _build ${EXAMPLE_NAME} _configure )
@@ -36,16 +37,19 @@ function(add_example)
36
37
if (EXAMPLE_TYPE STREQUAL "desktop" )
37
38
add_custom_target (${EXAMPLE_NAME} _run
38
39
COMMAND "${EXAMPLE_BINARY_DIR} /${EXAMPLE_APP_NAME} .app/Contents/MacOS/${EXAMPLE_APP_NAME} "
40
+ WORKING_DIRECTORY "${EXAMPLE_BINARY_DIR} "
39
41
COMMENT "Running ${EXAMPLE_NAME} example (bundle)" )
40
42
else ()
41
43
add_custom_target (${EXAMPLE_NAME} _run
42
44
COMMAND "${EXAMPLE_BINARY_DIR} /${EXAMPLE_APP_NAME} " --foo bar
45
+ WORKING_DIRECTORY "${EXAMPLE_BINARY_DIR} "
43
46
COMMENT "Running ${EXAMPLE_NAME} example (executable)" )
44
47
endif ()
45
48
add_dependencies (${EXAMPLE_NAME} _run ${EXAMPLE_NAME} _build )
46
49
elseif (WIN32 )
47
50
add_custom_target (${EXAMPLE_NAME} _run
48
51
COMMAND "${CMAKE_CURRENT_BINARY_DIR} /${EXAMPLE_NAME} /Debug/${EXAMPLE_APP_NAME} .exe"
52
+ WORKING_DIRECTORY "${EXAMPLE_BINARY_DIR} "
49
53
COMMENT "Running ${EXAMPLE_NAME} example (Windows)" )
50
54
add_dependencies (${EXAMPLE_NAME} _run ${EXAMPLE_NAME} _build )
51
55
endif ()
Original file line number Diff line number Diff line change 1
1
function (native_add_app )
2
- cmake_parse_arguments (NATIVE "" "TARGET;PLATFORM" "" ${ARGN} )
2
+ cmake_parse_arguments (NATIVE "" "TARGET;PLATFORM" "ASSETS " ${ARGN} )
3
3
4
4
if (APPLE )
5
5
_native_add_app_apple (${ARGN} )
@@ -14,6 +14,27 @@ function(native_add_app)
14
14
"NATIVE_${NATIVE_PLATFORM_UPPER} =1" )
15
15
endfunction ()
16
16
17
+ function (native_add_assets )
18
+ cmake_parse_arguments (NATIVE "" "TARGET" "ASSETS" ${ARGN} )
19
+
20
+ if (NOT NATIVE_TARGET )
21
+ message (FATAL_ERROR "You must specify a target" )
22
+ endif ()
23
+
24
+ if (NOT NATIVE_ASSETS )
25
+ message (FATAL_ERROR "You must specify assets" )
26
+ endif ()
27
+
28
+ foreach (asset IN LISTS NATIVE_ASSETS )
29
+ add_custom_command (
30
+ TARGET ${NATIVE_TARGET}
31
+ POST_BUILD
32
+ COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR} /${asset} ${CMAKE_CURRENT_BINARY_DIR} /assets/${asset}
33
+ COMMENT "Copying asset: ${asset} \n "
34
+ )
35
+ endforeach ()
36
+ endfunction ()
37
+
17
38
# Function to set profile properties for the app, including code signing identity
18
39
function (native_set_profile )
19
40
if (APPLE )
Original file line number Diff line number Diff line change @@ -13,6 +13,10 @@ native_add_app(
13
13
PLATFORM desktop
14
14
SOURCES hello_world.cc )
15
15
16
+ native_add_assets (
17
+ TARGET hello_world_app
18
+ ASSETS index.html style.css )
19
+
16
20
native_set_profile (
17
21
TARGET hello_world_app
18
22
NAME "example_hello_world"
Original file line number Diff line number Diff line change 5
5
#endif
6
6
7
7
#include < exception>
8
+ #include < filesystem>
8
9
#include < iostream>
9
10
10
11
class App : public sourcemeta ::native::Application {
@@ -18,7 +19,7 @@ class App : public sourcemeta::native::Application {
18
19
window.show ();
19
20
20
21
#ifdef _WIN32
21
- webview.load_url ( " https://www.sourcemeta.com " );
22
+ webview.load_html ( " index.html " );
22
23
window.add (webview);
23
24
#endif
24
25
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+
4
+ < head >
5
+ < meta charset ="UTF-8 ">
6
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
7
+ < title > Native Framework</ title >
8
+ < link rel ="stylesheet " href ="https://native.assets/style.css ">
9
+ </ head >
10
+
11
+ < body >
12
+ < h1 > Welcome to Native</ h1 >
13
+ < p > This is a simple example to demonstrate loading HTML with CSS styling.</ p >
14
+ </ body >
15
+
16
+ </ html >
Original file line number Diff line number Diff line change
1
+ body {
2
+ font-family : Arial, sans-serif;
3
+ margin : 0 ;
4
+ padding : 0 ;
5
+ display : flex;
6
+ flex-direction : column;
7
+ align-items : center;
8
+ justify-content : center;
9
+ height : 100vh ;
10
+ background-color : # f0f0f0 ;
11
+ }
12
+
13
+ h1 {
14
+ color : # 333 ;
15
+ }
16
+
17
+ p {
18
+ color : # 666 ;
19
+ }
Original file line number Diff line number Diff line change @@ -18,8 +18,10 @@ class WebView {
18
18
19
19
// Core functionality
20
20
auto attach_to (sourcemeta::native::Window &window) -> void;
21
+
22
+ // Load content
21
23
auto load_url (const std::string &url) -> void;
22
- // auto load_html(const std::string& html ) -> void;
24
+ auto load_html (const std::string &html_path ) -> void;
23
25
24
26
// IPC messaging
25
27
// auto send_message(const std::string& channel, const std::string& message)
@@ -30,8 +32,8 @@ class WebView {
30
32
auto resize () -> void;
31
33
32
34
private:
33
- using Internal = void * ;
34
- Internal internal_;
35
+ class Internal ;
36
+ Internal * internal_;
35
37
};
36
38
37
39
} // namespace sourcemeta::native
You can’t perform that action at this time.
0 commit comments