diff --git a/CMakeLists.txt b/CMakeLists.txt index f1cc6b9..600d7ed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,7 @@ endif() project(ftxui LANGUAGES CXX - VERSION 0.4.${git_version} + VERSION 0.5.${git_version} ) option(FTXUI_BUILD_EXAMPLES "Set to ON to build examples" ON) @@ -80,6 +80,7 @@ add_library(component include/ftxui/component/captured_mouse.hpp include/ftxui/component/checkbox.hpp include/ftxui/component/component.hpp + include/ftxui/component/component_base.hpp include/ftxui/component/container.hpp include/ftxui/component/event.hpp include/ftxui/component/input.hpp @@ -88,7 +89,6 @@ add_library(component include/ftxui/component/radiobox.hpp include/ftxui/component/receiver.hpp include/ftxui/component/screen_interactive.hpp - include/ftxui/component/slider.hpp include/ftxui/component/toggle.hpp src/ftxui/component/button.cpp src/ftxui/component/checkbox.cpp @@ -99,6 +99,7 @@ add_library(component src/ftxui/component/menu.cpp src/ftxui/component/radiobox.cpp src/ftxui/component/radiobox.cpp + src/ftxui/component/renderer.cpp src/ftxui/component/screen_interactive.cpp src/ftxui/component/slider.cpp src/ftxui/component/terminal_input_parser.cpp diff --git a/doc/Doxyfile.in b/doc/Doxyfile.in index 4599a80..a01c5d8 100644 --- a/doc/Doxyfile.in +++ b/doc/Doxyfile.in @@ -44,7 +44,7 @@ PROJECT_NUMBER = @CMAKE_PROJECT_VERSION@ # for a project that appears at the top of each page and should give viewer a # quick idea about the purpose of the project. Keep the description short. -PROJECT_BRIEF = "C++ functionnal terminal UI." +PROJECT_BRIEF = "C++ functional terminal UI." # With the PROJECT_LOGO tag one can specify a logo or an icon that is included # in the documentation. The maximum height of the logo should not exceed 55 diff --git a/doc/example_list.md b/doc/example_list.md index efddeab..5f65403 100644 --- a/doc/example_list.md +++ b/doc/example_list.md @@ -34,6 +34,7 @@ @example ./examples/component/input.cpp @example ./examples/component/homescreen.cpp @example ./examples/component/radiobox.cpp +@example ./examples/component/slider_rgb.cpp @example ./examples/component/menu.cpp @example ./examples/component/menu_style.cpp @example ./examples/component/radiobox_in_frame.cpp diff --git a/doc/mainpage.md b/doc/mainpage.md index 672fda1..38434b9 100644 --- a/doc/mainpage.md +++ b/doc/mainpage.md @@ -31,7 +31,7 @@ int main(void) { Dimension::Fit(document) // Height ); Render(screen, document); - std::cout << screen.ToString() << std::endl; + screen.Print(); return EXIT_SUCCESS; } @@ -44,28 +44,71 @@ int main(void) { └────┘└─────────────────────────────────────────────────────────────────┘└─────┘ ``` -**cmake** -```c +# Build + +## Using CMake + +CMakeLists.txt +~~~cmake cmake_minimum_required (VERSION 3.11) +# --- Fetch FTXUI -------------------------------------------------------------- include(FetchContent) + +set(FETCHCONTENT_UPDATES_DISCONNECTED TRUE) FetchContent_Declare(ftxui GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui + # Specify a GIT_TAG here. ) + FetchContent_GetProperties(ftxui) if(NOT ftxui_POPULATED) FetchContent_Populate(ftxui) add_subdirectory(${ftxui_SOURCE_DIR} ${ftxui_BINARY_DIR} EXCLUDE_FROM_ALL) endif() -add_executable(main src/main.cpp) -target_link_libraries(main +# ------------------------------------------------------------------------------ + +project(ftxui-starter + LANGUAGES CXX + VERSION 1.0.0 +) + +add_executable(ftxui-starter src/main.cpp) +target_include_directories(ftxui-starter PRIVATE src) + +target_link_libraries(ftxui-starter PRIVATE ftxui::screen PRIVATE ftxui::dom PRIVATE ftxui::component # Not needed for this example. ) -set_target_properties(main PROPERTIES CXX_STANDARD 17) -``` + +# C++17 is used. We requires fold expressions at least. +set_target_properties(ftxui-starter PROPERTIES CXX_STANDARD 17) + +~~~ + +Build +~~~ +mkdir build && cd build +cmake .. +make +./main +~~~ + +## Using NXXM + +**.nxxm/deps** +~~~json +{ + "ArthurSonzogni/FTXUI": {} +} +~~~ + +Build: +~~~ +nxxm . -t clang-cxx17 +~~~ # List of modules. @@ -82,7 +125,7 @@ input. It defines a set of ftxui::Component. The use can navigates using the arrow keys and interact with widgets like checkbox/inputbox/... You can make you own components. -## screen +# screen It defines a ftxui::Screen. This is a grid of ftxui::Pixel. A Pixel represent a unicode character and its associated style (bold, colors, etc...). @@ -106,7 +149,7 @@ The screen can be printed as a string using ftxui::Screen::ToString(). } ~~~ -## dom +# dom This module defines a hierachical set of Element. An element manages layout and can be responsive to the terminal dimensions. @@ -130,23 +173,6 @@ You only need one header: ftxui/dom/elements.hpp \include ftxui/dom/elements.hpp -## component - -Finally, the ftxui/component directory defines the logic to get interactivity. - -Please take a look at ./examples/component - -This provides: -1. A main loop. -2. Get events and respond to them. -3. A predefined implementation of "keyboard navigation". -4. A set of predefined widget: CheckBox, RadioBox, Input, Menu, Toggle. - -# ftxui/dom - -Every elements of the dom are declared from: -\ref ftxui/dom/elements.hpp - ## text The most simple widget. It displays a text. @@ -219,6 +245,7 @@ border(gauge(0.5)) ~~~ ## graph + @htmlonly @endhtmlonly @@ -362,7 +389,25 @@ An horizontal flow layout is implemented by: └────┘└───────────────────────────────────┘└───────────────────────────────────┘ ~~~ -# ftxui/component + +# component + +The `ftxui/component` directory defines the logic to get produce +interactive component responding to user's events (keyboard, mouse, etc...) + +A ftxui::ScreenInteractive defines a main loop to render a component. + +A ftxui::Component is a shared pointer to a ftxui::ComponentBase. The later +defines + - ftxui::ComponentBase::Render(): How to render the interface. + - ftxui::ComponentBase::OnEvent(): How to react to events. + - ftxui::ComponentBase::Add(): Give a parent/child relation ship in between + two component. This defines a tree a components, which help properly define + how keyboard navigation works. + +Predefined components are available in `ftxui/dom/component.hpp`: + +\include ftxui/component/component.hpp Element are stateless object. On the other side, components are used when an internal state is needed. Components are used to interact with the user with @@ -370,7 +415,7 @@ its keyboard. They handle keyboard navigation, including component focus. ## Input -The component: \ref ftxui::Input +Produced by: ftxui::Input() from "ftxui/component/component.hpp" @htmlonly @@ -378,7 +423,7 @@ The component: \ref ftxui::Input ## Menu -The component: \ref ftxui::Menu +Produced by: ftxui::Menu() from "ftxui/component/component.hpp" @htmlonly @@ -386,7 +431,7 @@ The component: \ref ftxui::Menu ## Toggle. -The component: \ref ftxui::Toggle +Produced by: ftxui::Toggle() from "ftxui/component/component.hpp" @htmlonly @@ -394,7 +439,7 @@ The component: \ref ftxui::Toggle ## CheckBox -The component: \ref ftxui::CheckBox +Produced by: ftxui::Checkbox() from "ftxui/component/component.hpp" @htmlonly @@ -402,99 +447,32 @@ The component: \ref ftxui::CheckBox ## RadioBox -The component: \ref ftxui::RadioBox +Produced by: ftxui::Radiobox() from "ftxui/component/component.hpp" @htmlonly @endhtmlonly -# Build +## Renderer -Assuming this example example.cpp file. +Produced by: ftxui::Renderer() from \ref "ftxui/component/component.hpp". This +component decorate another one by using a different function to render an +interface. -**main.cpp** -~~~cpp -#include "ftxui/screen/screen.c -#include "ftxui/dom/elements.c -#include +## Container::Horizontal -int main(int argc, const char *argv[]) { - using namespace ftxui; - auto document = - hbox({ - text(L"left") | bold | border, - text(L"middle") | flex | border, - text(L"right") | border, - }); - auto screen = Screen::Create(Dimension::Full(), Dimension::Fit(document)); - Render(screen, document); +Produced by: ftxui::Container::Horizontal() from +"ftxui/component/component.hpp". It displays a list of components horizontally +and handle keyboard/mouse navigation. - std::cout << screen.ToString(); +## Container::Vertial - return 0; -} -~~~ +Produced by: ftxui::Container::Vertical() from +"ftxui/component/component.hpp". It displays a list of components vertically +and handles keyboard/mouse navigation. -## Using CMake +## Container::Tab -CMakeLists.txt -~~~cmake -cmake_minimum_required (VERSION 3.11) - -# --- Fetch FTXUI -------------------------------------------------------------- -include(FetchContent) - -set(FETCHCONTENT_UPDATES_DISCONNECTED TRUE) -FetchContent_Declare(ftxui - GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui - # Specify a GIT TAG here. -) - -FetchContent_GetProperties(ftxui) -if(NOT ftxui_POPULATED) - FetchContent_Populate(ftxui) - add_subdirectory(${ftxui_SOURCE_DIR} ${ftxui_BINARY_DIR} EXCLUDE_FROM_ALL) -endif() - -# ------------------------------------------------------------------------------ - -project(ftxui-starter - LANGUAGES CXX - VERSION 1.0.0 -) - -add_executable(ftxui-starter src/main.cpp) -target_include_directories(ftxui-starter PRIVATE src) - -target_link_libraries(ftxui-starter - PRIVATE ftxui::screen - PRIVATE ftxui::dom - PRIVATE ftxui::component # Not needed for this example. -) - -# C++17 is used. We requires fold expressions at least. -set_target_properties(ftxui-starter PROPERTIES CXX_STANDARD 17) - -~~~ - -Build -~~~ -mkdir build && cd build -cmake .. -make -./main -~~~ - -## Using NXXM - -**.nxxm/deps** -~~~json -{ - "ArthurSonzogni/FTXUI": {} -} -~~~ - -Build: -~~~ -nxxm . -t clang-cxx17 -~~~ +Produced by: ftxui::Container::Tab() from +"ftxui/component/component.hpp". It take a list of component and display only +one of them. This is useful for implementing a tab bar. diff --git a/examples/component/CMakeLists.txt b/examples/component/CMakeLists.txt index 07dc0b3..3f4e5f1 100644 --- a/examples/component/CMakeLists.txt +++ b/examples/component/CMakeLists.txt @@ -17,6 +17,7 @@ example(modal_dialog) example(radiobox) example(radiobox_in_frame) example(slider) +example(slider_rgb) example(tab_horizontal) example(tab_vertical) example(toggle) diff --git a/examples/component/button.cpp b/examples/component/button.cpp index dc3ceaf..5bc7852 100644 --- a/examples/component/button.cpp +++ b/examples/component/button.cpp @@ -1,51 +1,37 @@ -#include // for function -#include // for unique_ptr, make_u... -#include // for wstring -#include // for move -#include // for vector +#include // for __shared_ptr_access, shared_ptr +#include // for operator+, to_wstring -#include "ftxui/component/button.hpp" // for Button -#include "ftxui/component/component.hpp" // for Component -#include "ftxui/component/container.hpp" // for Container +#include "ftxui/component/captured_mouse.hpp" // for ftxui +#include "ftxui/component/component.hpp" // for Button, Horizontal, Renderer +#include "ftxui/component/component_base.hpp" // for ComponentBase #include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive -#include "ftxui/screen/box.hpp" // for ftxui +#include "ftxui/dom/elements.hpp" // for separator, Element, gauge, text, operator|, vbox, border using namespace ftxui; -class MyComponent : public Component { - private: - std::vector> buttons_; - Container container_ = Container::Horizontal(); - - public: - MyComponent() { - Add(&container_); - - auto button_add = std::make_unique