Closed mitchmindtree closed 10 years ago
Hi,
I was trying to implement it. I have a few questions. 1) Shouldn't it be Vec < Box < Widget > > ? 2) get_widget in ui_context inserts a widget for you if not already present. To support the same thing using Vec, we need to check if the ui_id falls within it's range and if not, resize it etc etc. I think to make it worth the change:
I tried pushing for a new Widget which would work if we were storing widgets in increasing uiid order starting from 0 but inside demo we either save button (start at 0 and go to 2 directly) or slider(start at 1) the first time and it won't work.
Does it make sense? Am I missing something (very likely)?
Thanks for your time.
@eklavya thanks for contributing and sharing your ideas!
I don't think resize should be an issue - to save on performance I think it'd be best to initialise the vector with a very large number of NoWidget
s (an empty variant we could add to the Widget
enum) - this way we wouldn't need any resizing.
As for the automatic UIID- The only way I see this working is if the user always called every widget in the same order, however this is often not practical and would restrict the user from drawing widgets conditionally or within loops that have dynamic ranges.
I've had a long think about how to automatically generate UIIDs in a practical way - the closest I got was to make a procedural macro that created a unique u64 in ever instance it was called, however this macro would have to be highly contextually aware i.e. whether or not it is being called within for
, while
and loop
loops which I don't yet know how to approach.
Perhaps I'm misunderstanding your suggestion though - if your solution works feel free to update to master and do a PR so we can check it out :+1: If you have a solution so that the user is not required to write their own UIID, then that would be great! However it is my understanding that this is one of the caveats of Immediate-Mode GUIs.
Completed with #118
A widget's UIID could simply represent the index at which its state is stored within the Vec (this would be faster than checking as a key)