Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Sort widgets by parent before updating all (#2213)
Browse files Browse the repository at this point in the history
  • Loading branch information
MortimerGoro authored and bluemarvin committed Nov 8, 2019
1 parent 30a1a72 commit 2353c72
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion app/src/main/cpp/BrowserWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ struct BrowserWorld::State {
WidgetPtr GetWidget(int32_t aHandle) const;
WidgetPtr FindWidget(const std::function<bool(const WidgetPtr&)>& aCondition) const;
bool IsParent(const Widget& aChild, const Widget& aParent) const;
int ParentCount(const WidgetPtr& aWidget) const;
float ComputeNormalizedZ(const Widget& aWidget) const;
void SortWidgets();
};
Expand Down Expand Up @@ -566,6 +567,19 @@ BrowserWorld::State::IsParent(const Widget& aChild, const Widget& aParent) const
return false;
}

int
BrowserWorld::State::ParentCount(const WidgetPtr& aWidget) const {
int result = 0;
WidgetPtr current = aWidget;
while (current && current->GetPlacement()->parentHandle > 0) {
current = GetWidget(current->GetPlacement()->parentHandle);
if (current) {
result++;
}
}
return result;
}

float
BrowserWorld::State::ComputeNormalizedZ(const Widget& aWidget) const {
const vrb::Vector headPosition = device->GetHeadTransform().GetTranslation();
Expand Down Expand Up @@ -1123,7 +1137,19 @@ BrowserWorld::FinishWidgetMove() {
void
BrowserWorld::UpdateVisibleWidgets() {
ASSERT_ON_RENDER_THREAD();
for (const WidgetPtr& widget: m.widgets) {

std::vector<WidgetPtr> widgets = m.widgets;
// Sort by parent before updating.
std::sort(widgets.begin(), widgets.end(), [=](const WidgetPtr& a, const WidgetPtr& b) {
int parentsA = m.ParentCount(a);
int parentsB = m.ParentCount(b);
if (parentsA != parentsB) {
return parentsA < parentsB;
}
return m.IsParent(*b, *a);
});

for (const WidgetPtr& widget: widgets) {
if (widget->IsVisible() && !widget->IsResizing()) {
UpdateWidget(widget->GetHandle(), widget->GetPlacement());
}
Expand Down

0 comments on commit 2353c72

Please sign in to comment.