lgtk-0.6: lens-based API for Gtk

Safe HaskellNone

LGtk.ADTEditor

Description

A generic ADT editor defined on top of the main LGtk interface, LGtk.

Synopsis

Documentation

newtype Lens_ a b Source

Constructors

Lens_ 

Fields

unLens_ :: Lens' a b
 

data List a Source

Type-level lists

Constructors

Nil 
Cons a (List a) 

data Elems xs whereSource

Heterogeneous lists

Constructors

ElemsNil :: Elems Nil 
ElemsCons :: ADTLens a => a -> Elems as -> Elems (Cons a as) 

class ADTLens a whereSource

Lens for editable ADTs with support of shared record fields between constructors.

Suppose we have the data type

data X
    = X1 { a :: Int, b :: Bool }
    | X2 { a :: Int, c :: Char }

We can build an editor which can switch between two editor for the constructors. If the field a is edited in one editor, it will be updated in the other.

Associated Types

type ADTEls a :: List *Source

ADTEls a is the list of types of the parts of the ADT.

For example,

ADTEls X = Cons Int (Cons Bool (Cons Char Nil))

Methods

adtLens :: ([(String, [Int])], Elems (ADTEls a), Lens_ (Int, Elems (ADTEls a)) a)Source

The lens which defines an abstract editor.

The first parameter defines the displayed constructor name and the parts of the constructor for each constructor. Int is an index in the ADTEls list.

For example, in case of X,

fst3 adtLens = [("X1", [0, 1]), ("X2", [0, 2])]

The second parameter is the list of default values for each part.

The third parameter is a lens from the selected constructor index plus the values of the ADT parts to the ADT values.

Instances

ADTLens T

ADTLens instance for T

adtEditor :: (EffRef m, ADTLens a) => Ref m a -> m (Widget m)Source

A generic ADT editor