Edit: added a screenshot to show what we are working towards.
When I started working with wxHaskell, it quickly became obvious that a lot of time could be saved if I could produce reusable custom widgets in Haskell.
Looking into the samples which come with wxHaskell, there is one example of a custom control, but it is so simple as to be almost useless to someone hoping to develop something a little more ambitious.
Over the next few posts I will explain how I put custom controls together and try to point out a few of the pitfalls. I will do this by working through the development of a fairly simple custom control to display the output of running the diff command to compare two files.
This example is short enough to be manageable in a few posts, but contains enough functionality to explore some of the issues you may come up against.
Outline of a custom control
The control I am building is subclassed from Panel. This is probably a good choice for most controls as it can contain a top level sizer and many children.
- You need to create a suitable subclass for the main window of your control, deriving from Panel. wxHaskell uses witness types to provide a good degree of type safety in what is basically a thin wrapper over a C++ library.
- You need to create the widgets and their layout inside the main window.
- You need to create and manage any Attributes your control may require. This may include making your control an instance of some of the standard wxHaskell attribute classes.
- You need to handle any custom paint operations on the control.
- You may require custom event handlers .