Overview
TheWidget class is the abstract base for all UI components in Kraken TUI. It provides:
- Layout methods: Width, height, padding, margin, gap
- Style methods: Colors, text decorations, borders, opacity
- Tree methods: Append, insert, remove children, destroy
- Animation methods: Property animations, built-in effects (spinner, pulse, progress)
- Focus methods: Make focusable, request focus
- Accessibility methods: Roles, labels, descriptions
Widget is abstract. Instantiate concrete types like Box, Text, Input, Select, ScrollBox, or TextArea.Properties
Opaque native handle for FFI calls. Do not modify.
Tree Management
append()
Append a child widget to this widget’s children.Widget to append.
insertChild()
Insert a child widget at a specific index. If index >= childCount, the child is appended.Widget to insert.
Zero-based index. If >= childCount, appends.
removeChild()
Remove a child widget from this widget’s children. Does not destroy the child.Widget to remove.
childCount()
Get the number of children.Number of direct children.
destroy()
Destroy this widget. Does not destroy children automatically.destroySubtree()
Destroy this widget and all descendants in one native call. More efficient than recursive destroy.Visibility
setVisible()
Set widget visibility. Invisible widgets are not rendered and do not participate in layout.Whether the widget is visible.
isVisible()
Check if the widget is visible.true if visible, false otherwise.markDirty()
Mark this widget as dirty, forcing a re-render on the next frame.Layout Properties
setWidth()
Set the widget width.Width value:
number: Fixed width in columns"<number>%": Percentage of parent"auto": Auto-size to content
setHeight()
Set the widget height.Height value:
number: Fixed height in rows"<number>%": Percentage of parent"auto": Auto-size to content
setPadding()
Set inner spacing (padding) on all four sides.Top padding in rows.
Right padding in columns.
Bottom padding in rows.
Left padding in columns.
setMargin()
Set outer spacing (margin) on all four sides.Top margin in rows.
Right margin in columns.
Bottom margin in rows.
Left margin in columns.
setGap()
Set spacing between children in flex layouts.Gap between rows in rows.
Gap between columns in columns.
Style Properties
setForeground()
Set text color (foreground).Color value:
"#RRGGBB": Hex RGB (24-bit true color)"red","blue", etc.: Named colornumber: 256-color palette index (0-255)
setBackground()
Set background color.Color value (same format as
setForeground).setBold()
Enable or disable bold text.Whether to enable bold.
setItalic()
Enable or disable italic text.Whether to enable italic.
setUnderline()
Enable or disable underline text decoration.Whether to enable underline.
setBorderStyle()
Set the border style.Border style:
"none": No border"single": Single-line box drawing"double": Double-line box drawing"rounded": Rounded corners"bold": Bold/thick lines
setOpacity()
Set widget opacity.Opacity value from 0.0 (fully transparent) to 1.0 (fully opaque).
Animation
animate()
Animate a style property over time.Property to animate:
"opacity": Widget opacity (0.0–1.0)"fgColor": Foreground color"bgColor": Background color"borderColor": Border color"positionX": Horizontal offset"positionY": Vertical offset
Target value:
- For opacity/position:
number - For colors:
string(hex/named) ornumber(palette index)
Animation duration in milliseconds.
Easing function:
"linear": Constant speed"easeIn": Slow start"easeOut": Slow end"easeInOut": Slow start and end"cubicIn": Cubic ease-in"cubicOut": Cubic ease-out"elastic": Spring-like overshoot"bounce": Bouncing effect
If true, animation reverses and repeats indefinitely (oscillates).
Animation handle for cancellation or chaining.
cancelAnimation()
Cancel an active animation. The property retains its current value.Animation handle returned by
animate().spinner()
Start a built-in spinner animation (cycles through braille frames).Frame interval in milliseconds.
Animation handle for cancellation.
progress()
Start a built-in progress animation (opacity 0→1 over the given duration).Animation duration in milliseconds.
Easing function (same as
animate).Animation handle for cancellation.
pulse()
Start a built-in pulse animation (opacity oscillates indefinitely).Duration of one oscillation cycle in milliseconds.
Easing function (same as
animate).Animation handle for cancellation.
Focus
setFocusable()
Make this widget focusable or non-focusable.Whether the widget can receive focus.
focus()
Request focus for this widget.The widget must be focusable (
setFocusable(true)).Accessibility
setRole()
Set the accessibility role for this widget.Accessibility role constant from
AccessibilityRole enum.setLabel()
Set the accessibility label (short description for screen readers).Label text.
setDescription()
Set the accessibility description (detailed description for screen readers).Description text.