Home > wxHaskell > Custom Controls in wxHaskell (part 1)

Custom Controls in wxHaskell (part 1)

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.

DiffCtrl screenshot

DiffCtrl lScreenshot

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 .
About these ads
Categories: wxHaskell Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: