package stk

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Stk.WidgetSource

Widget base class.

Global keys

Keys to make focus circulate between widgets:

Sourceval focus_next_keys : Key.keystate ref

Keys to move focus to next widget.

Sourceval focus_prev_keys : Key.keystate ref

Keys to move focus to previous widget.

Widget tree

This representation of widget tree is used for debugging.

Sourcetype 'a tree =
  1. | N of 'a * 'a tree list
Sourceval pp_tree : (Format.formatter -> 'a -> unit) -> ?indent:string -> Format.formatter -> 'a tree -> unit

Events

Sourcetype 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.

Sourcetype 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.

Sourcetype 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.

Sourcetype drop_ev = {
  1. text : string;
  2. x : int;
  3. y : int;
}

Drop (filename or text) event, with mouse coordinates.

Sourcetype 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.

    *)
  12. | File_dropped : (drop_ev -> bool) Events.ev
    (*

    A file is drag'n'dropped on widget

    *)
  13. | Text_dropped : (drop_ev -> bool) Events.ev
    (*

    Text is drag'n'dropped on widget

    *)

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 types

Sourcetype widget_type = ..

This extensible type is used to add constructor for each widget. The widget has a method typ returning an optional value of this type. When only values of class widget are available, this method can be used to retrieve the object corresponding to the widget type and use its specific methods.

Widget data

Sourcetype 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.

Expressing size constraints

Sourcetype size_constraints = {
  1. min : int;
  2. max_used : int option;
  3. max_abs : int option;
}
Sourceval size_constraints : ?max_used:int -> ?max_abs:int -> int -> size_constraints
Sourceval size_constraints_none : size_constraints
Sourceval size_constraints_fixed : int -> size_constraints
Sourceval pp_size_constraints : Format.formatter -> size_constraints -> unit
Sourceval add_to_size_constraints : size_constraints -> int -> size_constraints

Widget class

Sourceclass virtual widget : ?classes:string list option -> ?name:string option -> ?props:Props.t option -> ?wdata: wdata 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 Scrollbox.scrollbox):

  • classes specifies the classes of the widget. This is used to retrieve its default properties when theming. Some widgets have default classes, some have classes depending on property values (like Props.orientation.
  • name specifies the name of the widget. This is useful for debugging purposes and is also used in theming.
  • props specifies properties to use in addition to the default properties associated to kind, classes and name when theme is applied. 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

Sourceval pp_widget_tree : 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.

Sourceval pp : Format.formatter -> < me : string.. > -> unit

pp ppf w prints w#me to formater ppf.

Sourceval 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.

Sourceval widget_prop : ?after:widget Stk__Props.post_action list -> ?default:widget -> ?inherited:bool -> ?transition:(start:widget -> stop:widget -> float -> widget) -> string -> widget Stk__Props.prop

A function to create a property holding a widget.

Sourceclass virtual oriented : object ... end
Sourcemodule Set : sig ... end

Set of widgets.

Sourcemodule Map : sig ... end

Map with widgets as keys.

OCaml

Innovation. Community. Security.