Skip to content

Commit

Permalink
[Feature] Adding color options for Toggle and Dropdown (#11)
Browse files Browse the repository at this point in the history
Signed-off-by: Vedant <[email protected]>
  • Loading branch information
vrnimje authored Sep 9, 2023
1 parent 6fc9e21 commit e968fd4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
6 changes: 3 additions & 3 deletions examples/menu_toggle_dropdown.qf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Vertical
{
int x
Blue Menu{
Red Menu{
[ "Physics", "Maths", "Chemistry", "Biology",],
HorizontalAnimated,
x
Expand All @@ -14,11 +14,11 @@ Vertical
}
int y
int z
Toggle {
Cyan Toggle {
[ "On", "Off", ],
y
}
Dropdown {
BlueLight Dropdown {
[ "Zain", "Mahesh", "Alqama", "Vaidic", "Mundane", "Advait", ],
z
}
Expand Down
22 changes: 17 additions & 5 deletions include/quick-ftxui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,13 @@ struct menu {
};

struct toggle {
colours color = colours::Default;
std::vector<std::string> entries;
std::string selected;
};

struct dropdown {
colours color = colours::Default;
std::vector<std::string> entries;
std::string selected;
};
Expand Down Expand Up @@ -239,11 +241,13 @@ BOOST_FUSION_ADAPT_STRUCT(quick_ftxui_ast::menu,
)

BOOST_FUSION_ADAPT_STRUCT(quick_ftxui_ast::toggle,
(quick_ftxui_ast::colours, color)
(std::vector <std::string> , entries)
(std::string, selected)
)

BOOST_FUSION_ADAPT_STRUCT(quick_ftxui_ast::dropdown,
(quick_ftxui_ast::colours, color)
(std::vector <std::string> , entries)
(std::string, selected)
)
Expand Down Expand Up @@ -525,21 +529,29 @@ struct node_printer : boost::static_visitor<> {

void operator()(quick_ftxui_ast::toggle const &text) const {
// tab(indent + tabsize);

ftxui::Color toggle_clr = quick_ftxui_ast::resolveColour(text.color);

if (auto It = quick_ftxui_ast::numbers.find(std::string(text.selected));
It != quick_ftxui_ast::numbers.end()) {
data->components.push_back(
ftxui::Toggle(&text.entries, (int *)(&It->second)));
ftxui::Toggle(&text.entries, (int *)(&It->second)) |
ftxui::color(toggle_clr));
} else {
throw std::runtime_error("Variable " + text.selected + " not found");
}
}

void operator()(quick_ftxui_ast::dropdown const &text) const {
// tab(indent + tabsize);

ftxui::Color drpdwn_clr = quick_ftxui_ast::resolveColour(text.color);

if (auto It = quick_ftxui_ast::numbers.find(std::string(text.selected));
It != quick_ftxui_ast::numbers.end()) {
data->components.push_back(
ftxui::Dropdown(&text.entries, (int *)(&It->second)));
ftxui::Dropdown(&text.entries, (int *)(&It->second)) |
ftxui::color(drpdwn_clr));
} else {
throw std::runtime_error("Variable " + text.selected + " not found");
}
Expand Down Expand Up @@ -696,10 +708,10 @@ struct parser
+(quoted_string >> ',') >> ']' >> -(',' >> menuopt_kw) >>
',' >> identifier >> '}';

toggle_comp %= qi::lit("Toggle") >> '{' >> '[' >> +(quoted_string >> ',') >>
']' >> ',' >> identifier >> '}';
toggle_comp %= -(color_kw) >> qi::lit("Toggle") >> '{' >> '[' >>
+(quoted_string >> ',') >> ']' >> ',' >> identifier >> '}';

drpdwn_comp %= qi::lit("Dropdown") >> '{' >> '[' >>
drpdwn_comp %= -(color_kw) >> qi::lit("Dropdown") >> '{' >> '[' >>
+(quoted_string >> ',') >> ']' >> ',' >> identifier >> '}';

int_var_decl %= qi::lit("int") >> identifier >> -('=' > qi::int_);
Expand Down

0 comments on commit e968fd4

Please sign in to comment.