package stk

  1. Overview
  2. Docs

Widget base class.

Global keys

Keys to make focus circulate between widgets:

val focus_next_keys : Key.keystate Stdlib.ref

Keys to move focus to next widget.

val focus_prev_keys : Key.keystate Stdlib.ref

Keys to move focus to previous widget.

Widget tree

This representation of widget tree is used for debugging.

type 'a tree =
  1. | N of 'a * 'a tree list
val pp_tree : (Stdlib.Format.formatter -> 'a -> unit) -> ?indent:string -> Stdlib.Format.formatter -> 'b tree -> unit

Events

type button_ev = {
  1. event : Tsdl.Sdl.event;
  2. button : int;
  3. x : int;
  4. y : int;
}

Button event (press, release, click) holding the original SDL event and fields with the button and coordinates of mouse cursor in event.

type mouse_motion_ev = {
  1. event : Tsdl.Sdl.event;
  2. x : int;
  3. y : int;
}

Mouse motion event holding the original SDL event and the coordinates of the mouse cursor in event.

type key_ev = {
  1. event : Tsdl.Sdl.event;
  2. key : Tsdl.Sdl.keycode;
  3. mods : Tsdl.Sdl.keymod;
}

Key event (press or release) with the origina SDL event, the concerned key and the activated modifiers.

type Events.ev +=
  1. | Clicked : (button_ev -> bool) Events.ev
    (*

    A click occured in widget (press and release button).

    *)
  2. | Activated : (unit -> unit) Events.ev
    (*

    The widget was activated, like a menu item or a button.

    *)
  3. | Button_pressed : (button_ev -> bool) Events.ev
    (*

    A button was pressed in widget.

    *)
  4. | Button_released : (button_ev -> bool) Events.ev
    (*

    A button was released in widget.

    *)
  5. | Key_pressed : (key_ev -> bool) Events.ev
    (*

    A key was pressed in a focused widget.

    *)
  6. | Key_released : (key_ev -> bool) Events.ev
    (*

    A key was released in a focused widget.

    *)
  7. | Mouse_enter : (unit -> bool) Events.ev
    (*

    Mouse cursor entered the widget.

    *)
  8. | Mouse_leave : (unit -> bool) Events.ev
    (*

    Mouse cursor leaved the widget.

    *)
  9. | Mouse_motion : (mouse_motion_ev -> bool) Events.ev
    (*

    Mouse moved over the widget.

    *)
  10. | Destroy : (unit -> bool) Events.ev
    (*

    Widget is being destroyed.

    *)
  11. | Geometry_changed : (unit -> unit) Events.ev
    (*

    Geometry of widget changed.

    *)

Events common to all widgets. Extend the Events.ev type so that callbacks can be registered to be called when a widget triggers an event.

Widget data

type wdata = ..

A widget can hold an optional value of the wdata extensible type. This is useful to store application specific data directly in some widgets rather than storing them in a map aside.

Widget class

class virtual widget : ?class_:string option -> ?name:string option -> ?props:Props.t option -> unit -> object ... end

The base widget class. It contains methods to be called by children widgets, event if the base class does not handle child widgets.

Widget arguments

All widget classes handle the following optional arguments, which are handled by the convenient functions provided to create widgets (like Bin.scrollbox):

  • class_ specifies the class name of the widget. This is used to retrieve its default properties. The default class_ of a widget is defined by its class. class_ for a widget class is usually set to the same name as the class; for example, Bin.scrollbox widgets have a default class_ set to "scrollbox".
  • name specifies the name of the widget. This is useful for debugging purposes and default properties can also be associated to names. Default name is equal to class_ value.
  • props specifies properties to use in addition to the default properties associated to class_ and name. Propertes props are merged with the default properties, with Props.merge. This is useful to override or add some properties at widget creation.

Convenient functions also handle a pack optional argument. It is a function called with the created widget coerced to widget type, and is usually used to pack or add the created widget to another one.

Utils

val pp_widget_tree : Stdlib.Format.formatter -> widget tree -> unit

pp_widget_tree ppf w pretty-prints widget w and its children to formatter ppf, with some properties. This is for debugging purpose.

val pp : Stdlib.Format.formatter -> < me : string.. > -> unit

pp ppf w prints w#me to formater ppf.

val may_pack : ?pack:(widget -> unit) -> < coerce : widget.. > -> unit

may_pack ?pack w will apply the pack function if provided, to widget w. This is used by convenient functions, usually to pack a creatd widget, hence the name.

val widget_prop : ?after:widget Stk__Props.post_action list -> ?default:widget -> ?inherits:bool -> string -> widget Stk__Props.prop

A function to create a property holding a widget.

module Set : sig ... end

Set of widgets.

module Map : sig ... end

Map with widgets as keys.