Page MenuHome

Property Search: Implementation of setting panel expansion when switching tabs
Closed, ResolvedPublicDESIGN

Description

I'm working on setting panel expansion when switching tabs, currently with this diff: P1651

I currently get the following behavior though. I'll describe why I think that is and propose
a couple solutions.

Imagine the search is for "sdklfjghs". There will be no results. Then imagine you switch
to a new tab where all the panels were previously open.

While the buttons inside the panel still need to be added for searching, they should be
removed / hidden because they should not be shown. You'd think it would be as simple as that--
no results, so hide the buttons. BUT, at the point where the panels are hidden, the subpanels
have not been searched, because the panel layout pass uses a breadth first tree traversal.
Because of that there's no way if the subpanels have results, and we don't have enough
information to know if the panel should close or not.

As "proof", here is how the search only field is set for the panel contents layout:
uiLayoutRootSetSearchOnly(panel->layout, search_only || !open);

This works fine (although only by accident) when staying in the same tab because there can
be multiple redraws. The first redraw finds whether there are results and sets the expansion
then the next redraw uses that proper expansion to properly remove buttons. But when
switching tabs there shouldn't be animation, so this all has to be done in one redraw.

There could be multiple ways to fix this:
1
I first thought of tying "other-tab" search (D8859) more closely to single tab search, so that
the expansion for ALL panels would be set on every redraw. This could probably work fine,
but I think the original idea was to separate the multi-tab search because it could possibly
be dangerous, and this means the same panel list would need to be used.
2
Convert the panel layout pass to be depth first so the subpanels would build their layout first.
I'm notsure if this would have any adverse consequences, but it would probably be pretty simple
to try, and it resolves this situation in theory.
3
Do a property search pass first that sets the panel expansion, then do a normal layout pass
(which would still need to include search in order to highlight buttons properly). This seems
pretty foolproof, and although this could be limited to when the tab changes, it's still double
the work in this situation, and it doesn't properly resolve the dependence on the panels'
previous expansion state.

Event Timeline

Hans Goudey (HooglyBoogly) changed the task status from Needs Triage to Confirmed.Sep 24 2020, 1:00 AM
Hans Goudey (HooglyBoogly) created this task.
Hans Goudey (HooglyBoogly) created this object with edit policy "All Users".
  • 1) does seem a little risky/error prone & worth avoiding.
  • 2) am I right in assuming this impacts all layouts for drawing? (not only while searching), in this case I don't know if this would cause issues but changing panel layout logic only for search could introduce errors.

    If it's significantly simpler it might be worth writing a patch to test it out.
  • 3) While this seems OK.
    • Do you think the extra pass will be give a noticeable performance loss?
    • Dealing with the previous expansion state seems important to resolve, is this something that can be handled separately?

Dealing with the previous expansion state seems important to resolve, is this something that can be handled separately?

I agree, and it will be important to have regardless of supporting multi-tab search.

Convert the panel layout pass to be depth first so the subpanels would build their layout first.

This confuses me, the panel layout is already done depth first, but it's pre-order traversal. You seem to suggest switching to post-order traversal? Are we talking about the same thing, that is ed_panel_draw() calls?

It seems the issue is how ed_panel_draw() mixes the item definition and the layout phase. Couldn't we separate them, like we've already split out the drawing phase? We could do a much more sane definitionapply searchlayout pipeline. Either as entirely separate passes or for a single root panel at a time.
I guess that would be 3).
I'm not sure why you need to run the search during the layout pass, but I think that's not such a big deal.

Regarding "previous expansion state", do you mean keeping the expansion state stored that the search overrides? Can't this just be a different flag from PNL_CLOSED, stored in Panel.runtime_flag? Would be nicer to have a UI_panel_is_closed() query anyway.

Thanks for the response.

Dealing with the previous expansion state seems important to resolve, is this something that can be handled separately?

Yes, I agree that it's quite important.

It turns out even number two doesn't quite work, because the "search only" status of a subpanel depends on whether its parent is open, and that can't be known if we do the layout for the parent panel first.
So I think this needs to be done in two separate passes. I think I've found a much better way to accomplish that than running the whole layout pass twice though-- keeping all the blocks and buttons around
during the layout process and then remove the invisible ones at the end in a separate pass. The only complication is sometimes just panel headers need to be visible but not their contents. I'll work through
this and report back.

This confuses me, the panel layout is already done depth first, but it's pre-order traversal. You seem to suggest switching to post-order traversal? Are we talking about the same thing, that is ed_panel_draw() calls?

Oh yes, I messed up the terminology here. That's what I meant to suggest. Oops! This actually won't work like I thought though, (see my previous comment).

I'm not sure why you need to run the search during the layout pass, but I think that's not such a big deal.

Currently the "button groups" are freed after the layout pass as they're stored in uiLayoutRoot, but I guess that could change. I also agree this isn't a big deal though-- the important change that has to happen is separating the search and panel expansion from search passes.

Can't this just be a different flag from PNL_CLOSED, stored in Panel.runtime_flag? Would be nicer to have a UI_panel_is_closed() query anyway.

That's a good suggestion for my patch that restores the panel expansion after search is closed, but I don't think it actually applies here. The essence of the problem is that all buttons must be added for search, but there needs to be a way to remove / disappear a subset of them at the end. Currently this happens during the ed_panel_draw layout pass, but I'm suggesting moving it to a separate pass at the end in UI_panels_end.

Okay, I found a fairly nice solution: D9006

Nice, as it removes all the "search only" handling from the area and property search layout code.

Thanks for the input.