mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-22 20:58:10 +08:00
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:
@@ -72,6 +72,7 @@ struct AnimatedColorsOption {
|
||||
/// @brief Option for the MenuEntry component.
|
||||
/// @ingroup component
|
||||
struct MenuEntryOption {
|
||||
ConstStringRef label = "MenuEntry";
|
||||
std::function<Element(const EntryState& state)> transform;
|
||||
AnimatedColorsOption animated_colors;
|
||||
};
|
||||
@@ -86,9 +87,12 @@ struct MenuOption {
|
||||
static MenuOption VerticalAnimated();
|
||||
static MenuOption Toggle();
|
||||
|
||||
ConstStringListRef entries; ///> The list of entries.
|
||||
Ref<int> selected = 0; ///> The index of the selected entry.
|
||||
|
||||
// Style:
|
||||
UnderlineOption underline;
|
||||
MenuEntryOption entries;
|
||||
MenuEntryOption entries_option;
|
||||
Direction direction = Direction::Down;
|
||||
std::function<Element()> elements_prefix;
|
||||
std::function<Element()> elements_infix;
|
||||
@@ -115,6 +119,9 @@ struct ButtonOption {
|
||||
Color background_active,
|
||||
Color foreground_active);
|
||||
|
||||
ConstStringRef label = "Button";
|
||||
std::function<void()> on_click = [] {};
|
||||
|
||||
// Style:
|
||||
std::function<Element(const EntryState&)> transform;
|
||||
AnimatedColorsOption animated_colors;
|
||||
@@ -126,6 +133,10 @@ struct CheckboxOption {
|
||||
// Standard constructors:
|
||||
static CheckboxOption Simple();
|
||||
|
||||
ConstStringRef label = "Checkbox";
|
||||
|
||||
Ref<bool> checked = false;
|
||||
|
||||
// Style:
|
||||
std::function<Element(const EntryState&)> transform;
|
||||
|
||||
@@ -153,6 +164,9 @@ struct InputOption {
|
||||
/// @brief A white on black style with high margins:
|
||||
static InputOption Spacious();
|
||||
|
||||
/// The content of the input.
|
||||
StringRef content = "";
|
||||
|
||||
/// The content of the input when it's empty.
|
||||
StringRef placeholder = "";
|
||||
|
||||
@@ -176,6 +190,10 @@ struct RadioboxOption {
|
||||
// Standard constructors:
|
||||
static RadioboxOption Simple();
|
||||
|
||||
// Content:
|
||||
ConstStringListRef entries;
|
||||
Ref<int> selected = 0;
|
||||
|
||||
// Style:
|
||||
std::function<Element(const EntryState&)> transform;
|
||||
|
||||
|
Reference in New Issue
Block a user