Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Added Spacious InputOption #32

Merged
merged 3 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ include(FetchContent)

if(QUICK_FTXUI_FETCH_BOOST)
FetchContent_Declare(Boost
URL https://github.com/boostorg/boost/releases/download/boost-1.81.0/boost-1.81.0.tar.gz
URL https://github.com/boostorg/boost/releases/download/boost-1.83.0/boost-1.83.0.tar.gz
TLS_VERIFY true
DOWNLOAD_EXTRACT_TIMESTAMP true
)
FetchContent_Populate(Boost)

Expand Down
2 changes: 1 addition & 1 deletion examples/input.qf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Vertical {
}
BlueLight Input {
"Last Name....",
None,
Spacious,
l
}
Red Input {
Expand Down
29 changes: 26 additions & 3 deletions include/quick-ftxui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct str_variable_decl;

enum block_alignment { VERTICAL, HORIZONTAL };
enum button_option { Ascii, Animated, Simple, NoOpt };
enum input_option { None, Password };
enum input_option { None, Password, Spacious };
enum sep_style { Normal, Light, Dashed, Double, Heavy };
enum borders {
NoBorder,
Expand Down Expand Up @@ -573,18 +573,35 @@ struct node_printer : boost::static_visitor<> {

if (auto It = quick_ftxui_ast::strings.find(std::string(text.value));
It != quick_ftxui_ast::strings.end()) {
ftxui::InputOption pass;

ftxui::InputOption pass = ftxui::InputOption::Default();
ftxui::Color input_clr = quick_ftxui_ast::resolveColour(text.color);

pass.transform = [input_clr](ftxui::InputState state) {
state.element |= ftxui::color(input_clr);
if (state.is_placeholder) {
state.element |= ftxui::dim;
}
if (state.is_placeholder && state.focused) {
state.element |= bgcolor(input_clr);
state.element |= ftxui::bgcolor(input_clr);
}
return state.element;
};

ftxui::InputOption spacious = ftxui::InputOption::Spacious();

spacious.transform = [input_clr](ftxui::InputState state) {
state.element |= ftxui::borderEmpty;
state.element |= ftxui::color(input_clr);
if (state.is_placeholder) {
state.element |= ftxui::dim;
}
if (state.is_placeholder && state.focused) {
state.element |= ftxui::bgcolor(input_clr);
}
return state.element;
};

switch (text.opt) {
case quick_ftxui_ast::input_option::None:
data->components.push_back(
Expand All @@ -596,6 +613,11 @@ struct node_printer : boost::static_visitor<> {
data->components.push_back(
ftxui::Input(&It->second, text.placeholder, pass));
break;

case quick_ftxui_ast::input_option::Spacious:
data->components.push_back(
ftxui::Input(&It->second, text.placeholder, spacious));
break;
default:
throw std::runtime_error("Should never reach here");
break;
Expand Down Expand Up @@ -897,6 +919,7 @@ struct parser
.add
("None", quick_ftxui_ast::input_option::None)
("Password", quick_ftxui_ast::input_option::Password)
("Spacious", quick_ftxui_ast::input_option::Spacious)
;

menuopt_kw
Expand Down
Loading