2020-08-26 16:26:09 +02:00
|
|
|
#include "ftxui/component/button.hpp"
|
2021-05-01 18:13:56 +02:00
|
|
|
#include "ftxui/component/screen_interactive.hpp"
|
2020-08-26 16:26:09 +02:00
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
namespace ftxui {
|
|
|
|
|
|
|
|
Element Button::Render() {
|
2021-04-24 18:16:13 +02:00
|
|
|
auto style = Focused() ? inverted : nothing;
|
|
|
|
return text(label) | border | style | reflect(box_);
|
2020-08-26 16:26:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Button::OnEvent(Event event) {
|
2021-04-25 15:22:38 +02:00
|
|
|
if (event.is_mouse() && box_.Contain(event.mouse().x, event.mouse().y)) {
|
2021-05-01 18:13:56 +02:00
|
|
|
if (!event.screen()->CaptureMouse())
|
|
|
|
return false;
|
|
|
|
|
2021-04-25 15:22:38 +02:00
|
|
|
TakeFocus();
|
|
|
|
|
|
|
|
if (event.mouse().button == Mouse::Left &&
|
|
|
|
event.mouse().motion == Mouse::Pressed) {
|
2021-04-18 22:33:41 +02:00
|
|
|
on_click();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-08-26 16:26:09 +02:00
|
|
|
if (event == Event::Return) {
|
|
|
|
on_click();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace ftxui
|
|
|
|
|
|
|
|
// Copyright 2020 Arthur Sonzogni. All rights reserved.
|
|
|
|
// Use of this source code is governed by the MIT license that can be found in
|
|
|
|
// the LICENSE file.
|