-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// | ||
// Created by Nagy Levente on 29/12/2023. | ||
// | ||
|
||
#ifndef RECIPE_AGENT_TUI_H | ||
#define RECIPE_AGENT_TUI_H | ||
|
||
#include "ftxui/component/captured_mouse.hpp" | ||
#include "ftxui/component/component.hpp" | ||
#include "ftxui/component/component_base.hpp" | ||
#include "ftxui/component/component_options.hpp" | ||
#include "ftxui/component/screen_interactive.hpp" | ||
#include <ftxui/dom/elements.hpp> | ||
#include <ftxui/screen/screen.hpp> | ||
|
||
#include <ftxui/component/loop.hpp> | ||
#include <vector> | ||
|
||
namespace recipeagent { | ||
|
||
namespace tui { | ||
// TODO: Refactor this into indigent module. | ||
const std::vector<std::string> INDIGENT_TYPES{ | ||
"SEED", | ||
"FRUIT", | ||
"VEGETABLE", | ||
"DAIRY", | ||
"MEAT", | ||
"FAT", | ||
"BREAD", | ||
"SNACK", | ||
"CONDIMENT", | ||
}; | ||
|
||
/// @brief This object encapsulates the tab of the Indigents menu. | ||
struct IndigentsMenu { | ||
IndigentsMenu(); | ||
|
||
std::vector<std::string> tab_indigents_entries; | ||
|
||
std::string indigent_name_field; | ||
ftxui::Component indigent_name_input; | ||
|
||
int selected_indigent_type; | ||
ftxui::Component indigent_type_dropdown; | ||
|
||
ftxui::Component indigent_add_button; | ||
|
||
int tab_indigents_selected; | ||
|
||
}; | ||
|
||
/// @brief This function is the main entry point of the tui module. | ||
void display_menu(); | ||
|
||
/// @brief This function is the entry point to draw all the indigent related menus, tabs, etc. | ||
ftxui::Component display_indigents_menu(IndigentsMenu &indigents_menu); | ||
|
||
ftxui::Component create_indigents_component(IndigentsMenu &indigents_menu); | ||
|
||
ftxui::ButtonOption button_style(); | ||
|
||
}// namespace tui | ||
|
||
} // namespace recipeagent | ||
#endif// RECIPE_AGENT_TUI_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
include(GenerateExportHeader) | ||
|
||
add_library(tui tui.cpp) | ||
|
||
add_library(recipe_agent::tui ALIAS tui) | ||
|
||
target_link_libraries(tui PRIVATE recipe_agent_options recipe_agent_warnings) | ||
|
||
target_link_system_libraries(tui PRIVATE ftxui::screen | ||
ftxui::dom | ||
ftxui::component | ||
fmt::fmt | ||
spdlog::spdlog) | ||
|
||
target_include_directories(tui ${WARNING_GUARD} PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> | ||
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>) | ||
|
||
target_compile_features(tui PUBLIC cxx_std_20) | ||
|
||
set_target_properties( | ||
tui | ||
PROPERTIES VERSION ${PROJECT_VERSION} | ||
CXX_VISIBILITY_PRESET hidden | ||
VISIBILITY_INLINES_HIDDEN YES) | ||
|
||
generate_export_header(tui EXPORT_FILE_NAME ${PROJECT_BINARY_DIR}/include/recipe_agent/tui_export.hpp) | ||
|
||
if(NOT BUILD_SHARED_LIBS) | ||
target_compile_definitions(tui PUBLIC SAMPLE_LIBRARY_STATIC_DEFINE) | ||
endif() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// | ||
// Created by Nagy Levente on 29/12/2023. | ||
// | ||
#include "recipe_agent/tui/tui.h" | ||
#include <ftxui/component/loop.hpp> | ||
|
||
#include <spdlog/spdlog.h> | ||
|
||
|
||
namespace recipeagent { | ||
Check failure on line 10 in src/tui/tui.cpp
|
||
namespace tui { | ||
|
||
IndigentsMenu::IndigentsMenu() | ||
: tab_indigents_entries({ | ||
"Add indigent", | ||
"Get indigent", | ||
"List all indigents", | ||
"Get indigents by category", | ||
}), | ||
indigent_name_field(), indigent_name_input(ftxui::Input(&indigent_name_field, "name here")), | ||
Check failure on line 20 in src/tui/tui.cpp
|
||
selected_indigent_type(0), indigent_type_dropdown(ftxui::Dropdown(&INDIGENT_TYPES, &selected_indigent_type)), | ||
indigent_add_button(ftxui::Button( | ||
"Add", | ||
[&] { spdlog::info("Indigent added!"); }, | ||
button_style())), | ||
tab_indigents_selected(0) | ||
{} | ||
|
||
void display_menu() | ||
{ | ||
using namespace ftxui; | ||
|
||
std::vector<std::string> tab_values{ | ||
Check failure on line 33 in src/tui/tui.cpp
|
||
"Indigents", | ||
"Recipes", | ||
"Generation", | ||
}; | ||
int tab_selected = 0; | ||
auto tab_main_menu = Menu(&tab_values, &tab_selected); | ||
|
||
auto indigents_menu = IndigentsMenu{}; | ||
auto tab_indigents_menu = display_indigents_menu(indigents_menu); | ||
auto add_indigents_component = create_indigents_component(indigents_menu); | ||
|
||
auto container = Container::Horizontal({ tab_main_menu, tab_indigents_menu, add_indigents_component }); | ||
|
||
auto renderer = Renderer(container, [&] { | ||
return hbox({ tab_main_menu->Render(), | ||
separator(), | ||
tab_indigents_menu->Render(), | ||
separator(), | ||
vbox({ hbox({ text("Indigent name : "), indigents_menu.indigent_name_input->Render() }), | ||
hbox({ text("Indigent type : "), indigents_menu.indigent_type_dropdown->Render() }), | ||
indigents_menu.indigent_add_button->Render() }) }) | ||
| border; | ||
}); | ||
|
||
auto screen = ScreenInteractive::TerminalOutput(); | ||
screen.Loop(renderer); | ||
} | ||
|
||
ftxui::Component display_indigents_menu(IndigentsMenu &indigents_menu) | ||
{ | ||
using namespace ftxui; | ||
|
||
return Menu(&indigents_menu.tab_indigents_entries, &indigents_menu.tab_indigents_selected); | ||
} | ||
|
||
ftxui::Component create_indigents_component(IndigentsMenu &indigents_menu) | ||
{ | ||
using namespace ftxui; | ||
|
||
return Container::Vertical({ indigents_menu.indigent_name_input, | ||
indigents_menu.indigent_type_dropdown, | ||
indigents_menu.indigent_add_button }); | ||
} | ||
|
||
ftxui::ButtonOption button_style() | ||
{ | ||
using namespace ftxui; | ||
|
||
auto option = ButtonOption::Animated(); | ||
option.transform = [](const EntryState &s) { | ||
Check failure on line 83 in src/tui/tui.cpp
|
||
auto element = text(s.label); | ||
if (s.focused) { element |= bold; } | ||
return element | center | borderEmpty; | ||
}; | ||
|
||
return option; | ||
} | ||
|
||
|
||
}// namespace tui | ||
}// namespace recipeagent |