added menu like view
bbc8515 parent: 4f1f5a9 modified
CMakeLists.txt +1 -1 | @@ -5,7 +5,7 @@ include(FetchContent) | ||
| 5 | 5 | set(FETCHCONTENT_UPDATES_DISCONNECTED TRUE) |
| 6 | 6 | FetchContent_Declare(ftxui |
| 7 | 7 | GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui |
| 8 | - GIT_TAG v4.0.0 | |
| 8 | + GIT_TAG v5.0.0 | |
| 9 | 9 | ) |
| 10 | 10 | FetchContent_MakeAvailable(ftxui) |
| 11 | 11 | if(NOT ftxui_POPULATED) |
| @@ -5,7 +5,7 @@ include(FetchContent) | |||
| 5 | set(FETCHCONTENT_UPDATES_DISCONNECTED TRUE) | 5 | set(FETCHCONTENT_UPDATES_DISCONNECTED TRUE) |
| 6 | FetchContent_Declare(ftxui | 6 | FetchContent_Declare(ftxui |
| 7 | GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui | 7 | GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui |
| 8 | - GIT_TAG v4.0.0 | 8 | + GIT_TAG v5.0.0 |
| 9 | ) | 9 | ) |
| 10 | FetchContent_MakeAvailable(ftxui) | 10 | FetchContent_MakeAvailable(ftxui) |
| 11 | if(NOT ftxui_POPULATED) | 11 | if(NOT ftxui_POPULATED) |
modified
src/main.cpp +25 -23 | @@ -1,6 +1,9 @@ | ||
| 1 | 1 | #include "ftxui/dom/elements.hpp" |
| 2 | 2 | #include "ftxui/screen/screen.hpp" |
| 3 | 3 | #include "ftxui/screen/string.hpp" |
| 4 | +#include "ftxui/component/component.hpp" | |
| 5 | +#include "ftxui/component/component_options.hpp" | |
| 6 | +#include "ftxui/component/screen_interactive.hpp" | |
| 4 | 7 | |
| 5 | 8 | #include <iostream> |
| 6 | 9 | #include <string> |
| @@ -95,22 +98,12 @@ int main() { | ||
| 95 | 98 | } |
| 96 | 99 | sqlite3_finalize(stmt); |
| 97 | 100 | |
| 98 | - int choice = 1; | |
| 101 | + int exit_id = games.size(); | |
| 102 | + int choice = 0; | |
| 99 | 103 | do { |
| 100 | 104 | system("clear"); |
| 101 | - std::vector<Element> localGames = {}; | |
| 102 | - for (const auto& [name, path] : games) { | |
| 103 | - localGames.push_back(hbox({text(" " + name)}) | color(Color::Green)); | |
| 104 | - } | |
| 105 | - | |
| 106 | - auto summary = [&] { | |
| 107 | - auto content = vbox(localGames); | |
| 108 | - return window(text(L" Games "), content); | |
| 109 | - }; | |
| 110 | - | |
| 111 | 105 | auto document = vbox({ |
| 112 | - text(L" Fluffy v0.1 "), | |
| 113 | - vbox({summary()}), | |
| 106 | + center(text(L" Fluffy v0.1 ")), | |
| 114 | 107 | }); |
| 115 | 108 | |
| 116 | 109 | document = document | size(WIDTH, LESS_THAN, 120); |
| @@ -119,15 +112,26 @@ int main() { | ||
| 119 | 112 | Render(screen, document); |
| 120 | 113 | |
| 121 | 114 | std::cout << screen.ToString() << '\0' << std::endl; |
| 122 | - std::cin >> choice; | |
| 123 | - switch (choice) | |
| 124 | - { | |
| 125 | - case 0: | |
| 126 | - break; | |
| 127 | - default: | |
| 128 | - int i{ 1 }; | |
| 115 | + | |
| 116 | + | |
| 117 | + auto menu_screen = ScreenInteractive::TerminalOutput(); | |
| 118 | + | |
| 119 | + std::vector<std::string> localGames = {}; | |
| 120 | + for (const auto& [name, path] : games) { | |
| 121 | + localGames.push_back(name); | |
| 122 | + } | |
| 123 | + localGames.push_back("Exit"); | |
| 124 | + | |
| 125 | + MenuOption option; | |
| 126 | + option.on_enter = menu_screen.ExitLoopClosure(); | |
| 127 | + auto menu = Menu(&localGames, &choice, option); | |
| 128 | + menu_screen.Loop(menu); | |
| 129 | + | |
| 130 | + if (choice != exit_id) { | |
| 131 | + int i{ 0 }; | |
| 129 | 132 | std::string pathToRun = ""; |
| 130 | 133 | for (const auto& [name, path] : games) { |
| 134 | + | |
| 131 | 135 | if (i == choice) { |
| 132 | 136 | pathToRun = path; |
| 133 | 137 | |
| @@ -135,10 +139,8 @@ int main() { | ||
| 135 | 139 | i++; |
| 136 | 140 | } |
| 137 | 141 | system(pathToRun.c_str()); |
| 138 | - break; | |
| 139 | 142 | } |
| 140 | - } while (choice != 0); | |
| 141 | - | |
| 143 | + } while (choice != exit_id); | |
| 142 | 144 | sqlite3_close(database); |
| 143 | 145 | return EXIT_SUCCESS; |
| 144 | 146 | } |
| \ No newline at end of file | ||
| @@ -1,6 +1,9 @@ | |||
| 1 | #include "ftxui/dom/elements.hpp" | 1 | #include "ftxui/dom/elements.hpp" |
| 2 | #include "ftxui/screen/screen.hpp" | 2 | #include "ftxui/screen/screen.hpp" |
| 3 | #include "ftxui/screen/string.hpp" | 3 | #include "ftxui/screen/string.hpp" |
| 4 | +#include "ftxui/component/component.hpp" | ||
| 5 | +#include "ftxui/component/component_options.hpp" | ||
| 6 | +#include "ftxui/component/screen_interactive.hpp" | ||
| 4 | 7 | ||
| 5 | #include <iostream> | 8 | #include <iostream> |
| 6 | #include <string> | 9 | #include <string> |
| @@ -95,22 +98,12 @@ int main() { | |||
| 95 | } | 98 | } |
| 96 | sqlite3_finalize(stmt); | 99 | sqlite3_finalize(stmt); |
| 97 | 100 | ||
| 98 | - int choice = 1; | 101 | + int exit_id = games.size(); |
| 102 | + int choice = 0; | ||
| 99 | do { | 103 | do { |
| 100 | system("clear"); | 104 | system("clear"); |
| 101 | - std::vector<Element> localGames = {}; | ||
| 102 | - for (const auto& [name, path] : games) { | ||
| 103 | - localGames.push_back(hbox({text(" " + name)}) | color(Color::Green)); | ||
| 104 | - } | ||
| 105 | - | ||
| 106 | - auto summary = [&] { | ||
| 107 | - auto content = vbox(localGames); | ||
| 108 | - return window(text(L" Games "), content); | ||
| 109 | - }; | ||
| 110 | - | ||
| 111 | auto document = vbox({ | 105 | auto document = vbox({ |
| 112 | - text(L" Fluffy v0.1 "), | 106 | + center(text(L" Fluffy v0.1 ")), |
| 113 | - vbox({summary()}), | ||
| 114 | }); | 107 | }); |
| 115 | 108 | ||
| 116 | document = document | size(WIDTH, LESS_THAN, 120); | 109 | document = document | size(WIDTH, LESS_THAN, 120); |
| @@ -119,15 +112,26 @@ int main() { | |||
| 119 | Render(screen, document); | 112 | Render(screen, document); |
| 120 | 113 | ||
| 121 | std::cout << screen.ToString() << '\0' << std::endl; | 114 | std::cout << screen.ToString() << '\0' << std::endl; |
| 122 | - std::cin >> choice; | 115 | + |
| 123 | - switch (choice) | 116 | + |
| 124 | - { | 117 | + auto menu_screen = ScreenInteractive::TerminalOutput(); |
| 125 | - case 0: | 118 | + |
| 126 | - break; | 119 | + std::vector<std::string> localGames = {}; |
| 127 | - default: | 120 | + for (const auto& [name, path] : games) { |
| 128 | - int i{ 1 }; | 121 | + localGames.push_back(name); |
| 122 | + } | ||
| 123 | + localGames.push_back("Exit"); | ||
| 124 | + | ||
| 125 | + MenuOption option; | ||
| 126 | + option.on_enter = menu_screen.ExitLoopClosure(); | ||
| 127 | + auto menu = Menu(&localGames, &choice, option); | ||
| 128 | + menu_screen.Loop(menu); | ||
| 129 | + | ||
| 130 | + if (choice != exit_id) { | ||
| 131 | + int i{ 0 }; | ||
| 129 | std::string pathToRun = ""; | 132 | std::string pathToRun = ""; |
| 130 | for (const auto& [name, path] : games) { | 133 | for (const auto& [name, path] : games) { |
| 134 | + | ||
| 131 | if (i == choice) { | 135 | if (i == choice) { |
| 132 | pathToRun = path; | 136 | pathToRun = path; |
| 133 | 137 | ||
| @@ -135,10 +139,8 @@ int main() { | |||
| 135 | i++; | 139 | i++; |
| 136 | } | 140 | } |
| 137 | system(pathToRun.c_str()); | 141 | system(pathToRun.c_str()); |
| 138 | - break; | ||
| 139 | } | 142 | } |
| 140 | - } while (choice != 0); | 143 | + } while (choice != exit_id); |
| 141 | - | ||
| 142 | sqlite3_close(database); | 144 | sqlite3_close(database); |
| 143 | return EXIT_SUCCESS; | 145 | return EXIT_SUCCESS; |
| 144 | } | 146 | } |
| \ No newline at end of file | \ No newline at end of file | ||