Widgets for creating applications
Whether the widget can receive the focus or not.
Enqueue a redraw operation. If the widget has a parent, this is the same as calling the queue_draw method of the parent, otherwise this does nothing.
set_queue_draw f
sets the function called when the
queue_draw method is invoked, for this widget and all its
children.
draw ctx focused
draws the widget on the given
context. focused
is the focused widget.
Method invoked when the widget has the focus, it returns the position of the cursor inside the widget if it should be displayed.
Send an event to the widget. If the widget cannot process the event, it is sent to the parent and so on.
on_event ?switch f
calls f
each time an event is
received. If f
returns true
, the event is not passed to
other callbacks.
Sets the resources of the widget and of all its children.
The resource class of the widget.
Sets the resource class of the widget. This can be used to set an alternative style for the widget.
Method invoked when the resources or the resource class of the widget change. The default function does nothing.
The base class. The parameter is the initial resource class. The resource class is the first part of all resource keys used by the widget.
For examples, buttons use the resources
"button.focused.foreground"
, "button.unfocused.bold"
, ... so
their resource class is "button"
.
add ?position ?expand widget
adds a widget to the box. If
expand
is true
(the default) then widget
will occupy as
much space as possible. If position
is not specified then
the widget is appended to the end of the widget list. It
raises Out_of_range if the given position is negative or
exceed the number of widgets.
Type of widgets displaying a list of widget.
The text displayed on the checkbutton.
The state of checkbutton; true
means checked and false
means unchecked.
on_click ?switch f
calls f
when the button state is changed.
Checkbutton. A button that can be in active or inactive state.
on_state_change ?switch f
calls f
when the state of the group is changed.
The state of the group. Contains Some id
with the id of "on" object
in the group or None if no objects were added to the group yet.
Radio group.
Radio group governs the set of radio objects. At each given moment of time only one of the objects in the "on" state and the rest are in the "off" state.
The state of the button; true
if button is "on" and false
if the button
is "off".
Switches the button state to "on". Affects only how the button is drawn, does not change the state of the group the button is added to. Use radiogroup.switch_to instead.
Switches the button state to "off". Affects only how the button is drawn, does not change the state of the group the button is added to. Use radiogroup.switch_to instead.
The text displayed on the radiobutton.
The id of the button.
on_click ?switch f
calls f
when the button is clicked. You probably want
to use radiogroup.on_state_change instead.
Radiobutton. The button which implements radio object contract, so can be added to radiogroup.
run term ?save_state widget w
runs on the given terminal using
widget
as main widget. It returns when w
terminates. If
save_state
is true
(the default) then the state of the
terminal is saved and restored when w
terminates.
If load_resources
is true
(the default) then
resources_file
(which default to ".lambda-termrc" in the home
directory) is loaded and the result is set to w
.
This function works in the same way as run but also takes two Lwt_react.event parameters. The first one should contain LTerm_widget.t widget and makes it new topmost layer in UI. The second message removes the topmost level from UI. All layers are redrawn, from bottom to up, but only the topmost layer gets keyboard events delivered to it. This allows to implement things like modal dialogs.
prepare_simple_run ()
returns a tuple (do_run, push_layer, pop_layer,
exit)
-- functions useful for creating simple UI.
do_run w
where w is a widget runs the given widget in a terminal over
stdout, loading resources from .lambda-termrc
, saving state and
restoring it on exit from ui.
Example: do_run my_frame
push_layer w
where w is a widget is a callback to add w as a new modal
layer to UI.
Example: button#on_click (push_layer my_modal_dialog)
.
pop_layer
is a callback to destroy the topmost modal layer.
Example: cancel_button#on_click pop_layer
.
exit
is a callback to exit the UI.
Example: exit_button#on_click exit