mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-15 23:48:15 +08:00
Add options for checkbox.
This commit is contained in:

committed by
Arthur Sonzogni

parent
359100ca73
commit
2b7daf061f
@@ -22,18 +22,11 @@ class CheckboxBase : public ComponentBase {
|
||||
static CheckboxBase* From(Component component);
|
||||
|
||||
// Constructor.
|
||||
CheckboxBase(ConstStringRef label, bool* state);
|
||||
CheckboxBase(ConstStringRef label,
|
||||
bool* state,
|
||||
ConstRef<CheckboxOption> option = {});
|
||||
~CheckboxBase() override = default;
|
||||
|
||||
std::wstring checked = L"▣ "; /// Prefix for a "checked" state.
|
||||
std::wstring unchecked = L"☐ "; /// Prefix for a "unchecked" state.
|
||||
|
||||
Decorator focused_style = inverted; /// Decorator used when focused.
|
||||
Decorator unfocused_style = nothing; /// Decorator used when unfocused.
|
||||
|
||||
/// Called when the user change the state of the CheckboxBase.
|
||||
std::function<void()> on_change = []() {};
|
||||
|
||||
// Component implementation.
|
||||
Element Render() override;
|
||||
bool OnEvent(Event) override;
|
||||
@@ -43,8 +36,8 @@ class CheckboxBase : public ComponentBase {
|
||||
|
||||
ConstStringRef label_;
|
||||
bool* const state_;
|
||||
int cursor_position = 0;
|
||||
Box box_;
|
||||
ConstRef<CheckboxOption> option_;
|
||||
};
|
||||
|
||||
} // namespace ftxui
|
||||
|
@@ -27,7 +27,9 @@ std::shared_ptr<T> Make(Args&&... args) {
|
||||
Component Button(ConstStringRef label,
|
||||
std::function<void()> on_click,
|
||||
ConstRef<ButtonOption> = {});
|
||||
Component Checkbox(ConstStringRef label, bool* checked);
|
||||
Component Checkbox(ConstStringRef label,
|
||||
bool* checked,
|
||||
ConstRef<CheckboxOption> option = {});
|
||||
Component Input(StringRef content, ConstStringRef placeholder);
|
||||
Component Menu(const std::vector<std::wstring>* entries,
|
||||
int* selected_,
|
||||
|
@@ -1,6 +1,8 @@
|
||||
#ifndef FTXUI_COMPONENT_COMPONENT_OPTIONS_HPP
|
||||
#define FTXUI_COMPONENT_COMPONENT_OPTIONS_HPP
|
||||
|
||||
#include <ftxui/dom/elements.hpp>
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
struct MenuOption {
|
||||
@@ -18,6 +20,17 @@ struct ButtonOption {
|
||||
bool border = true;
|
||||
};
|
||||
|
||||
struct CheckboxOption {
|
||||
std::wstring checked = L"▣ "; /// Prefix for a "checked" state.
|
||||
std::wstring unchecked = L"☐ "; /// Prefix for a "unchecked" state.
|
||||
|
||||
Decorator focused_style = inverted; /// Decorator used when focused.
|
||||
Decorator unfocused_style = nothing; /// Decorator used when unfocused.
|
||||
|
||||
/// Called when the user change the state.
|
||||
std::function<void()> on_change = []() {};
|
||||
};
|
||||
|
||||
}; // namespace ftxui
|
||||
|
||||
#endif /* end of include guard: FTXUI_COMPONENT_COMPONENT_OPTIONS_HPP */
|
||||
|
Reference in New Issue
Block a user