package stk

  1. Overview
  2. Docs

A box is a Container.container which stacks its children, giving each one more or less space according to its size and properties. Widgets can be stacked horizontally or vertically (depending on the Props.orientation property).

Properties

method orientation : Stk.Props.orientation
method set_orientation : Stk.Props.orientation -> unit
method inter_padding : int
method set_inter_padding : int -> unit

Children

method widget_data : Stk.Widget.widget -> 'a option option

b#widget_data w returns Container.child.data data associated to the given child widget w, if w is a child of b and it has data associated.

method widget_index : Stk.Widget.widget -> int option

b#widget_index w returns 0-based index of w in b's children, if w is a child of b.

method children_widgets : Stk.Widget.widget list

o#children_widgets returns the list of children widget of o.

method reorder_child : Stk.Widget.widget -> int -> unit

o#reorder_child w pos moves child widget w to new position pos (if possible).

method pack : ?pos:int -> ?hexpand:int -> ?vexpand:int -> ?hfill:bool -> ?vfill:bool -> ?data:'a -> Stk.Widget.widget -> unit

o#pack w adds widget w to o. Optional parameters are:

  • pos indicates a position to insert w; default is to append w to children.
  • hexpand (resp. vexpand) sets Props.hexpand (resp. Props.vexpand) property of w to the given value.
  • hfill (resp. vfill) sets Props.hfill (resp. Props.vfill) property of w to the given value.
  • data associates the given value to w. All data associated to children must have the same type (this type is the type parameter of class box.

To allocate space for children widgets, the following algorithm is applied (here for horizontal packing; for vertical packing, replace width by height and hexpand by vexpand):

  1. The minimum widths of children are summed. This sum is deducted from the width allocated to o.
  2. The remaining space is then distributed among children, according to their hexpand value. 0 means that widget does not require more than its minimal width. A positive value p means that the widget requires p shares of the remaining space. The remaining space is divided by the total number of shares and each widget is given as width its minimal width + the width corresponding to its required shares. For example, if three widgets of same minimum size have hexpand values of 3, 2 and 1, the first widget will have half of the available width, the second will have one third and the last on sixth.
  3. When allocated width of each widget is computed, each widget is given this width (if value of hfill is true) of just its minimum width (if it is false).
method unpack : Stk.Widget.widget -> unit

o#unpack w removes child widget w from o.

method unpack_all : destroy:bool -> unit

o#unpack_all ~destroy removes all children from o. destroy indicates whether to call #destroy on children after removing.

OCaml

Innovation. Community. Security.