mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-15 15:38:21 +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:
@@ -40,37 +40,42 @@ Component Vertical(Components children, int* selector);
|
||||
Component Horizontal(Components children);
|
||||
Component Horizontal(Components children, int* selector);
|
||||
Component Tab(Components children, int* selector);
|
||||
|
||||
} // namespace Container
|
||||
|
||||
Component Button(ButtonOption options);
|
||||
Component Button(ConstStringRef label,
|
||||
std::function<void()> on_click,
|
||||
Ref<ButtonOption> = ButtonOption::Simple());
|
||||
ButtonOption options = ButtonOption::Simple());
|
||||
|
||||
Component Checkbox(CheckboxOption options);
|
||||
Component Checkbox(ConstStringRef label,
|
||||
bool* checked,
|
||||
Ref<CheckboxOption> option = CheckboxOption::Simple());
|
||||
CheckboxOption options = CheckboxOption::Simple());
|
||||
|
||||
Component Input(StringRef content, Ref<InputOption> option = {});
|
||||
Component Input(InputOption options = {});
|
||||
Component Input(StringRef content, InputOption options = {});
|
||||
Component Input(StringRef content,
|
||||
StringRef placeholder,
|
||||
Ref<InputOption> option = {});
|
||||
InputOption options = {});
|
||||
|
||||
Component Menu(MenuOption options);
|
||||
Component Menu(ConstStringListRef entries,
|
||||
int* selected_,
|
||||
Ref<MenuOption> = MenuOption::Vertical());
|
||||
Component MenuEntry(ConstStringRef label, Ref<MenuEntryOption> = {});
|
||||
|
||||
Component Dropdown(ConstStringListRef entries, int* selected);
|
||||
MenuOption options = MenuOption::Vertical());
|
||||
Component MenuEntry(MenuEntryOption options);
|
||||
Component MenuEntry(ConstStringRef label, MenuEntryOption options = {});
|
||||
|
||||
Component Radiobox(RadioboxOption options);
|
||||
Component Radiobox(ConstStringListRef entries,
|
||||
int* selected_,
|
||||
Ref<RadioboxOption> option = {});
|
||||
RadioboxOption options = {});
|
||||
|
||||
Component Dropdown(ConstStringListRef entries, int* selected);
|
||||
Component Toggle(ConstStringListRef entries, int* selected);
|
||||
|
||||
// General slider constructor:
|
||||
template <typename T>
|
||||
Component Slider(SliderOption<T> options = {});
|
||||
Component Slider(SliderOption<T> options);
|
||||
|
||||
// Shorthand without the `SliderOption` constructor:
|
||||
Component Slider(ConstStringRef label,
|
||||
@@ -89,11 +94,11 @@ Component Slider(ConstStringRef label,
|
||||
ConstRef<long> max = 100l,
|
||||
ConstRef<long> increment = 5l);
|
||||
|
||||
Component ResizableSplit(ResizableSplitOption options);
|
||||
Component ResizableSplitLeft(Component main, Component back, int* main_size);
|
||||
Component ResizableSplitRight(Component main, Component back, int* main_size);
|
||||
Component ResizableSplitTop(Component main, Component back, int* main_size);
|
||||
Component ResizableSplitBottom(Component main, Component back, int* main_size);
|
||||
Component ResizableSplit(ResizableSplitOption options);
|
||||
|
||||
Component Renderer(Component child, std::function<Element()>);
|
||||
Component Renderer(std::function<Element()>);
|
||||
|
@@ -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