mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-11-26 04:31:34 +08:00
Add option to have button without border. (#101)
This commit is contained in:
parent
ab9d6feaa5
commit
7b88656e25
@ -14,8 +14,8 @@ int main(int argc, const char* argv[]) {
|
||||
|
||||
// The tree of components. This defines how to navigate using the keyboard.
|
||||
auto buttons = Container::Horizontal({
|
||||
Button("Decrease", [&] { value--; }),
|
||||
Button("Increase", [&] { value++; }),
|
||||
Button("[Decrease]", [&] { value--; }, false),
|
||||
Button("[Increase]", [&] { value++; }, false),
|
||||
});
|
||||
|
||||
// Modify the way to render them on screen:
|
||||
|
@ -21,7 +21,7 @@ class ButtonBase : public ComponentBase {
|
||||
static ButtonBase* From(Component);
|
||||
|
||||
// Constructor.
|
||||
ButtonBase(ConstStringRef label, std::function<void()> on_click);
|
||||
ButtonBase(ConstStringRef label, std::function<void()> on_click, bool border);
|
||||
~ButtonBase() override = default;
|
||||
|
||||
// Component implementation.
|
||||
@ -31,6 +31,7 @@ class ButtonBase : public ComponentBase {
|
||||
private:
|
||||
ConstStringRef label_;
|
||||
std::function<void()> on_click_;
|
||||
bool border_;
|
||||
Box box_;
|
||||
};
|
||||
|
||||
|
@ -22,7 +22,9 @@ std::shared_ptr<T> Make(Args&&... args) {
|
||||
return std::make_shared<T>(args...);
|
||||
}
|
||||
|
||||
Component Button(ConstStringRef label, std::function<void()> on_click);
|
||||
Component Button(ConstStringRef label,
|
||||
std::function<void()> on_click,
|
||||
bool border = true);
|
||||
Component Checkbox(ConstStringRef label, bool* checked);
|
||||
Component Input(StringRef content, ConstStringRef placeholder);
|
||||
Component Menu(const std::vector<std::wstring>* entries, int* selected_);
|
||||
|
@ -31,8 +31,10 @@ namespace ftxui {
|
||||
/// │Click to quit│
|
||||
/// └─────────────┘
|
||||
/// ```
|
||||
Component Button(ConstStringRef label, std::function<void()> on_click) {
|
||||
return Make<ButtonBase>(label, on_click);
|
||||
Component Button(ConstStringRef label,
|
||||
std::function<void()> on_click,
|
||||
bool border) {
|
||||
return Make<ButtonBase>(label, on_click, border);
|
||||
}
|
||||
|
||||
// static
|
||||
@ -40,12 +42,15 @@ ButtonBase* ButtonBase::From(Component component) {
|
||||
return static_cast<ButtonBase*>(component.get());
|
||||
}
|
||||
|
||||
ButtonBase::ButtonBase(ConstStringRef label, std::function<void()> on_click)
|
||||
: label_(label), on_click_(on_click) {}
|
||||
ButtonBase::ButtonBase(ConstStringRef label,
|
||||
std::function<void()> on_click,
|
||||
bool border)
|
||||
: label_(label), on_click_(on_click), border_(border) {}
|
||||
|
||||
Element ButtonBase::Render() {
|
||||
auto style = Focused() ? inverted : nothing;
|
||||
return text(*label_) | border | style | reflect(box_);
|
||||
auto my_border = border_ ? border : nothing;
|
||||
return text(*label_) | my_border | style | reflect(box_);
|
||||
}
|
||||
|
||||
bool ButtonBase::OnEvent(Event event) {
|
||||
|
Loading…
Reference in New Issue
Block a user