| Widget | R Documentation |
Every element of a termr interface is a Widget. Widgets form a tree:
each widget has one parent and an ordered list of children. Most users
create widgets with constructor functions such as label() or
vertical(), and define new widget types with widget(). Subclassing
Widget with R6::R6Class() is also supported for advanced use.
A subclass usually overrides some of:
default_style(): the built-in style() of the widget type;
render(): returns the content as a string, a character vector of
lines or span()s;
on_key(event): handle a key press (return TRUE when handled);
paint(buffer, area, st): full control over drawing.
Widget state lives in reactive fields: assigning a new value invalidates the widget and schedules a repaint. Several assignments in one event loop tick produce a single repaint.
idUnique identifier used by #id selectors, or NULL.
classesCharacter vector of classes used by .class selectors.
helpOptional help text (Markdown) shown on the help screen (F1) while this widget or a descendant has focus.
paint_statesNames of state fields whose changes only need a
repaint (see invalidate_paint()); used by set_state().
focusableCan the widget receive keyboard focus?
regionBorder box assigned by the layout engine (region()).
parentThe parent widget (read-only).
childrenList of child widgets (read-only).
appThe App this widget belongs to, or NULL.
typeWidget type name used by type selectors.
visibleIs the widget shown? Hidden widgets take no space.
disabledDisabled widgets cannot be focused or used.
styleThe widget's own style() (layered over its defaults).
border_titleText shown in the top border (reactive), or NULL.
hoveredIs the mouse pointer over this widget (or a descendant)?
focusedDoes the widget currently have keyboard focus?
Widget$new()Create a widget.
Widget$new( ..., id = NULL, classes = NULL, style = NULL, disabled = FALSE, visible = TRUE )
...Child widgets.
idOptional identifier.
classesCharacter vector (or space separated string) of classes.
styleA style().
disabledIs the widget disabled?
visibleIs the widget visible?
Widget$default_style()The built-in style of this widget type.
Widget$default_style()
Widget$render()Content of the widget (string, lines or spans). Containers
return NULL.
Widget$render()
Widget$mount()Add child widgets, at the end or at a position. A widget that already has a parent is moved. Ids must be unique within a screen.
Widget$mount(..., before = NULL, after = NULL)
...Widgets or lists of widgets.
before, afterA child widget (or its index) to insert before / after.
Widget$replace()Remove all children and mount new ones.
Widget$replace(...)
...Widgets.
Widget$clear()Remove all children (containers). Some widgets redefine
clear() for their content (e.g. input(), log_view()).
Widget$clear()
Widget$remove()Detach this widget (and its children) from its parent.
Widget$remove()
Widget$remove_children()Remove all children.
Widget$remove_children()
Widget$walk()This widget followed by all descendants (depth first).
Widget$walk()
Widget$ancestors()Parent, grandparent, ... up to the root.
Widget$ancestors()
Widget$query()Find descendants matching a CSS-like selector.
Widget$query(selector)
selectorE.g. "Button", "#name", ".danger",
"Vertical > Button.primary", or several separated by commas.
A list of widgets.
Widget$query_one()The first descendant matching selector.
Widget$query_one(selector)
selectorA selector, see query().
Widget$matches()Does this widget match selector?
Widget$matches(selector)
selectorA selector, see query().
Widget$on()Handle events of a type that reach this widget (its own events and events bubbling up from descendants).
Widget$on(type, handler, selector = NULL)
typeEvent type, or "*" for all.
handlerfunction(event, app).
selectorOptional selector matched against the event sender.
The order of on() / app$on(), widget$on(type, selector, handler), is accepted too.
Widget$bind()Add a key binding to this widget, see bind().
Widget$bind(key, action = NULL, description = NULL)
keyKey name or a bind() binding.
actionAction name or function.
descriptionOptional description.
Widget$default_bindings()Built-in bindings of this widget type.
Widget$default_bindings()
Widget$bindings()All bindings of this widget (type bindings first, so instance bindings win).
Widget$bindings()
Widget$bind_reactive()Keep a field in sync with a reactive function: fn runs
now and again whenever the signal()s it reads change, and its
result is assigned to field (e.g. "text" for a label). The
binding ends when the widget is removed.
Widget$bind_reactive(field, fn)
fieldName of a widget field (an active binding such as text).
fnA function of no arguments.
Widget$capture_mouse()Receive all mouse events (also outside this widget's
region) until release_mouse() or the button is released.
Widget$capture_mouse()
Widget$release_mouse()Stop capturing the mouse.
Widget$release_mouse()
Widget$run_action()Run an action, looked up on this widget, its ancestors, then the app.
Widget$run_action(action)
actionAction name or function.
Widget$post_message()Send a message that bubbles up from this widget to the
app. Handlers receive a MessageEvent whose sender is this widget.
Widget$post_message(type, data = list(), bubbles = TRUE)
typeMessage name, e.g. "counter.changed".
dataA list of values.
bubblesShould the message bubble to ancestors?
The event (invisibly), or NULL when not attached to an app.
Widget$set_timeout()Call callback(self, app) once after delay seconds.
The timer is cancelled automatically when the widget is removed.
Widget$set_timeout(delay, callback)
delaySeconds.
callbackFunction.
A Timer.
Widget$set_interval()Call callback(self, app) every interval seconds
while the widget is mounted.
Widget$set_interval(interval, callback)
intervalSeconds.
callbackFunction.
A Timer.
Widget$animate()Animate a numeric field of this widget. See animate().
Widget$animate(property, to, ...)
propertyField name.
toTarget value.
...Other arguments of animate().
Widget$run_worker()Run a background worker owned by this widget (cancelled
when the widget is removed). See run_worker().
Widget$run_worker(fn, ...)
fnFunction to run.
...Other arguments of run_worker().
Widget$run_process()Run an external program owned by this widget. See
run_process().
Widget$run_process(command, ...)
commandProgram to run.
...Other arguments of run_process().
Widget$focus()Give keyboard focus to this widget.
Widget$focus()
Widget$blur()Remove keyboard focus from this widget.
Widget$blur()
Widget$add_class()Add classes.
Widget$add_class(...)
...Class names.
Widget$remove_class()Remove classes.
Widget$remove_class(...)
...Class names.
Widget$toggle_class()Add a class if absent, remove it if present.
Widget$toggle_class(name)
nameClass name.
Widget$has_class()Does the widget have this class?
Widget$has_class(name)
nameClass name.
Widget$set()Assign one or more fields, e.g.
app$query_one("#name")$set(value = ""). R does not allow
app$query_one("#name")$value <- "", so use this method when the
widget comes from a function call.
Widget$set(...)
...Named values.
The widget, invisibly (so calls can be chained).
Widget$get_state()Read a state field.
Widget$get_state(name)
nameField name.
Widget$set_state()Write a state field; invalidates the widget when the value changes.
Widget$set_state(name, value)
nameField name.
valueNew value.
Widget$layout_differs()Would the widget's size-related style differ if it were
in the pseudo states with rather than without? Used to decide
whether a focus / hover change needs a layout pass.
Widget$layout_differs(with, without)
with, withoutCharacter vectors of states.
Widget$invalidate()Mark the widget as needing a re-render and schedule a repaint, including a new layout pass (its size may have changed). Repaints are batched per event-loop tick.
Widget$invalidate()
Widget$invalidate_paint()Like invalidate() for changes that cannot affect the
size or position of anything (a cursor moved, a colour changed): the
widget is repainted but the layout is not recomputed.
Widget$invalidate_paint()
Widget$refresh()Force the widget to re-render on the next repaint.
Widget$refresh()
Widget$render_lines()Rendered content as lines of styled segments (cached until the widget is invalidated).
Widget$render_lines(width = NA_integer_)
widthAvailable content width (may be NA while measuring).
Widget$content_width()Natural width of the content area.
Widget$content_width()
Widget$content_height()Natural height of the content area for a given width.
Widget$content_height(width)
widthContent width.
Widget$arrange_children()Place the visible children inside the content box. Containers with special behaviour (scrolling, ...) override this.
Widget$arrange_children(children, inner, st)
childrenVisible child widgets.
innerContent rectangle of this widget.
stComputed style of this widget.
A list with one rectangle per child.
Widget$child_clip()The rectangle children are clipped to when painting.
Widget$child_clip(st)
stComputed style of this widget.
Widget$pseudo_states()Names of active states used to select state styles.
Widget$pseudo_states()
Widget$computed_style()The fully resolved style of the widget.
Widget$computed_style(inherited = NULL)
inheritedThe parent's computed style (computed if NULL).
Widget$layout_descend()Which children need their own layout? Containers that clip their children (scroll views) skip the ones that are entirely out of view; they get their region but not their descendants.
Widget$layout_descend(rects)
rectsThe rectangles arrange_children() returned.
Widget$paint()Paint the widget (not its children) into a buffer.
Widget$paint(buffer, area, st)
bufferA ScreenBuffer.
areaThe visible part of self$region.
stThe computed style.
Widget$is_enabled()Is the widget and every ancestor enabled?
Widget$is_enabled()
Widget$is_displayed()Is the widget and every ancestor visible?
Widget$is_displayed()
Widget$format()A one-line description used by print().
Widget$format(...)
...Ignored.
Widget$print()Print the widget tree.
Widget$print(...)
...Ignored.
Widget$clone()The objects of this class are cloneable with this method.
Widget$clone(deep = FALSE)
deepWhether to make a deep clone.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.