Difference between revisions of "LGtk"

From HaskellWiki
Jump to navigation Jump to search
(add links)
(restructure; begin to write semantics overview)
Line 9: Line 9:
 
LGtk has a lens-based API which fits better these user interfaces.
 
LGtk has a lens-based API which fits better these user interfaces.
   
== Demo application ==
+
== Semantics overview ==
   
  +
The semantics of LGtk is given by a reference implementation.
You can try the demo application with the following commands:
 
  +
The reference implementation is given by the following stages.
   
  +
=== Lenses ===
cabal install gtk2hs-buildtools
 
cabal install lgtk
 
lgtkdemo
 
   
  +
LGtk use simple lenses, defined in the data-lens package:
== Features ==
 
   
  +
<haskell>
Features of lgtk-0.5
 
  +
newtype Lens a b = Lens { runLens :: a -> Store b a }
  +
</haskell>
  +
  +
This data type is isomorphic to <hask>(a -> b, b -> a -> a)</hask>, the
  +
well-know lens data type.
  +
  +
In certain places LGtk allows to use non-pure lenses, i.e. lenses which
  +
brake lens laws. Those places are explicitly marked.
  +
  +
  +
=== References ===
  +
  +
A reference <hask>Ref a</hask> is isomorphic to <hask>Lens s a</hask> for some fixed state <hask>s</hask>.
  +
  +
TODO
   
* The API is closed, you can safely use any constructs as far as you obey the documented laws.
 
* Support for asynchronous events. Using LGtk is a safe way for writing multithreaded Gtk applications.
 
   
 
== Examples ==
 
== Examples ==
Line 77: Line 89:
 
== Status ==
 
== Status ==
   
 
Features of lgtk-0.5
LGtk is actively developed. The semantics is getting stable but it is not yet documented.
 
  +
 
* The API is closed, you can safely use any constructs as far as you obey the documented laws.
 
* Support for asynchronous events. Using LGtk is a safe way for writing multithreaded Gtk applications.
 
* The semantics is getting stable but it is not yet documented.
   
 
TODO list:
 
TODO list:
Line 85: Line 101:
 
* Support more Gtk constructs.
 
* Support more Gtk constructs.
   
  +
  +
== Demo application ==
  +
 
You can try the demo application with the following commands:
  +
 
cabal install gtk2hs-buildtools
 
cabal install lgtk
 
lgtkdemo
   
 
== Changelog ==
 
== Changelog ==

Revision as of 06:37, 2 June 2013

What is it?

LGtk is a lens-based API for Gtk. LGtk is built on Gtk2Hs.

Most Haskellers would like to use a mature FRP-based API for creating graphical user interfaces. FRP may not be the best tool for special user interfaces, like interfaces which consists of buttons, checkboxes, combo boxes, text entries and menus only. LGtk has a lens-based API which fits better these user interfaces.

Semantics overview

The semantics of LGtk is given by a reference implementation. The reference implementation is given by the following stages.

Lenses

LGtk use simple lenses, defined in the data-lens package:

newtype Lens a b = Lens { runLens :: a -> Store b a }

This data type is isomorphic to (a -> b, b -> a -> a), the well-know lens data type.

In certain places LGtk allows to use non-pure lenses, i.e. lenses which brake lens laws. Those places are explicitly marked.


References

A reference Ref a is isomorphic to Lens s a for some fixed state s.

TODO


Examples

Hello World

main = runWidget $ label $ return "Hello World!"

return is neded because labels may be dynamic, see the next examples.

Copy

The following applications presents an entry and a label below of it. When a text is entered in the entry, the label is changed to the entered text.

main = runWidget $ action $ do
   r <- newRef "enter text here"
   return $ vcat
       [ entry r
       , label $ readRef r
       ]

action gives acces to a monad in which new references can be made by newRef. A crutial feature of LGtk is that you cannot change the value of references in this monad (you can read them though).

label gives acces to a monad in which you can read references but no reference creation or write is possible.

Addition

Two entries of integers and a label which shows the sum:

main = runWidget $ action $ do
   r1 <- newRef (12 :: Integer)
   r2 <- newRef 4
   return $ vcat
       [ entryShow r1
       , entryShow r2
       , label $ liftM show $ liftM2 (+) (readRef r1) (readRef r2)
       ]

Complex examples

You can find more complex examples in the source code of LGtk. More examples will be presented here also.

Lgtkdemo.png

Status

Features of lgtk-0.5

  • The API is closed, you can safely use any constructs as far as you obey the documented laws.
  • Support for asynchronous events. Using LGtk is a safe way for writing multithreaded Gtk applications.
  • The semantics is getting stable but it is not yet documented.

TODO list:

  • Add an efficient implementation for LGtk. LGtk has only a reference implementation currently.
  • Add support for styles (layout, colors, etc).
  • Support more Gtk constructs.


Demo application

You can try the demo application with the following commands:

cabal install gtk2hs-buildtools
cabal install lgtk
lgtkdemo

Changelog

lgtk-0.5.1

  • Documentation fixes and cleanup
  • Try to support Haskell Platform 2012.4.0.0

lgtk-0.5

  • Do not use monadic lenses any more.
  • Support for asynchronous events.
  • Lazily created tabs.
  • Unactive tabs are really unactive (event handlers are detached).
  • File references watch the files. When the file changes, the GUI is updated.
  • References with inherent identity (makes defining auto-sensitive buttons easier)
  • Experimental support for colored buttons.
  • More examples in the demo application.
  • Lots of inner changes.

External links

Related Stackoverflow questions:

Reddit comments: