Updownquark / Quick

Quark's User Interface Creation Kit
0 stars 0 forks source link

CompoundListener #29

Closed Updownquark closed 11 years ago

Updownquark commented 12 years ago

(Changed from Annotation for attributes & styles)

It would ease development of new widgets, layouts, textures etc. if there were an annotation on types that would instruct a MUIS element to accept/require an attribute and have an option of an action to take when the attribute value changes. Also need an annotation that instructs an element to repaint or take an arbitrary action when a style attribute changes.

A good example would be with layouts. Right now, if a layout requires or can use certain attributes (e.g. orientation on the parent; x, y, width, height on the children) to do its job, it has to make all the calls to accept/require those attributes as well as add a listener for all those attributes to call the container's doLayout method. Instead, the layout class could be tagged with something like

@MuisAttributeConsumer(attributes={LayoutConstants.width, LayoutConstants.height}, action=MuisAction.layout)

When the given layout was set as an attribute on an element, the MuisTypeInstanceAttribute or some other system would check the type hierarchy (at least the class and all its super classes, maybe interfaces as well) for these annotations and add the listeners. If the attribute value changed, those accepted/required attributes would be reverted and the listeners removed automatically somehow.

This could really decrease the amount of boilerplate code required to create new MUIS classes. Have to figure out how to do this elegantly.

Updownquark commented 12 years ago

I have implemented this, but it's very ugly--mostly because you can't specify custom types in annotations, so that section about attributes={LayoutConstants.width... becomes attrs={@NeededAttr(name="width", type=MuisAttrType.SIZE)... and it's even more onerous for enum and arbitrary types. I might think about a compound listener class that would allow this stuff to be put together more cleanly and more customizably. I may or may not back out the stuff I've already done once there's a cleaner solution.

Updownquark commented 12 years ago

As mentioned in the most recent commit, I removed the @MuisAttributeConsumer annotation and its functionality for reasons outlined above. The CompoundListener utility does everything it did but much cleaner, easier, and less verbose.

I still need to add the capability to CompoundListener to react to style changes similarly to attribute changes.

Updownquark commented 12 years ago

I also need to add the ability to edit the attribute requirements of an element dynamically. Currently, the attribute requirements are locked after they are created. BorderLayout, for example, only accepts the width attribute if the widget is on the left or right region; it accepts the height attribute if and only if the widget is on the top or bottom region. This cannot be handled by the CompoundListener currently, but this utility should be expanded to allow this type of functionality.

Updownquark commented 11 years ago

Changed the name of this issue since the annotation idea didn't work out.

Updownquark commented 11 years ago

The CompoundListener class is basically complete. Not all of its functionality has been tested, but some has and I feel fairly confident that the logic of it all is sound, though there may be bugs that need to be worked out when it gets used more. This is done.