Module: ui.widgets.button
Source: ./ui/widgets/button.reef
Overview
ui/widgets/button.reef - Clickable button widget Part of reef-stdlib UI module
The Button widget provides an interactive button that responds to mouse clicks and keyboard activation. It supports:
- Text labels
- Multiple visual states (normal, hovered, pressed, disabled)
- Focus handling
- Themed appearance
Button generates action events when clicked or activated via keyboard.
Types
ButtonState (enum)
Variants:
NormalHoveredPressedDisabled
Objects
Button
Extends: widget.Widget
Fields:
| Name | Type |
|---|---|
label |
string |
state |
ButtonState |
focused |
bool |
min_width |
float |
padding_h |
float |
padding_v |
float |
proc init(id: widget.WidgetId, label: string)
Methods:
override shared fn kind(): string
exclusive proc set_label(label: string)
exclusive proc set_enabled(enabled: bool)
exclusive proc set_min_width(width: float)
exclusive proc set_padding(horizontal: float, vertical: float)
exclusive proc set_state(state: ButtonState)
exclusive proc set_focused(focused: bool)
shared fn clone(): Button
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 button_state_normal(): ButtonState
fn button_state_hovered(): ButtonState
fn button_state_pressed(): ButtonState
fn button_state_disabled(): ButtonState
fn is_button_normal(s: ButtonState): bool
fn is_button_hovered(s: ButtonState): bool
fn is_button_pressed(s: ButtonState): bool
fn is_button_disabled(s: ButtonState): bool
fn button(label: string): Button
fn button_with_id(label: string, id: int): Button
fn handle_mouse_event(b: Button, me: event.MouseEvent, bounds: core.Rect): widget.EventResult
fn handle_key_event(b: Button, ke: event.KeyEvent): widget.EventResult
fn handle_focus_event(b: Button, fe: event.FocusEvent): widget.EventResult
fn get_button_background(state: ButtonState, colors: theme.ThemeColors): core.Color
fn get_button_text_color(state: ButtonState, colors: theme.ThemeColors): core.Color
fn get_button_border_color(state: ButtonState, colors: theme.ThemeColors): core.Color
fn point_in_rect(px: float, py: float, r: core.Rect): bool
fn string_length(s: string): int
fn keys_equal(a: keys.KeyCode, b: keys.KeyCode): bool
Procedures
proc draw_rect_border(surf: surface.Surface, x: float, y: float, w: float, h: float, color: core.Color, width: float)
Generated by reefc doc