layout_node.hpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #pragma once
  2. #include <memory>
  3. #include <vector>
  4. #include "lumacs/window.hpp" // For Window class
  5. #include "lumacs/buffer.hpp" // For shared_ptr<Buffer> (indirectly via Window)
  6. namespace lumacs {
  7. // Forward declaration
  8. class Window;
  9. /// @brief Represents a node in the window layout tree.
  10. /// Can be a leaf node (holding a Window) or an internal node (representing a split).
  11. struct LayoutNode {
  12. enum class Type {
  13. Leaf,
  14. HorizontalSplit, // Children are top/bottom
  15. VerticalSplit // Children are left/right
  16. };
  17. Type type;
  18. std::shared_ptr<Window> window; // Valid if type is Leaf
  19. std::shared_ptr<LayoutNode> child1; // Valid if type is Horizontal/VerticalSplit
  20. std::shared_ptr<LayoutNode> child2; // Valid if type is Horizontal/VerticalSplit
  21. double ratio = 0.5; // Ratio for split (e.g., 0.5 for a 50/50 split)
  22. // Constructor for leaf nodes (a window)
  23. explicit LayoutNode(std::shared_ptr<Window> win)
  24. : type(Type::Leaf), window(std::move(win)) {}
  25. // Constructor for internal nodes (a split)
  26. LayoutNode(Type t, std::shared_ptr<LayoutNode> c1, std::shared_ptr<LayoutNode> c2)
  27. : type(t), child1(std::move(c1)), child2(std::move(c2)) {}
  28. };
  29. } // namespace lumacs