excessive / DOMy

A DOM-like GUI framework for the *awesome* LÖVE framework
Other
32 stars 2 forks source link

Cloning Elements #18

Closed karai17 closed 9 years ago

karai17 commented 9 years ago

I am currently implementing the base Element object and I need to know what people would expect from a cloned element.

When cloning an Element, do you simply expect a default element of the same type with the same value, an element with the same value and properties (such as visual styles) and scripts, or something else?

My issue with cloning properties verbatim is that some properties such as positioning are going to be relative (unless otherwise specified) so if you clone an element that is 10 dp to the left and it was inside some other element, this new element will be 10 dp left from the screen which is not in the same position at all. Is that expected behaviour?

adrix89 commented 9 years ago

It would be best to make sense in the hierarchical context. Lets say we have two lists with some items in it. Cloning elements from one list to another the element should be just like the rest of the items in that list.

I think the easiest way to achieve this is to let the parent manage the organization and style of the elements and the elements should be in a default blank state. if the elements are give any style/position/whatever then that should override the parent and that should be cloned.

karai17 commented 9 years ago

Here is a thought: Is cloning an element even necessary? I have alternative plans for templating so let's not confuse the two. Is cloning an active element (and possibly its children) even a useful task?

Are there any use cases where I would need two of the exact same button, or text box, or list, or...?

adrix89 commented 9 years ago

I can see where you would need a duplicate. Say you have character with an inventory and another character with another inventory at the same time where you can trade items between those characters. You can even have 3,4,6 characters depending on how you organize it. To be fair you can probably do it some other way, like you said templates, but templates are a form of duplication anyway. A thing you should keep in mind about cloning is that what you absolutely need is functions and the graphics and whatever animations and effects that has been coded in the elements(aka functions AND graphics) How you get those functions and graphics doesn't matter, whether templates,styles,classes,IDs,whatever. Data like values and tables are always easily modifiable,that would be the reason why you can clone elements and populate it with a characters data.

karai17 commented 9 years ago

Trading items wouldn't involve duplicating GUI elements. At best it would be moving them.

If you are talking the inventory window, that would be a template not a straight duplication. My concern here is that duplicating existing elements and their internal data isn't entirely useful. On Jan 20, 2015 3:21 AM, "adrix89" notifications@github.com wrote:

I can see where you would need a duplicate. Say you have character with an inventory and another character with another inventory at the same time where you can trade items between those characters. You can even have 3 characters. To be fair you can probably do it some other way, like you said templates, but templates are a form of duplication anyway. A thing you should keep in mind about cloning is the what you absolutely need is functions and the graphics and whatever animations and effects that has been coded in the elements(aka functions AND graphics) How you get those functions and graphics doesn't matter, whether templates,styles,classes,IDs,whatever.

— Reply to this email directly or view it on GitHub https://github.com/excessive/DOMinatrix/issues/18#issuecomment-70619135.

adrix89 commented 9 years ago

that would be a template not a straight duplication.

It doesn't matter what it is as long as it contains functions and data.

Another example: Lets say we have a custom load bar that instead of one fill bar(the filing part) it has multiple fill bars. It with have the same total value and min and max but also a table with the values of the different fills. Think of it as the character attributes where you have the base stats and the bonuses by equipment and buffs. Hovering the different parts of the attribute bar will give you different tooltips. This is a custom element that may override the normal load bar. If this functionality is done by classes or templates or whatever you don't have to worry but if its done by overrides you would have to copy the overrides.

karai17 commented 9 years ago

I think you are misunderstanding here. What I am talking about is directly copying an active object (and optionally all of its children). Extending elements, creating custom elements, or writing widgets (templates) are not in the scope of this issue.

This issue is: Is it useful to make a carbon copy of an already active element, and if so, why? If it isn't useful then I just won't implement it. If it is, I'll add it.

karai17 commented 9 years ago

Alright so I have decided to add Element cloning with an optional flag to clone all children as well. A cloned element will be a root element by default and you can then attach it to someplace else if you so desire. Optionally there is a parent argument you can immediately attach a clone to.

karai17 commented 9 years ago

Clone now works!