Breaking It Down: Complex Controls As Combinations of Simple OnesThe list becomes much more manageable when we realize that the more complex controls are just clever combinations of other, more simple controls. For example, a scrollbar is basically just two buttons and a slider control. A checkbox is a static control and two buttons (one "off" button, and one "on" button). A plain old button could be implemented using three static icon controls (just show/hide the appropriate ones to get the button to "press"), so that you can reuse your drawing code. If you were really strapped for time, you could even implement a progress bar as a slider that's moved by the computer, though I prefer having a separate control for this. There are, however, disadvantages to this - namely, your GUI controls are going to take up more system resources than they really need. Think about it - each control is a window. Let's say you've gone with the reuse philosophy, and have created a button control that's really just three different statics. That's three windows per button. Now, you build a scrollbar control, using two button controls. That's six windows per scrollbar control. Build a List control using horizontal and vertical scrollbars, and you're sitting at twelve windows per list. It adds up quickly. So it's really just another example of the classic tradeoff between "how fast can I develop it" and "how little resources can I get it to use?" If you need a very high performance, no-waste GUI, implement each control from the ground up. If you would instead a quick implementation, and don't mind the performance hit, you might choose to implement your controls so that the only control that would actually draw to the screen would be the static, and all other controls would be made up of combinations of statics. When building my GUI, I tried to create a good balance between these two extremes. Now, let's dive into the actual implementation of each control, starting with everyone's favorite, the static label.
|
|