package stk_xml

  1. Overview
  2. Docs

Module Stk_xml.LayoutSource

Creating widgets from XML tree.

Functions of this module should only be used by code handling specific XML nodes, through the function provided to the XML view with the View.xmlview.set_of_node method.

Sourcemodule WMap = Stk.Widget.Map
Sourcetype of_node = {
  1. ctx : ctx;
  2. widget : Stk.Widget.widget option;
  3. before : Stk.Widget.widget option;
  4. after : Stk.Widget.widget option;
  5. subs_handled : bool;
}

This structure is returned by functions called on a node.

Sourceand of_node_fun = ctx -> Xml.node -> of_node option

Type of a function called to handle a node. None as result means that the function did not handle this kind of node. In this case, the default function default_of_node will handle it.

Sourceand ctx = {
  1. of_node : of_node_fun;
  2. container : Stk.Widget.widget;
  3. css_rules : Iri.t Css.S.rule_ list;
  4. root_props : Css.C.t;
  5. props : Css.C.t;
  6. font_desc : Stk.Font.font_desc;
  7. path : Xml.node list list;
  8. nodes : Doc.node list;
  9. node_count : int;
  10. item_map : Doc.node WMap.t;
  11. id_map : Doc.node Stk.Smap.t;
  12. load_resource : Iri.t -> [ `Error of string | `None | `Ok of Ldp.Types.resource ] Lwt.t;
  13. iri : Iri.t option;
  14. base_iri : Iri.t option;
}

The context with the information needed to create nodes.

Sourceval of_node_none : ctx -> of_node

of_node_none ctx returns { ctx ; widget = None ; before = None ; after = None ; subs_handled = false }.

Sourceval pack : container:Stk.Widget.widget -> ?kind:Stk.Flex.item_kind -> Stk.Widget.widget -> unit

pack ~container widget will pack widget into container, depending on the widget type of container: by now widgets can only be packed into Stk.Flex.flex widgets. Trying to pack into a table will do nothing and an error message will be issued when trying to pack into another type of container.

The optional argument kind can be used to specify how to handle the packed widget. If no value is provided, the Stk.Flex.item_kind property is not set and its default value will be used.

Sourceval pack_break : Stk.Widget.widget -> ?props:Stk.Props.t -> unit -> Stk.Widget.widget option

pack_break container () packs a break into the container. As for pack, this functions should be called only with flex containers. Optional argument props can be used to specify properties for the Stk.Flex.break widget inserted.

Sourceval pack_space : Stk.Widget.widget -> ?props:Stk.Props.t -> unit -> Stk.Widget.widget option

Same as pack_break but inserts a Stk.Flex.space.

Sourceval build_text : ctx -> Xtmpl.Types.cdata -> Stk.Widget.widget option

build_text ctx cdata creates a label widget from the given cdata and inserts it into ctx.container. If cdata is "\n" (resp. " "), a break (resp. a space) is packed into the ctx.container and no widget is returned.

Sourceval build_image : ctx -> int option -> int option -> Stk.Props.t -> Stk.Image.image

build_image ctx width height props creates a Stk.Image.image widget from given width, height and props and packs it into ctx.container. The created image is returned.

Sourceval image : ctx -> ?xml:'a -> Iri.t -> Xml.node -> of_node

image ctx ?xml iri node creates and packs an image widget from the given node, using value of "src" node attribute as image IRI. Image IRI is resolved using iri as base. If no valid image IRI is found, no widget is created. Else an image is created, using width and height if present in node attributes. The image is loaded in a Lwt.async and the newly created widget is returned through the of_node structure.

Sourceval set_container_borders : Stk.Widget.widget -> Css.C.t -> unit

set_container_borders widget computed_css sets widget properties for border widths and colors according to computed_css.

Sourceval flex_of_props : ?name:string -> Css.C.t -> Stk.Flex.flex

flex_of_props computed_css creates a Stk.Flex.flex widget with properties from computed_css.

Sourceval table_of_props : ?name:string -> Css.C.t -> Stk.Table.table

table_of_props computed_css creates a Stk.Table.table widget with properties from computed_css.

Sourceval ctx_new_block : name:string -> ctx -> ctx

ctx_new_block ~name ctx creates a new block context from ctx. To do so, it creates a flex widget with name, which is set as container is the returned context.

Sourceval default_of_node : ctx -> Xml.node -> of_node

default_of_node ctx node is the default function creating widgets from XML node. When the View.xmlview has no of_node function or if it returns None for an XML node, this default_of_node function will be called to handle the XML node.

OCaml

Innovation. Community. Security.