class UI::Button

Overview

A tappable button with a text label and optional action callback.

The #on_tap proc is invoked when the button is activated. Buttons can be disabled to prevent interaction.

Defined in:

ui/views/button.cr

Constructors

Instance Method Summary

Instance methods inherited from class UI::View

accept(visitor : PlatformVisitor) accept, accessibility_label : String | Nil accessibility_label, accessibility_label=(accessibility_label : String | Nil) accessibility_label=, background : Color | Nil background, background=(background : Color | Nil) background=, blur_radius : Float64 blur_radius, blur_radius=(blur_radius : Float64) blur_radius=, border_color : Color | Nil border_color, border_color=(border_color : Color | Nil) border_color=, border_width : Float64 border_width, border_width=(border_width : Float64) border_width=, clip_to_bounds : Bool clip_to_bounds, clip_to_bounds=(clip_to_bounds : Bool) clip_to_bounds=, container_query(name : String) : self container_query, container_query_name : String | Nil container_query_name, container_query_name=(container_query_name : String | Nil) container_query_name=, corner_radius : Float64 corner_radius, corner_radius=(corner_radius : Float64) corner_radius=, fill_screen! : self fill_screen!, fluid_height(min : String | Number, ideal : String | Number, max : String | Number) : self
fluid_height : UI::Fluid | Nil
fluid_height
, fluid_height=(fluid_height : UI::Fluid | Nil) fluid_height=, fluid_width(min : String | Number, ideal : String | Number, max : String | Number) : self
fluid_width : UI::Fluid | Nil
fluid_width
, fluid_width=(fluid_width : UI::Fluid | Nil) fluid_width=, hidden : Bool hidden, hidden=(hidden : Bool) hidden=, id : String | Nil id, id=(id : String | Nil) id=, maximum_height : Float64 | Nil maximum_height, maximum_height=(maximum_height : Float64 | Nil) maximum_height=, maximum_width : Float64 | Nil maximum_width, maximum_width=(maximum_width : Float64 | Nil) maximum_width=, minimum_height : Float64 | Nil minimum_height, minimum_height=(minimum_height : Float64 | Nil) minimum_height=, minimum_width : Float64 | Nil minimum_width, minimum_width=(minimum_width : Float64 | Nil) minimum_width=, opacity : Float64 opacity, opacity=(opacity : Float64) opacity=, padding : EdgeInsets padding, padding=(padding : EdgeInsets) padding=, root_fill : Bool root_fill, root_fill=(root_fill : Bool) root_fill=, shadow_color : Color | Nil shadow_color, shadow_color=(shadow_color : Color | Nil) shadow_color=, shadow_offset_x : Float64 shadow_offset_x, shadow_offset_x=(shadow_offset_x : Float64) shadow_offset_x=, shadow_offset_y : Float64 shadow_offset_y, shadow_offset_y=(shadow_offset_y : Float64) shadow_offset_y=, shadow_radius : Float64 shadow_radius, shadow_radius=(shadow_radius : Float64) shadow_radius=, swiftkit_state_handle : Pointer(Void) | Nil swiftkit_state_handle, swiftkit_state_handle=(swiftkit_state_handle : Pointer(Void) | Nil) swiftkit_state_handle=, test_id : String | Nil test_id, test_id=(test_id : String | Nil) test_id=

Constructor Detail

def self.new(label : String, *, role : Symbol = :default, style : ButtonStyle = ButtonStyle::Default, symbol : String | Nil = nil, type : Type = Type::Button) #

[View source]
def self.new(label : String, *, role : Symbol = :default, style : ButtonStyle = ButtonStyle::Default, symbol : String | Nil = nil, type : Type = Type::Button, &block : -> Nil) #

Convenience constructor that accepts a tap handler block


[View source]

Instance Method Detail

def accept(visitor : PlatformVisitor) #
Description copied from class UI::View

Accept a platform visitor for rendering dispatch. Each concrete view type calls visitor.visit(self).


[View source]
def background=(new_color : Color | Nil) : Color | Nil #
Description copied from class UI::View

Background color, nil means transparent/inherited


[View source]
def corner_radius=(new_radius : Float64) : Float64 #
Description copied from class UI::View

Shape modifiers


[View source]
def disabled : Bool #

Whether the button is disabled (non-interactive).

Reactive: after the renderer has emitted the SwiftUI hosting view, mutating this property propagates through the SwiftKit bridge so SwiftUI re-renders the Button with .disabled(true) / .disabled(false) without a tree rebuild. Setters issued before the view has been rendered are plain property assignments — the next render seeds the reactive state from the new value. Phase 6.11 added the reactive path so the Voyager Todo editor can flip Save's disabled state as the user types (blank title → disabled; non-blank → enabled) without rebuilding the whole screen.


[View source]
def disabled=(new_value : Bool) : Bool #

[View source]
def font : Font #

Font for the button label


[View source]
def font=(font : Font) #

Font for the button label


[View source]
def foreground_color : Color #

Foreground (label) color


[View source]
def foreground_color=(new_color : Color) : Color #

Foreground (label) color


[View source]
def label : String #

The button's display label


[View source]
def label=(label : String) #

The button's display label


[View source]
def on_tap : Proc(Nil) | Nil #

Callback invoked when the button is tapped


[View source]
def on_tap=(on_tap : Proc(Nil) | Nil) #

Callback invoked when the button is tapped


[View source]
def role : Symbol #

Semantic role for the button. HIG-standard values: :default — normal/primary action (no special styling) :destructive — action destroys data; renderers color the label red :cancel — dismisses a presentation surface; renderers weight the label Semibold per HIG


[View source]
def role=(role : Symbol) #

Semantic role for the button. HIG-standard values: :default — normal/primary action (no special styling) :destructive — action destroys data; renderers color the label red :cancel — dismisses a presentation surface; renderers weight the label Semibold per HIG


[View source]
def style : ButtonStyle #

Visual style. See ButtonStyle for full documentation. Default renders as a system bordered button; override to Prominent for filled-blue primary CTAs or Borderless for text-link style.


[View source]
def style=(style : ButtonStyle) #

Visual style. See ButtonStyle for full documentation. Default renders as a system bordered button; override to Prominent for filled-blue primary CTAs or Borderless for text-link style.


[View source]
def symbol : String | Nil #

Leading SF Symbol glyph name (macOS 11+ / iOS 13+). When non-nil the renderers prepend an SF Symbol image to the button. Unknown symbol names are silently skipped rather than crashing.


[View source]
def symbol=(symbol : String | Nil) #

Leading SF Symbol glyph name (macOS 11+ / iOS 13+). When non-nil the renderers prepend an SF Symbol image to the button. Unknown symbol names are silently skipped rather than crashing.


[View source]
def type : Type #

HTML form-submission role on the web target. See UI::Button::Type. Defaults to Type::Button (non-submitting). Set explicitly on the button intended to submit a UI::Form — multi-button forms do NOT auto-promote; only single-button forms do (see UI::Form).


[View source]
def type=(type : Type) #

HTML form-submission role on the web target. See UI::Button::Type. Defaults to Type::Button (non-submitting). Set explicitly on the button intended to submit a UI::Form — multi-button forms do NOT auto-promote; only single-button forms do (see UI::Form).


[View source]