slint icon indicating copy to clipboard operation
slint copied to clipboard

WIP: Try to have generic tree traversal infrastructure

Open hunger opened this issue 3 years ago • 3 comments

This is not ready to be merged in any way or form!

The idea is to have a "logical item tree" where all the repeaters are replaced with their contents and have that accessible at the level of the ItemRc. This PR also implements a (non-recursive) traversals at the level of this logical tree. The good thing there is that this traversal does not need any generated helper code and that similar code can be used to move the focus item and probably more.

At this point the logical item tree is implemented in the Component which is not ideal IMHO as that needs to be implemnted in too many places. It would probably make sense to expose the (Component) ItemTree and a way of find embedded repeaters and move the code generating the logical item tree out of the Component.

This code contains stray println statements, commented out code and is generally buggy, but does render most of the UI in the viewer.

This PR is to get a feel for whether this direction is worthwhile or not.

hunger avatar Mar 10 '22 07:03 hunger

I think that this is the right direction. It looks like a substantial effort though. I like that this enables a stepwise iteration through the tree.

I hope this will help to avoid the entire "traverse through Repeaters" logic a couple of times more. That should really be in one place and properly tested instead of getting ad-hoc reimplementations.

The traversal through the repeater exists currently inside Repeater<C>::visit() in model.rs - used by Rust generated code & interpreter - as well as in Repeater::visit() in slint.h. Unless the Repeater is bridged entirely into Rust I don't think that will change - but OTOH that's probably fine.

tronical avatar Mar 10 '22 12:03 tronical

Do we need to be able to implement repeaters in C++ code?

I don't think that makes too much sense, so I am not concerned about making repeaters a (almost) rust-only thing. Other languages of course need to be able to add them into their tree, but I do not expect those languages to be used to implement custom traversal operations and such.

hunger avatar Mar 10 '22 14:03 hunger

Do we need to be able to implement repeaters in C++ code?

The model type in C++ is a template on the contained data type, which is a good API to expose. The repeated component is generated C++ that operates on the same model data type.

In Rust it is the same, Repeater is a generic on RepeatedComponent, which in turn provides the model data associated type.

The only way that I can see how we could use Rust's generic repeater with concrete C++ model data types would be complete type erasure, which could make C++ slower.

I'm uncertain if that is the right direction, given that the C++ repeater is ~150 LOC.

I might however be missing something :-)

tronical avatar Mar 10 '22 15:03 tronical

Not relevant anymore, this is now done in a different way.

hunger avatar Nov 29 '22 11:11 hunger