Personal tools


From HaskellWiki

(Difference between revisions)
Jump to: navigation, search
m (Using AutoForms in cooperation with WxHaskell)
m (Using the AutoForms monad (WxM))

Revision as of 21:35, 22 December 2007


1 Abstract

AutoForms is a library to ease the creation of Graphical User Interfaces (GUI). It does this by using generic programming to construct GUI components.

The AutoForms user creates an ordinary algebraic data type (ADT), which should reflect the data model of an application. From this ADT AutoForms automatically constructs a GUI component, by using the structure and identifiers of the ADT. To facilitate this construction, AutoForms uses the "Scrap your boilerplate" approach to generic programming.

This component can be displayed using WxHaskell or by an AutoForms custom monad called WxM.. The first facilitates that people who already knows WxHaskell quickly will be able to make GUIs. The second is our attempt at a more type-safe and easier to use GUI toolkit.

2 Installation

Download AutoForms release 0.3 (AForms.tgz) and follow the instructions in README.txt.

You can also try the bleeding edge version by doing:

svn export

3 Documentation

The three best sources of documentation is the

4 Using AutoForms in cooperation with WxHaskell

The best way to illustrate AutoForms is with some examples.

First, we create a widget consisting of a Double, an Int, and a String. This widget is displayed in a window and the values can be manipulated.

module AFWxExample where
import Graphics.UI.WX
import Graphics.UI.AF.AFWx
main :: IO ()
main = start $
     do w <- frame [text := "AFWx example"]
        p <- panel w []
        wid <- makeWidget (0.96::Double, 123::Int, "asdf") p []
        setWidButton <- button p [ text := "Set widget"
                                 , on command := set wid [ value := (0.32, 456, "New Value") ]
        set w [ layout := container p $ fill $ column 10
                           [ widget wid, widget setWidButton ]

The function makeWidget creates a WxHaskell widget and should be the only thing unrecognisable to an ordinary WxHaskell programmer.

We can also create widgets for custom ADT-s. We will show this be creating a settings dialog for a text editor:

{-# LANGUAGE FlexibleContexts, FlexibleInstances
  , MultiParamTypeClasses, TemplateHaskell, UndecidableInstances #-}
module SettingsForm where
import Graphics.UI.AF.AFWx
import Graphics.UI.WX
data Settings = Settings { lineWrap        :: Bool, splitWords      :: Bool
                         , autoSave        :: Bool, tabulatorStops  :: [Int]
                         , spacesInSteadOfTabulators :: Bool }     deriving (Show, Eq)
$(derive [''Settings])
defaultValues :: Settings
defaultValues = Settings True False False ([4,8,12] ++ [16,20..120]) False
main = start $
      do w <- frame [ text := "Text Editor Settings Forms" ]
         p <- panel w []
         wid <- makeWidget defaultValues p []
         set p [ layout := widget wid ]

Compared to the previous example there is a few new things. First of all we need to set some compiler options, as shown at the top. Secondly, we need to use the template-Haskell function to derive an instance for the Settings-type. Thirdly, we also need to declare that the Settings-type is an instance of ECCreator.

5 Using the AutoForms monad (WxM)

The best way to get familiar with the AutoForms monad (WxM) interface to AutoForms is via this tutorial.

6 Current state and plans

To understand the current state it will be advantageous to know the history of AutoForms. In the beginning this library was inspired by functional forms. E.g. it was an solely an attempt to ease the construction of simple forms (like a preference dialog). Shortly after starting the project, the author discovered that a very similar approach to GUI construction had existed for some time. Namely the clean GEC library. The Clean GEC library do not only try to create forms, but tries to be useable for any kind of GUI. This inspired the author to widen AutoForms scope, by creating functionality for buttons, menus, timers, and more. We encapsulated this functionality in our own monad (WxM). The extra functionality unfortunately delayed the core of AutoForms, namely the automatic transformation of an ADT to a GUI.

The larger set of functionality has proven less than perfect, as it is not as flexible as was initially hoped for. Thus, we need to make a change of direction. We will do this by either changing the more dynamic aspects of AutoForms (menus, buttons, ...) and/or by dropping the dynamic aspects of AutoForms and gambling on closer integration with existing libraries - like WxHaskell. The last option will also have the advantage of limiting AutoForms scope, and thus speed up development.

Many people are and has been working on making functional (as opposed to imperative) Haskell GUI toolkits. This could make Haskell a more productive language for constructing GUI-s. Thus we also consider to integrate AutoForms with one of these toolkits.

7 Users of AutoForms

  • Kamiariduki - A system to judge your derivative work's purpose and license is valid with Ceative Commons License Works.

8 Links

9 Author of AutoForms

The author of this library is Mads Lindstrøm. Feel free to contact me with questions, ideas, or comments.