Module: ui.widgets.checkbox

Source: ./ui/widgets/checkbox.reef


Overview

ui/widgets/checkbox.reef - Boolean toggle control Part of reef-stdlib UI module

The Checkbox widget provides a toggleable boolean control. It displays a box that can be checked or unchecked, with an optional text label.

Checkboxes support:

  • Checked/unchecked states
  • Optional indeterminate state
  • Text labels
  • Focus and disabled states
  • Keyboard activation (Space to toggle)

Types

CheckState (enum)

Variants:

  • Unchecked
  • Checked
  • Indeterminate

Objects

Checkbox

Extends: widget.Widget

Fields:

Name Type
label string
check_state CheckState
focused bool
hovered bool

proc init(id: widget.WidgetId, label: string)

Methods:

override shared fn kind(): string

exclusive proc set_label(label: string)

exclusive proc set_checked(checked: bool)

exclusive proc set_state(state: CheckState)

exclusive proc set_enabled(enabled: bool)

exclusive proc toggle()

exclusive proc set_hovered(hovered: bool)

exclusive proc set_focused(focused: bool)

shared fn clone(): Checkbox

D2 (docs/design/2026-09-08-ui-modernization.md): a SHALLOW copy. Setters mutate the receiver (reef-lang#62), so "give me a variant and leave the original alone" has to be asked for explicitly. Referenced objects are shared, not deep-copied.

shared fn preferred_size(th: theme.Theme): core.Size

exclusive proc layout(constraints: layout.Constraints, th: theme.Theme)

override exclusive fn handle_event(e: event.Event): widget.EventResult

override exclusive proc paint(surf: surface.Surface, th: theme.Theme)


Functions

fn check_unchecked(): CheckState

fn check_checked(): CheckState

fn check_indeterminate(): CheckState

fn is_unchecked(s: CheckState): bool

fn is_checked(s: CheckState): bool

fn is_indeterminate(s: CheckState): bool

fn checkbox(label: string): Checkbox

fn checkbox_checked(label: string, checked: bool): Checkbox

fn checkbox_is_checked(c: Checkbox): bool

fn handle_mouse_event(c: Checkbox, me: event.MouseEvent, bounds: core.Rect): widget.EventResult

fn handle_key_event(c: Checkbox, ke: event.KeyEvent): widget.EventResult

fn handle_focus_event(c: Checkbox, fe: event.FocusEvent): widget.EventResult

fn get_box_background(c: Checkbox, colors: theme.ThemeColors): core.Color

fn get_box_border(c: Checkbox, colors: theme.ThemeColors): core.Color

fn get_text_color(c: Checkbox, colors: theme.ThemeColors): core.Color

fn point_in_rect(px: float, py: float, r: core.Rect): bool

fn string_length(s: string): int


Procedures

proc draw_checkmark(surf: surface.Surface, x: float, y: float, size: float, colors: theme.ThemeColors)

proc draw_dash(surf: surface.Surface, x: float, y: float, size: float, colors: theme.ThemeColors)

proc draw_rect_border(surf: surface.Surface, x: float, y: float, w: float, h: float, color: core.Color, width: float)


Generated by reefc doc