diff --git a/README.md b/README.md index d8c6e506c670529b886b4df8e6de0f214190c4e7..042ee0b89b1b84e7cb4ea71432652d0c3a9009ea 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ A simple C++ library for terminal based user interface. - [Starter example project](https://github.com/ArthurSonzogni/ftxui-starter) - [Documentation](https://arthursonzogni.github.io/FTXUI/) -- [Examples (WebAssembly)](https://arthursonzogni.github.io/FTXUI/examples/) +- [Examples (WebAssembly)](https://arthursonzogni.com/FTXUI/examples/) - [Build using CMake](https://arthursonzogni.com/FTXUI/doc/#build-using-cmake) - [Build using nxxm](https://arthursonzogni.com/FTXUI/doc/#build-using-cmake) diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index b47de235559b857dff88b8fb38c8e9e739dc10c9..3062e2a1ca1b18bcc7bc09d044152b03f774a986 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -3,10 +3,9 @@ if (DOXYGEN_FOUND) # Generate example list for documentation set(EXAMPLE_LIST "${CMAKE_CURRENT_BINARY_DIR}/example_list.md") file(WRITE ${EXAMPLE_LIST} "# Examples") - file(GLOB_RECURSE EXAMPLES RELATIVE ${PROJECT_SOURCE_DIR} - "${PROJECT_SOURCE_DIR}/examples/*.cpp") + get_property(EXAMPLES GLOBAL PROPERTY FTXUI::EXAMPLES) foreach(EXAMPLE IN LISTS EXAMPLES) - file(APPEND ${EXAMPLE_LIST} "\n@example ${EXAMPLE}") + file(APPEND ${EXAMPLE_LIST} "\n@example examples/${EXAMPLE}.cpp") endforeach(EXAMPLE IN LISTS EXAMPLES) configure_file(Doxyfile.in Doxyfile @ONLY) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 41e32077dcd1d0a91d685877d55f84788610f65d..c30eb671b970cb49fd1ba2f11898d1feb5e1e67b 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,14 +1,19 @@ +set(EXAMPLES_DIR ${CMAKE_CURRENT_SOURCE_DIR}) +function(example name) + add_executable(${name} ${name}.cpp) + target_link_libraries(${name} PUBLIC ${DIRECTORY_LIB}) + file(RELATIVE_PATH dir ${EXAMPLES_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) + set_property(GLOBAL APPEND PROPERTY FTXUI::EXAMPLES ${dir}/${name}) +endfunction(example) + add_subdirectory(component) add_subdirectory(dom) -add_subdirectory(util) if (EMSCRIPTEN) + get_property(EXAMPLES GLOBAL PROPERTY FTXUI::EXAMPLES) foreach(file "index.html" - "run_webassembly.sh") - configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/${file} - ${CMAKE_CURRENT_BINARY_DIR}/${file} - ) + "run_webassembly.py") + configure_file(${file} ${file}) endforeach(file) endif() diff --git a/examples/component/CMakeLists.txt b/examples/component/CMakeLists.txt index 30702f580be4b47a6487ab8cec142db56f30ebd2..29f61ab03348efc50df52b3dc60c62aeb4bf8a8f 100644 --- a/examples/component/CMakeLists.txt +++ b/examples/component/CMakeLists.txt @@ -1,7 +1,4 @@ -function(example name) - add_executable(${name} ${name}.cpp) - target_link_libraries(${name} PUBLIC component) -endfunction(example) +set(DIRECTORY_LIB component) example(button) example(checkbox) @@ -23,3 +20,4 @@ example(tab_horizontal) example(tab_vertical) example(toggle) example(resizable_split) +example(print_key_press) diff --git a/examples/util/print_key_press.cpp b/examples/component/print_key_press.cpp similarity index 100% rename from examples/util/print_key_press.cpp rename to examples/component/print_key_press.cpp diff --git a/examples/dom/CMakeLists.txt b/examples/dom/CMakeLists.txt index e750925fe0d2630874d24e3f066fda318a0c26b1..c1297ea3610674122382f86f934e0be910aceed6 100644 --- a/examples/dom/CMakeLists.txt +++ b/examples/dom/CMakeLists.txt @@ -1,7 +1,4 @@ -function(example name) - add_executable(${name} ${name}.cpp) - target_link_libraries(${name} PUBLIC dom) -endfunction(example) +set(DIRECTORY_LIB dom) example(border) example(color_gallery) diff --git a/examples/index.html b/examples/index.html index a4a427d9b9d6adee8e2a84f89a0357474273536d..fe903b62c59eb5e37e4b3072303f5bb5d5736aa9 100644 --- a/examples/index.html +++ b/examples/index.html @@ -23,52 +23,10 @@ </div> </body> <script> - let example_list = [ - "./component/button.js", - "./component/checkbox.js", - "./component/checkbox_in_frame.js", - "./component/gallery.js", - "./component/homescreen.js", - "./component/input.js", - "./component/menu.js", - "./component/menu2.js", - "./component/menu_style.js", - "./component/modal_dialog.js", - "./component/radiobox.js", - "./component/radiobox_in_frame.js", - "./component/slider.js", - "./component/tab_horizontal.js", - "./component/tab_vertical.js", - "./component/toggle.js", - "./dom/border.js", - "./dom/color_gallery.js", - "./dom/color_info_palette256.js", - "./dom/color_truecolor_HSV.js", - "./dom/color_truecolor_RGB.js", - "./dom/dbox.js", - "./dom/gauge.js", - "./dom/graph.js", - "./dom/hflow.js", - "./dom/html_like.js", - "./dom/package_manager.js", - "./dom/paragraph.js", - "./dom/separator.js", - "./dom/size.js", - "./dom/spinner.js", - "./dom/style_blink.js", - "./dom/style_bold.js", - "./dom/style_color.js", - "./dom/style_dim.js", - "./dom/style_gallery.js", - "./dom/style_inverted.js", - "./dom/style_underlined.js", - "./dom/vbox_hbox.js", - "./dom/window.js", - "./util/print_key_press.js", - ]; + const example_list = "@EXAMPLES@".split(";"); const url_search_params = new URLSearchParams(window.location.search); - const example = url_search_params.get("file") || "./dom/color_gallery.js" + const example = url_search_params.get("file") || "dom/color_gallery"; const select = document.getElementById("selectExample"); for(var i = 0; i < example_list.length; i++) { @@ -113,7 +71,7 @@ postRun: [], onRuntimeInitialized: () => {}, }; - document.querySelector("#example_script").src = example + document.querySelector("#example_script").src = example + '.js'; </script> <style> diff --git a/examples/run_webassembly.py b/examples/run_webassembly.py new file mode 100755 index 0000000000000000000000000000000000000000..5e1a732f8441e7bba7a9a628ec3468ab48c27793 --- /dev/null +++ b/examples/run_webassembly.py @@ -0,0 +1,20 @@ +#! /usr/bin/python3 +from http.server import HTTPServer, SimpleHTTPRequestHandler +import sys +import webbrowser + +PORT = 8888 + +class CustomHTTPRequestHandler(SimpleHTTPRequestHandler): + def end_headers(self): + self.send_header("cross-origin-embedder-policy", "require-corp") + self.send_header("cross-origin-opener-policy", "same-origin") + SimpleHTTPRequestHandler.end_headers(self) + +with HTTPServer(("", PORT), CustomHTTPRequestHandler) as httpd: + try: + webbrowser.open("http://localhost:%s" % PORT) + print("serving at port", PORT) + httpd.serve_forever() + finally: + sys.exit(0) diff --git a/examples/run_webassembly.sh b/examples/run_webassembly.sh deleted file mode 100755 index 488c23c4372582e0400bf74784ea136607daddf6..0000000000000000000000000000000000000000 --- a/examples/run_webassembly.sh +++ /dev/null @@ -1,6 +0,0 @@ -#! /bin/bash -python3 -m http.server 8888 & -P1=$! -trap 'kill 0' SIGINT; P1 -python3 -m webbrowser http://localhost:8888 -wait $P1 diff --git a/examples/util/CMakeLists.txt b/examples/util/CMakeLists.txt deleted file mode 100644 index 7b2db4f6807bc3e06829d3b86cae2ba49b7d5d39..0000000000000000000000000000000000000000 --- a/examples/util/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -function(example name) - add_executable(${name} ${name}.cpp) - target_link_libraries(${name} PUBLIC component) -endfunction(example) - -example(print_key_press)