Library
Module
Module type
Parameter
Class
Class type
Creating and using widgets
Connections
A connection has a source widget and a target widget. When the source widget receives a specified event, the connection is activated, executing a specified function.
type action = t -> t -> Tsdl.Sdl.event -> unit
val connect :
t ->
t ->
action ->
?priority:action_priority ->
?update_target:bool ->
?join:connection ->
Trigger.t list ->
connection
connect source target action triggers
creates a connection from the source
widget to the target
widget, but does not register it (this may change in the future...). Once it is registered (either by Main.make
or add_connection
), and has focus, then when an event ev
matches one of the triggers
list, the action
is executed with arguments source target ev
.
val connect_main :
t ->
t ->
action ->
?update_target:bool ->
?join:connection ->
Trigger.t list ->
connection
Alias to connect ~priority:Main
. Should be used for very fast actions that can be run in the main thread.
val add_connection : t -> connection -> unit
val update : t -> unit
Ask for refresh at next frame. Use this in general in the action of a connection in case the action modifies the visual state of the widget, which then needs to be re-drawn.
on_release ~release:f w
registers on the widget w
the action f
, which will be executed when the mouse button is released on this widget. Uses priority=Main
val box :
?w:int ->
?h:int ->
?background:Style.background ->
?border:Style.border ->
?shadow:Style.shadow ->
unit ->
t
The standard on/off check boxes.
val check_box : ?state:bool -> ?style:Check.style -> unit -> t
val set_check_state : t -> bool -> unit
Use this for multi-line text.
val text_display : ?w:int -> ?h:int -> string -> t
val rich_text : ?size:int -> ?w:int -> ?h:int -> Text_display.words list -> t
val verbatim : string -> t
One-line text.
val label : ?size:int -> ?fg:Draw.color -> ?font:Label.font -> string -> t
val icon : ?size:int -> ?fg:Draw.color -> string -> t
fontawesome icon
Does not display anything but still gets focus and reacts to events.
val empty : w:int -> h:int -> unit -> t
val get_state : t -> bool
query a boolean state. Works for Button.t and Check.t
val get_text : t -> string
Return the text of the widget. Works for Button.t, TextDisplay.t, Label.t, and TextInput.t
val set_text : t -> string -> unit
Change the text of a widget. Works for Button.t, TextDisplay.t, Label.t, and TextInput.t
val image : ?w:int -> ?h:int -> ?bg:Draw.color -> ?noscale:bool -> string -> t
Load image file.
val image_from_svg : ?w:int -> ?h:int -> ?bg:Draw.color -> string -> t
Requires rsvg
.
val text_input :
?text:string ->
?prompt:string ->
?size:int ->
?filter:Text_input.filter ->
?max_size:int ->
unit ->
t
val button :
?kind:Button.kind ->
?label:Label.t ->
?label_on:Label.t ->
?label_off:Label.t ->
?fg:Draw.color ->
?bg_on:Style.background ->
?bg_off:Style.background ->
?bg_over:Style.background ->
?state:bool ->
?border_radius:int ->
?border_color:Draw.color ->
string ->
t
val slider :
?priority:action_priority ->
?step:int ->
?value:int ->
?kind:Slider.kind ->
?var:(int Avar.t, int) Tvar.t ->
?length:int ->
?thickness:int ->
?tick_size:int ->
?lock:bool ->
int ->
t
val slider_with_action :
?priority:action_priority ->
?step:int ->
?kind:Slider.kind ->
value:int ->
?length:int ->
?thickness:int ->
?tick_size:int ->
action:(int -> unit) ->
int ->
t
Create a slider that executes an action each time the local value of the slider is modified by the user.
let b,l = check_box_with_label text
creates a check box b
, a label l
, and connect them so that clicking on the text will also act on the check box.
Conversions from the generic Widget type to the specialized inner type
val get_text_display : t -> Text_display.t
val get_text_input : t -> Text_input.t