7namespace layout_designer {
44 for (
auto& panel :
panels) {
45 if (panel.panel_id == panel_id) {
54 if (
auto* found =
child_left->FindPanel(panel_id)) {
59 if (
auto* found =
child_right->FindPanel(panel_id)) {
83 auto clone = std::make_unique<DockNode>();
109 layout.
root = std::make_unique<DockNode>();
112 auto now = std::chrono::system_clock::now();
114 now.time_since_epoch()).count();
121 auto clone = std::make_unique<LayoutDefinition>();
132 clone->root =
root->Clone();
142 return root->FindPanel(panel_id);
146 std::vector<LayoutPanel*> result;
157 for (
auto& panel : node->panels) {
158 result.push_back(&panel);
161 collect(node->child_left.get());
162 collect(node->child_right.get());
173 *error_message =
"Layout name cannot be empty";
180 *error_message =
"Layout must have a root node";
186 std::function<bool(
const DockNode*)> validate_node =
190 *error_message =
"Null node found in tree";
196 if (!node->child_left || !node->child_right) {
198 *error_message =
"Split node must have both children";
203 if (node->split_ratio <= 0.0f || node->split_ratio >= 1.0f) {
205 *error_message =
"Split ratio must be between 0.0 and 1.0";
210 if (!validate_node(node->child_left.get())) {
213 if (!validate_node(node->child_right.get())) {
221 return validate_node(
root.get());
225 auto now = std::chrono::system_clock::now();
227 now.time_since_epoch()).count();
Represents a dock node in the layout tree.
void AddPanel(const LayoutPanel &panel)
void Split(ImGuiDir direction, float ratio)
std::vector< LayoutPanel > panels
LayoutPanel * FindPanel(const std::string &panel_id)
std::unique_ptr< DockNode > Clone() const
size_t CountPanels() const
std::unique_ptr< DockNode > child_left
std::unique_ptr< DockNode > child_right
Complete layout definition with metadata.
std::unique_ptr< LayoutDefinition > Clone() const
Clone the layout definition.
int64_t created_timestamp
std::vector< LayoutPanel * > GetAllPanels() const
Get all panels in the layout.
std::unique_ptr< DockNode > root
bool Validate(std::string *error_message=nullptr) const
Validate the layout structure.
static LayoutDefinition CreateEmpty(const std::string &name)
Create a default empty layout.
int64_t modified_timestamp
void Touch()
Update the modified timestamp to current time.
LayoutPanel * FindPanel(const std::string &panel_id) const
Find a panel by ID anywhere in the layout.
Represents a single panel in a layout.