Hi.
Just for fun and exercise I have started to create my own GUI toolkit, much like AWT, Swing, Qt, etc.
Its not my goal to make the next big thing and cash in lots of moneys; I just want to spend some time on more complex projects as a kind of training.
Now this is a fairly complicated project and I have already spent a couple of hours just planning all kinds of classes I could need for this and how all these classes are supposed to work together, and now I want to share some of my thoughts and maybe get some advice from more experienced programmers; maybe a push in the right (or better) direction.
Heres the basic concept:
- Everything in the GUI is a component
- Components are structured in a ComponentTree
- The ComponentTree manages the updating and rendering of all components in the GUI
- Components always have a parent (which is a component) unless they are the root of the ComponentTree
- Components can have any number of children (which are components)
- The componentTree is rendered by an in-order traversal of the tree starting at the root
- The componentTree is updated by a level-order traversal starting at the leafs (going up the tree to the root)
- Each component defines a viewport (rectangular) and its children must be contained completely within the viewport of their parent
- The viewport of a child must be contained completely within the viewport of its parent
Very rough draft of the class hierarchy:
GUI-Toolkit-Classes.jpg
A basic example GUI: (Showing a frame, menubar, panels to the left and bottom, and a pane with a picture in the center. Also: a border layout)
GUI-Example.jpg
This is how the component tree would look like internally: (for the example GUI above)
Frame { Menu Bar { File MenuButton { File MenuButton label } Edit MenuButton { Edit MenuButton label } About MenuButton { About MenuButton label } } Left Panel { } Center Pane { Picture } Bottom Panel { } }
There are also 2 other important aspects I left out so far:
- Compositions & Layouts
- A Composition is a component that you can add / remove other components to / from (Composition is an interface)
- A Composition can have a layout attached. The layout of the composition can change the positioning and size of components which have been added to the composition
- Floating Components
- An alternative variation of a Component is the FloatingComponent
- Floating components are NOT components. They can not be the root of a component tree, they are never the parent to a component nor a child of a component
- Floating components are usually temporary and *float* on top of all other components in the component tree
- Examples are drop-down menus, tooltips, context menus, etc
- Floating components are still registered at a component tree and are also updated / rendered by their tree just like regular components
What do you guys think about this? Would this work out this way or should I structure it differently?
Thank you very much and sorry for that big wall of text.