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.
|
// The tree of components. This defines how to navigate using the keyboard.
|
||||||
auto buttons = Container::Horizontal({
|
auto buttons = Container::Horizontal({
|
||||||
Button("Decrease", [&] { value--; }),
|
Button("[Decrease]", [&] { value--; }, false),
|
||||||
Button("Increase", [&] { value++; }),
|
Button("[Increase]", [&] { value++; }, false),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Modify the way to render them on screen:
|
// Modify the way to render them on screen:
|
||||||
|
@ -21,7 +21,7 @@ class ButtonBase : public ComponentBase {
|
|||||||
static ButtonBase* From(Component);
|
static ButtonBase* From(Component);
|
||||||
|
|
||||||
// Constructor.
|
// Constructor.
|
||||||
ButtonBase(ConstStringRef label, std::function<void()> on_click);
|
ButtonBase(ConstStringRef label, std::function<void()> on_click, bool border);
|
||||||
~ButtonBase() override = default;
|
~ButtonBase() override = default;
|
||||||
|
|
||||||
// Component implementation.
|
// Component implementation.
|
||||||
@ -31,6 +31,7 @@ class ButtonBase : public ComponentBase {
|
|||||||
private:
|
private:
|
||||||
ConstStringRef label_;
|
ConstStringRef label_;
|
||||||
std::function<void()> on_click_;
|
std::function<void()> on_click_;
|
||||||
|
bool border_;
|
||||||
Box box_;
|
Box box_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -22,7 +22,9 @@ std::shared_ptr<T> Make(Args&&... args) {
|
|||||||
return std::make_shared<T>(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 Checkbox(ConstStringRef label, bool* checked);
|
||||||
Component Input(StringRef content, ConstStringRef placeholder);
|
Component Input(StringRef content, ConstStringRef placeholder);
|
||||||
Component Menu(const std::vector<std::wstring>* entries, int* selected_);
|
Component Menu(const std::vector<std::wstring>* entries, int* selected_);
|
||||||
|
@ -31,8 +31,10 @@ namespace ftxui {
|
|||||||
/// │Click to quit│
|
/// │Click to quit│
|
||||||
/// └─────────────┘
|
/// └─────────────┘
|
||||||
/// ```
|
/// ```
|
||||||
Component Button(ConstStringRef label, std::function<void()> on_click) {
|
Component Button(ConstStringRef label,
|
||||||
return Make<ButtonBase>(label, on_click);
|
std::function<void()> on_click,
|
||||||
|
bool border) {
|
||||||
|
return Make<ButtonBase>(label, on_click, border);
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
@ -40,12 +42,15 @@ ButtonBase* ButtonBase::From(Component component) {
|
|||||||
return static_cast<ButtonBase*>(component.get());
|
return static_cast<ButtonBase*>(component.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
ButtonBase::ButtonBase(ConstStringRef label, std::function<void()> on_click)
|
ButtonBase::ButtonBase(ConstStringRef label,
|
||||||
: label_(label), on_click_(on_click) {}
|
std::function<void()> on_click,
|
||||||
|
bool border)
|
||||||
|
: label_(label), on_click_(on_click), border_(border) {}
|
||||||
|
|
||||||
Element ButtonBase::Render() {
|
Element ButtonBase::Render() {
|
||||||
auto style = Focused() ? inverted : nothing;
|
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) {
|
bool ButtonBase::OnEvent(Event event) {
|
||||||
|
Loading…
Reference in New Issue
Block a user