39class ResizeDecorator :
public NodeDecorator {
47 : NodeDecorator(std::move(child)),
54 void Render(Screen& screen)
override {
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) {
105 element = std::make_shared<ResizeDecorator>(
117class WindowImpl :
public ComponentBase,
public WindowOptions {
119 explicit WindowImpl(WindowOptions option) : WindowOptions(std::move(option)) {
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);
147 element |=
reflect(box_window_);
148 element |= PositionAndSize(
left(),
top(), width(), height());
154 bool OnEvent(Event event)
final {
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_) {
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)) {
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;
Element Render()
Draw the component. Build a ftxui::Element to be drawn on the ftxui::Screen representing this ftxui::...
static App * Active()
Return the currently active screen, or null if none.
CapturedMouse CaptureMouse()
Try to get the unique lock about behing able to capture the mouse.
virtual bool OnEvent(Event)
Called in response to an event.
Component Window(WindowOptions option)
A draggeable / resizeable window. To use multiple of them, they must be stacked using Container::Stac...
friend void Render(Screen &screen, Node *node, Selection &selection)
Element window(Element title, Element content, BorderStyle border=ROUNDED)
Draw window with a title and a border around the element.
Element clear_under(Element element)
Before drawing |child|, clear the cells below. This is useful in combination with dbox.
Decorator size(WidthOrHeight, Constraint, int value)
Apply a constraint on the size of an element.
Element dim(Element)
Use a light font, for elements with less emphasis.
Element text(std::wstring_view text)
Display a piece of unicode text.
void Render(Screen &screen, const Element &element)
Display an element on a ftxui::Screen.
Element vbox(Elements)
A container displaying elements vertically one by one.
Color
Color is an enumeration that represents the color support of the terminal.
The FTXUI ftxui:: namespace.
std::function< Element(Element)> Decorator
std::unique_ptr< CapturedMouseInterface > CapturedMouse
std::shared_ptr< T > Make(Args &&... args)
std::shared_ptr< Node > Element
Element hbox(Elements)
A container displaying elements horizontally one by one.
Decorator reflect(Box &box)
std::shared_ptr< ComponentBase > Component