39class ResizeDecorator :
public NodeDecorator {
47 : NodeDecorator(std::move(child)),
54 void Render(Screen& screen)
override {
55 NodeDecorator::Render(screen);
58 for (
int y = box_.y_min;
y <= box_.y_max; ++
y) {
59 auto& cell = screen.CellAt(box_.x_min,
y);
60 cell.foreground_color =
color_;
61 cell.automerge =
false;
65 for (
int y = box_.y_min;
y <= box_.y_max; ++
y) {
66 auto& cell = screen.CellAt(box_.x_max,
y);
67 cell.foreground_color =
color_;
68 cell.automerge =
false;
72 for (
int x = box_.x_min; x <= box_.x_max; ++x) {
73 auto& cell = screen.CellAt(x, box_.y_min);
74 cell.foreground_color =
color_;
75 cell.automerge =
false;
79 for (
int x = box_.x_min; x <= box_.x_max; ++x) {
80 auto& cell = screen.CellAt(x, box_.y_max);
81 cell.foreground_color =
color_;
82 cell.automerge =
false;
94Element DefaultRenderState(
const WindowRenderState& state) {
103 const Color color = Color::Red;
105 element = std::make_shared<ResizeDecorator>(
117class WindowImpl :
public ComponentBase,
public WindowOptions {
119 explicit WindowImpl(WindowOptions option) : WindowOptions(std::move(option)) {
128 auto element = ComponentBase::Render();
130 const bool captureable = captured_mouse_ || App::Active()->CaptureMouse();
132 const WindowRenderState state = {
139 (resize_right_hover_ || resize_right_) && captureable,
141 (resize_down_hover_ || resize_down_) && captureable,
144 element = render ? render(state) : DefaultRenderState(state);
154 bool OnEvent(Event event)
final {
155 if (ComponentBase::OnEvent(event)) {
159 if (!event.is_mouse()) {
163 mouse_hover_ = box_window_.Contain(event.mouse().x, event.mouse().y);
165 resize_down_hover_ =
false;
166 resize_top_hover_ =
false;
167 resize_left_hover_ =
false;
168 resize_right_hover_ =
false;
171 resize_left_hover_ =
event.mouse().x ==
left() + box_.x_min;
172 resize_right_hover_ =
173 event.mouse().x ==
left() + width() - 1 + box_.x_min;
174 resize_top_hover_ =
event.mouse().y ==
top() + box_.y_min;
175 resize_down_hover_ =
event.mouse().y ==
top() + height() - 1 + box_.y_min;
178 resize_top_hover_ &= resize_top();
179 resize_left_hover_ &= resize_left();
180 resize_down_hover_ &= resize_down();
181 resize_right_hover_ &= resize_right();
184 if (captured_mouse_) {
185 if (event.mouse().motion == Mouse::Released) {
186 captured_mouse_ =
nullptr;
191 width() =
left() + width() -
event.mouse().x + box_.x_min;
192 left() =
event.mouse().x - box_.x_min;
196 width() =
event.mouse().x - resize_start_x - box_.x_min;
200 height() =
top() + height() -
event.mouse().y + box_.y_min;
201 top() =
event.mouse().y - box_.y_min;
205 height() =
event.mouse().y - resize_start_y - box_.y_min;
209 left() =
event.mouse().x - drag_start_x - box_.x_min;
210 top() =
event.mouse().y - drag_start_y - box_.y_min;
214 width() = std::max<int>(width(),
static_cast<int>(title().
size() + 2));
215 height() = std::max<int>(height(), 2);
229 if (!CaptureMouse(event)) {
233 if (event.mouse().button != Mouse::Left) {
236 if (event.mouse().motion != Mouse::Pressed) {
242 captured_mouse_ = CaptureMouse(event);
243 if (!captured_mouse_) {
252 resize_start_x =
event.mouse().x - width() - box_.x_min;
253 resize_start_y =
event.mouse().y - height() - box_.y_min;
254 drag_start_x =
event.mouse().x -
left() - box_.x_min;
255 drag_start_y =
event.mouse().y -
top() - box_.y_min;
266 int drag_start_x = 0;
267 int drag_start_y = 0;
268 int resize_start_x = 0;
269 int resize_start_y = 0;
271 bool mouse_hover_ =
false;
278 bool resize_top_hover_ =
false;
279 bool resize_left_hover_ =
false;
280 bool resize_down_hover_ =
false;
281 bool resize_right_hover_ =
false;
Component Window(WindowOptions option)
A draggeable / resizeable window. To use multiple of them, they must be stacked using Container::Stac...
Element window(Element title, Element content, BorderStyle border=ROUNDED)
Draw window with a title and a border around the element.
Element text(std::string_view text)
Display a piece of UTF8 encoded unicode text.
Element clear_under(Element element)
Before drawing |child|, clear the cells below. This is useful in combination with dbox.
Decorator size(WidthOrHeight direction, Constraint constraint, int value)
Apply a constraint on the size of an element.
Element dim(Element child)
Use a light font, for elements with less emphasis.
Element vbox(Elements children)
A container displaying elements vertically one by one.
The FTXUI ftxui:: namespace.
std::unique_ptr< CapturedMouseInterface > CapturedMouse
std::shared_ptr< T > Make(Args &&... args)
std::shared_ptr< Node > Element
Element hbox(Elements children)
A container displaying elements horizontally one by one.
std::function< Element(Element)> Decorator
Decorator reflect(Box &box)
void Render(Screen &screen, Node *node, Selection &selection)
std::shared_ptr< ComponentBase > Component