FTXUI/include/ftxui/dom/requirement.hpp

52 lines
1.2 KiB
C++
Raw Permalink Normal View History

2023-08-19 19:56:36 +08:00
// 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.
#ifndef FTXUI_DOM_REQUIREMENT_HPP
#define FTXUI_DOM_REQUIREMENT_HPP
2018-09-18 14:48:40 +08:00
2019-01-20 05:06:05 +08:00
#include "ftxui/screen/box.hpp"
#include "ftxui/screen/screen.hpp"
2019-01-20 05:06:05 +08:00
namespace ftxui {
class Node;
2018-09-18 14:48:40 +08:00
struct Requirement {
// The required size to fully draw the element.
2020-06-01 22:13:29 +08:00
int min_x = 0;
int min_y = 0;
2018-09-18 14:48:40 +08:00
// How much flexibility is given to the component.
int flex_grow_x = 0;
int flex_grow_y = 0;
int flex_shrink_x = 0;
int flex_shrink_y = 0;
2019-01-20 05:06:05 +08:00
2020-06-01 22:13:29 +08:00
// Focus management to support the frame/focus/select element.
struct Focused {
bool enabled = false;
Box box;
Node* node = nullptr;
Screen::Cursor::Shape cursor_shape = Screen::Cursor::Shape::Hidden;
// Internal for interactions with components.
bool component_active = false;
// Return whether this requirement should be preferred over the other.
bool Prefer(const Focused& other) const {
if (!other.enabled) {
return false;
}
if (!enabled) {
return true;
}
return other.component_active && !component_active;
}
2020-06-01 22:13:29 +08:00
};
Focused focused;
2018-09-18 14:48:40 +08:00
};
} // namespace ftxui
2018-09-18 14:48:40 +08:00
2022-03-31 08:17:43 +08:00
#endif // FTXUI_DOM_REQUIREMENT_HPP