PDA

View Full Version : Custom UI Controls


damTyD
01-24-2011, 03:46 PM
I am building custom UI controls, eg. Button, Scrollbar, Checkbox, etc. I will want to be able to add new controls at a later time when needed. These controls will render in two ways. 1) import external images and position them 2) draw using code according to given properties such as background-color, highlight-color, etc.

I will have a UIManager class that will return the entire component by calling a method such as uiManager.getComponent("componentName","skinName"). I figure the UIManager will construct the component, and apply the skin. I currently have a UIPackage class which, in a way, acts as the skin by setting property names in one array, and property values in another that lines up with the property names. So a property could be a URL to an image, or values used to draw the custom component.

The issue I'm having is who is going to draw the component? Should Button be concerned with how it renders, or should I have a separate class to handle the actual display of the Button, and Button would only be concerned with it's state management.

The component that really makes me think of this is the Scrollbar. There will be a top button, bottom button, and scroller button, along with the base graphics. Shouldn't the scrollbar only be concerned with functioning and state, and take each of the controls in as some type of class that would have a sizeTo method? And if so, how can I create a system like this without having a Scrollbar class and another ScrollbarDisplay class, etc for each component?

I was thinking about using a Factory for the actually graphic rendering.