Remove Ref<XxxOption> and add new interfaces. (#686)

1. Stop taking Ref<XxxOption> in Component constructors. Instead, use
   the XxxOption directly. Passing by copy avoid problems developers had
   where one was shared in between multiple component, causing issues.

2. Add variants of most component constructors taking a struct only.

This replaces:
https://github.com/ArthurSonzogni/FTXUI/pull/670

This fixes:
https://github.com/ArthurSonzogni/FTXUI/issues/426
This commit is contained in:
Arthur Sonzogni
2023-06-25 17:22:05 +02:00
committed by GitHub
parent e73e7f0d68
commit 455998d759
26 changed files with 918 additions and 693 deletions

View File

@@ -48,7 +48,7 @@ void UnderlineOption::SetAnimationFunction(
MenuOption MenuOption::Horizontal() {
MenuOption option;
option.direction = Direction::Right;
option.entries.transform = [](const EntryState& state) {
option.entries_option.transform = [](const EntryState& state) {
Element e = text(state.label);
if (state.focused) {
e |= inverted;
@@ -76,7 +76,7 @@ MenuOption MenuOption::HorizontalAnimated() {
// static
MenuOption MenuOption::Vertical() {
MenuOption option;
option.entries.transform = [](const EntryState& state) {
option.entries_option.transform = [](const EntryState& state) {
Element e = text((state.active ? "> " : " ") + state.label); // NOLINT
if (state.focused) {
e |= inverted;
@@ -95,7 +95,7 @@ MenuOption MenuOption::Vertical() {
// static
MenuOption MenuOption::VerticalAnimated() {
auto option = MenuOption::Vertical();
option.entries.transform = [](const EntryState& state) {
option.entries_option.transform = [](const EntryState& state) {
Element e = text(state.label);
if (state.focused) {
e |= inverted;
@@ -124,9 +124,9 @@ MenuOption MenuOption::Toggle() {
ButtonOption ButtonOption::Ascii() {
ButtonOption option;
option.transform = [](const EntryState& s) {
const std::string label = s.focused ? "[" + s.label + "]" //
: " " + s.label + " ";
return text(label);
const std::string t = s.focused ? "[" + s.label + "]" //
: " " + s.label + " ";
return text(t);
};
return option;
}