Copying/templating widgets? #2531
-
I'm using Is there a reasonable "clone this widget hierarchy" mechanism? (I should probably just factor out the current widget construction code into a function that handles all three versions and builds them from scratch, it's just early enough in the prototyping that all of the code is still in |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
There's no builtin-mechanism to clone a widget hierarchy at present; but I'm not 100% sure we need one either. As you've noted, the best approach here is likely to refactor the construction code into a function. A clone mechanism is likely technically possible, but it would require every widget to gain a method to clone its current state. We'd also need to make decisions about whether some properties wouldn't be cloned - for example, should event handlers be cloned? On the one hand, it would be possible to write event handlers that response to where they are in the layout, but the easiest approach is to use a separate handler for every widget. Lastly, we'd need to encourage users to use the "lookup by ID" mechanism as the primary way of interacting with widgets - which, while it works, is a lot less efficient that retaining a reference to the widgets that you require. So - on balance, I'd suggest a clone mechanism is a complication that won't improve usability that much, and a "factory" method that produces the "similar, but slightly different" heirarchy is the approach we should encourage. |
Beta Was this translation helpful? Give feedback.
There's no builtin-mechanism to clone a widget hierarchy at present; but I'm not 100% sure we need one either. As you've noted, the best approach here is likely to refactor the construction code into a function.
A clone mechanism is likely technically possible, but it would require every widget to gain a method to clone its current state. We'd also need to make decisions about whether some properties wouldn't be cloned - for example, should event handlers be cloned? On the one hand, it would be possible to write event handlers that response to where they are in the layout, but the easiest approach is to use a separate handler for every widget. Lastly, we'd need to encourage users to use t…