Merge dom and component focus (#978)

Instead of two levels of focus with `focus` and `selected`, use a recursive
level. The components set the one "active" and hbox/vbox/dbox 

Co-authored-by: ArthurSonzogni <sonzogniarthur@gmail.com>
This commit is contained in:
Ayaan
2025-03-19 20:03:05 +05:30
committed by GitHub
parent 8519e9b0f3
commit b0e087ecef
38 changed files with 431 additions and 341 deletions

View File

@@ -89,6 +89,7 @@ class Flexbox : public Node {
}
void ComputeRequirement() override {
requirement_ = Requirement{};
for (auto& child : children_) {
child->ComputeRequirement();
}
@@ -103,12 +104,6 @@ class Flexbox : public Node {
}
Layout(global, true);
// Reset:
requirement_.selection = Requirement::Selection::NORMAL;
requirement_.selected_box = Box();
requirement_.min_x = 0;
requirement_.min_y = 0;
if (global.blocks.empty()) {
return;
}
@@ -130,19 +125,14 @@ class Flexbox : public Node {
// Find the selection:
for (size_t i = 0; i < children_.size(); ++i) {
if (requirement_.selection >= children_[i]->requirement().selection) {
continue;
if (requirement_.focused.Prefer(children_[i]->requirement().focused)) {
requirement_.focused = children_[i]->requirement().focused;
// Shift |focused.box| according to its position inside this component:
auto& b = global.blocks[i];
requirement_.focused.box.Shift(b.x, b.y);
requirement_.focused.box =
Box::Intersection(requirement_.focused.box, box);
}
requirement_.selection = children_[i]->requirement().selection;
Box selected_box = children_[i]->requirement().selected_box;
// Shift |selected_box| according to its position inside this component:
auto& b = global.blocks[i];
selected_box.x_min += b.x;
selected_box.y_min += b.y;
selected_box.x_max += b.x;
selected_box.y_max += b.y;
requirement_.selected_box = Box::Intersection(selected_box, box);
}
}