FTXUI icon indicating copy to clipboard operation
FTXUI copied to clipboard

input.cpp field length.

Open jgrillout opened this issue 2 years ago • 2 comments

I'm looking at the sample code for input.cpp. Is there a way to specify a fields length?

jgrillout avatar Jan 12 '24 21:01 jgrillout

Hello @jgrillout, See this example:

  • https://arthursonzogni.github.io/FTXUI/examples/?file=component/input
  • https://github.com/ArthurSonzogni/FTXUI/blob/5112d9139dfdd58f80230d30514e3e5d58735839/examples/component/input.cpp#L39-L41C6

You can use CatchEvent to filter out characters beyond a given length:

std::string input_string = "example";
auto input = Input({
  .content = &input_string,
  .placeholder = "This input allows up to 10 characters"
});

// Filter out characters beyond the 10th one.
input |= CatchEvent([&input_string](Event event) {
  return event.is_character() && input_string.size() > 10;
});

Does it solves your use case?

ArthurSonzogni avatar Jan 14 '24 16:01 ArthurSonzogni

Very helpful. Thanks 😊

From: Arthur Sonzogni @.> Sent: Sunday, January 14, 2024 11:19 AM To: ArthurSonzogni/FTXUI @.> Cc: jgrillout @.>; Mention @.> Subject: Re: [ArthurSonzogni/FTXUI] input.cpp field length. (Issue #808)

Hello @jgrillout https://github.com/jgrillout , See this example:

  • https://arthursonzogni.github.io/FTXUI/examples/?file=component/input
  • https://github.com/ArthurSonzogni/FTXUI/blob/5112d9139dfdd58f80230d30514e3e5d58735839/examples/component/input.cpp#L39-L41C6

You can use CatchEvent to filter out characters beyond a given length:

std::string input_string = "example"; auto input = Input({ .content = &input_string, .placeholder = "This input allows up to 10 characters" });

// Filter out characters beyond the 10th one. input |= CatchEvent([&input_string](Event event) { return event.is_character() && input_string.size() > 10; });

Does it solves your use case?

— Reply to this email directly, view it on GitHub https://github.com/ArthurSonzogni/FTXUI/issues/808#issuecomment-1890995822 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AGBBZ6ZY5TL6TJLN5CWKOULYOQAPXAVCNFSM6AAAAABBYXOMQ2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOJQHE4TKOBSGI . You are receiving this because you were mentioned. https://github.com/notifications/beacon/AGBBZ64C7PG6W2BOUHDHM7LYOQAPXA5CNFSM6AAAAABBYXOMQ2WGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTTQWZHG4.gif Message ID: @.*** @.***> >

jgrillout avatar Jan 15 '24 16:01 jgrillout