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

Sort widgets by parent before updating all #2213

Merged
merged 1 commit into from
Nov 8, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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