Module Widget

module Widget: sig .. end
A library of widgets for building GUIs.

type widget = {
   repaint : Gctx.gctx -> unit;
   handle : Gctx.gctx -> Gctx.event -> unit;
   size : unit -> Gctx.dimension;
}
A widget is an object that provides three services:

Layout Widgets



Layout widgets are containers for other widgets They route events to the appropriate child widget, translating the events to the child's local coordinate system
val space : Gctx.dimension -> widget
A widget that does nothing but take up space
val border : widget -> widget
Adds a border around another widget
val hpair : widget -> widget -> widget
A pair of horizontally adjacent widgets
val vpair : widget -> widget -> widget
A pair of vertically adjacent widgets
val vlist : widget list -> widget
A vertical group of widgets
val hlist : widget list -> widget
A horizontal group of widgets

Label Widgets


type label_controller = {
   get_label : unit -> string;
   set_label : string -> unit;
}
A record of functions that allows us to read and write the string associated with a label.
val label : string -> widget * label_controller
Construct a label widget and its controller.

Event Listeners


type event_listener = Gctx.gctx -> Gctx.event -> unit 
An event listener processes events as they "flow" through the widget hierarchy.
val mouseclick_listener : (unit -> unit) -> event_listener
Performs an action upon receiving a mouse click.

Notifier



A notifier widget is a widget "wrapper" that doesn't take up any extra screen space -- it extends an existing widget with the ability to react to events. It maintains a list of of "listeners" that eavesdrop on the events propagated through the notifier widget.

When an event comes in to the notifier, it is passed to each event_listener in turn, and then pass to the child widget.

type notifier_controller = {
   add_event_listener : event_listener -> unit;
}
A notifier_controller is associated with a notifier widget. It allows the program to add event listeners to the notifier.
val notifier : widget -> widget * notifier_controller
Construct a notifier widget and its controller

Button


val button : string ->
widget * label_controller * notifier_controller
A button has a string, which can be controlled by the corresponding label_controller, and an event listener, which can be controlled by the notifier_controller to add listeners (e.g. a mouseclick_listener) that will perform an action when the button is pressed.

Canvas



A widget that allows drawing to a graphics context
val canvas : Gctx.dimension ->
(Gctx.gctx -> unit) -> widget * notifier_controller
Canvases are just widgets with an associated notifier_controller. The repaint method of a canvas is a parameter of the widget constructor.

Checkbox


type 'a value_controller = {
   add_change_listener : ('a -> unit) -> unit;
   get_value : unit -> 'a;
   set_value : 'a -> unit;
}
A controller for a value associated with a widget.

This controller can read and write the value. It also allows change listeners to be registered by the application. These listeners are run whenever this value is set.

val checkbox : bool -> string -> widget * bool value_controller
A checkbox widget.