Skip to content

Commit

Permalink
Added color option for Sliders, and modified examples for the same
Browse files Browse the repository at this point in the history
Signed-off-by: Vedant <[email protected]>
  • Loading branch information
vrnimje committed Sep 8, 2023
1 parent f6001e4 commit 141101a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 29 deletions.
2 changes: 1 addition & 1 deletion cpp_examples/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ int main() {
Password,
y
}
Slider {
RedLight Slider {
"Test: ",
x,
0,
Expand Down
36 changes: 12 additions & 24 deletions examples/Slider.qf
Original file line number Diff line number Diff line change
@@ -1,35 +1,23 @@
Vertical{
int x = 5
Slider{
Blue Slider{
"Slider 1: ",
x,
0,
100,
1
}
Horizontal{
int y = 40
Slider{
"Slider 2: ",
y,
0,
100,
2
}
int z = 90
Slider{
"Slider 3: ",
z,
0,
100,
5
}
int y = 40
YellowLight Slider{
"Slider 2: ",
y,
0,
100,
2
}
Horizontal{
Button{
"Exit",
"Exit",
Animated
}
White Button{
"Exit",
"Exit",
Animated
}
}
14 changes: 10 additions & 4 deletions include/quick-ftxui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ struct input {
};

struct slider {
colours color = colours::NoColor;
std::string label;
std::string value;
int min;
Expand Down Expand Up @@ -219,6 +220,7 @@ BOOST_FUSION_ADAPT_STRUCT(quick_ftxui_ast::input,
)

BOOST_FUSION_ADAPT_STRUCT(quick_ftxui_ast::slider,
(quick_ftxui_ast::colours, color)
(std::string, label)
(std::string, value)
(int, min)
Expand Down Expand Up @@ -434,9 +436,13 @@ struct node_printer : boost::static_visitor<> {

if (auto It = quick_ftxui_ast::numbers.find(std::string(text.value));
It != quick_ftxui_ast::numbers.end()) {
data->components.push_back(ftxui::Slider(text.label, (int *)(&It->second),
text.min, text.max,
text.increment));
ftxui::SliderOption<int> slider_opt;
slider_opt.value = (int *)(&It->second);
slider_opt.min = text.min, slider_opt.max = text.max, slider_opt.increment = text.increment;
slider_opt.color_active = resolveColour(text.color), slider_opt.color_inactive = ftxui::Color::GrayDark;
auto sldr = ftxui::Slider<int>(slider_opt);
auto with_label = ftxui::Renderer(sldr, [sldr, &text]{ return ftxui::hbox({ftxui::text(text.label), sldr->Render()}); });
data->components.push_back(with_label);
} else {
throw std::runtime_error("Variable " + text.value + " not found");
}
Expand Down Expand Up @@ -670,7 +676,7 @@ struct parser
input_comp %= qi::lit("Input") >> '{' >> quoted_string >>
-(',' >> inputopt_kw) >> ',' >> identifier >> '}';

slider_comp %= qi::lit("Slider") >> '{' >> quoted_string >> ',' >>
slider_comp %= -(color_kw) >> qi::lit("Slider") >> '{' >> quoted_string >> ',' >>
identifier >> ',' >> qi::int_ >> ',' >> qi::int_ >> ',' >>
qi::int_ >> '}';

Expand Down

0 comments on commit 141101a

Please sign in to comment.