celina/widgets/base

Base widget system for Celina CLI library

This module defines the fundamental widget traits and base classes for building UI components.

Types

StatefulWidget[T] = ref object of Widget
  state*: T
Widget with internal state
Widget = ref object of RootObj
Base widget type - all widgets inherit from this

Procs

proc constrainSize(requested: Size; available: Size; minimum: Size): Size {.
    ...raises: [], tags: [], forbids: [].}
Constrain a size within bounds
proc getState[T](widget: StatefulWidget[T]): T
Get the current state of a stateful widget
proc measureWidget(widget: Widget; available: Size): Size {....raises: [Exception],
    tags: [RootEffect], forbids: [].}
Measure how much space a widget wants
proc newStatefulWidget[T](initialState: T): StatefulWidget[T]
Create a new stateful widget with initial state
proc newWidget(): Widget {....raises: [], tags: [], forbids: [].}
Create a new base widget
proc renderStateful[T](widget: StatefulWidget[T]; area: Rect; buf: var Buffer)
Render a stateful widget Default implementation does nothing
proc renderWidget(widget: Widget; area: Rect; buf: var Buffer) {.
    ...raises: [Exception], tags: [RootEffect], forbids: [].}
Convenience function to render any widget
proc renderWidgetAt(widget: Widget; x, y, width, height: int; buf: var Buffer) {.
    ...raises: [Exception], tags: [RootEffect], forbids: [].}
Render widget at specific coordinates
proc setState[T](widget: StatefulWidget[T]; newState: T)
Set the state of a stateful widget
proc updateState[T](widget: StatefulWidget[T]; updateFn: proc (state: T): T)
Update the state using a function

Methods

method canFocus(widget: Widget): bool {.base, ...raises: [], tags: [], forbids: [].}
Check if this widget can receive focus Default: widgets cannot receive focus
method getMinSize(widget: Widget): Size {.base, ...raises: [], tags: [],
    forbids: [].}
Get the minimum size required by this widget Default: no minimum size constraint
method getPreferredSize(widget: Widget; available: Size): Size {.base,
    ...raises: [], tags: [], forbids: [].}
Get the preferred size for the given available space Default: use all available space
method render(widget: Widget; area: Rect; buf: var Buffer) {.base, ...raises: [],
    tags: [], forbids: [].}
Render the widget into the given buffer area Default implementation does nothing