class Opal::UI::Switch

Overview

Interactive toggle switch widget inspired by Python Textual's Switch. Features smooth pill-track rendering, keyboard (Space/Enter) toggle, mouse click hit-testing, customizable ON/OFF glyphs and colors, and change callbacks.

Defined in:

opal/ui/components/switch.cr

Constructors

Instance Method Summary

Constructor methods inherited from class Opal::UI::Control

new new

Instance methods inherited from module Opal::UI::InputHookable

custom_inputs=(custom_inputs : Bool) custom_inputs=, custom_inputs? : Bool custom_inputs?, default_input_proc : Proc(InputEvent, Bool) | Nil default_input_proc, default_input_proc=(default_input_proc : Proc(InputEvent, Bool) | Nil) default_input_proc=, fallback_to_defaults!(enabled : Bool = true) : self fallback_to_defaults!, fallback_to_defaults=(fallback_to_defaults : Bool) fallback_to_defaults=, fallback_to_defaults? : Bool fallback_to_defaults?, focus : self focus, focused=(focused : Bool) focused=, focused? : Bool focused?, handle_default_input(event : InputEvent) : Bool handle_default_input, handle_input(event : InputEvent) : Bool handle_input, handle_key(key : Terminal::KeyEvent) : Bool handle_key, handle_mouse(event : Terminal::MouseEvent) : Bool handle_mouse, input_hook : Proc(InputEvent, Bool) | Nil input_hook, input_hook=(input_hook : Proc(InputEvent, Bool) | Nil) input_hook=, on_input(&block : self, InputEvent -> Bool) : self on_input, puppet(&block : self, InputEvent -> Bool) : self puppet, reset_inputs : self reset_inputs, setup_default_inputs : Nil setup_default_inputs, unfocus : self unfocus, use_custom_inputs!(enabled : Bool = true) : self use_custom_inputs!

Instance methods inherited from class Opal::UI::Element

add_class(name : String) : self add_class, children : Array(Element) children, classes : Set(String) classes, classes=(classes : Set(String)) classes=, has_class?(name : String) : Bool has_class?, id : String | Nil id, id=(id : String | Nil) id=, preferred_print_size(available_w : Int32) : Tuple(Int32, Int32) preferred_print_size, preferred_size(available_w : Int32, available_h : Int32) : Tuple(Int32, Int32) preferred_size, print(io : IO = STDOUT, width : Int32 | Nil = nil, color : Bool | Nil = nil, theme : Theme | Nil = nil) : Nil print, query(selector : String) : Array(Element)
query(klass : T.class) : Array(T) forall T
query
, query_one(selector : String) : Element
query_one(klass : T.class) : T forall T
query_one
, query_one?(selector : String) : Element | Nil
query_one?(klass : T.class) : T | Nil forall T
query_one?
, remove_class(name : String) : self remove_class, render(buffer : Buffer, x : Int32, y : Int32, width : Int32, height : Int32) : Nil render, render_print(buffer : Buffer, width : Int32, height : Int32) : Nil render_print, to_print_s(width : Int32 | Nil = nil, color : Bool | Nil = nil, theme : Theme | Nil = nil) : String to_print_s, to_string(width : Int32 | Nil = nil, color : Bool | Nil = nil, theme : Theme | Nil = nil) : String to_string

Instance methods inherited from module Opal::UI::Themable

current_theme : Theme current_theme, style(&block : self -> Nil) : self style, theme : Theme | Nil theme, theme=(theme : Theme | Nil) theme=, with_theme(new_theme : Theme | Symbol | String) : self with_theme

Constructor Detail

def self.new(label : String | Nil = nil, on : Bool = false, disabled : Bool = false, on_change : Proc(Bool, Nil) | Nil = nil) #

[View source]
def self.new(label : String | Nil = nil, on : Bool = false, disabled : Bool = false, &block : Bool -> Nil) : Switch #

[View source]

Instance Method Detail

def disabled=(disabled : Bool) #

[View source]
def disabled? : Bool #

[View source]
def focus_border_fg : Color | Nil #

[View source]
def focus_border_fg=(focus_border_fg : Color | Nil) #

[View source]
def handle_key(event : Terminal::KeyEvent) : Bool #
Description copied from module Opal::UI::InputHookable

Default key event handler. Override in subclasses if not using @default_input_proc.


[View source]
def handle_mouse(event : Terminal::MouseEvent) : Bool #
Description copied from module Opal::UI::InputHookable

Default mouse event handler. Override in subclasses if not using @default_input_proc.


[View source]
def label : String | Nil #

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

[View source]
def label_fg : Color | Nil #

[View source]
def label_fg=(label_fg : Color | Nil) #

[View source]
def off_thumb_bg : Color | Nil #

[View source]
def off_thumb_bg=(off_thumb_bg : Color | Nil) #

[View source]
def off_thumb_fg : Color | Nil #

[View source]
def off_thumb_fg=(off_thumb_fg : Color | Nil) #

[View source]
def off_track_bg : Color | Nil #

[View source]
def off_track_bg=(off_track_bg : Color | Nil) #

[View source]
def off_track_fg : Color | Nil #

[View source]
def off_track_fg=(off_track_fg : Color | Nil) #

[View source]
def on=(val : Bool) #

[View source]
def on? : Bool #

[View source]
def on_change : Proc(Bool, Nil) | Nil #

[View source]
def on_change(&block : Bool -> Nil) : self #

[View source]
def on_change=(on_change : Proc(Bool, Nil) | Nil) #

[View source]
def on_thumb_bg : Color | Nil #

[View source]
def on_thumb_bg=(on_thumb_bg : Color | Nil) #

[View source]
def on_thumb_fg : Color | Nil #

Manipulable theme properties and glyph swaps


[View source]
def on_thumb_fg=(on_thumb_fg : Color | Nil) #

Manipulable theme properties and glyph swaps


[View source]
def on_track_bg : Color | Nil #

[View source]
def on_track_bg=(on_track_bg : Color | Nil) #

[View source]
def on_track_fg : Color | Nil #

[View source]
def on_track_fg=(on_track_fg : Color | Nil) #

[View source]
def preferred_size(available_w : Int32, available_h : Int32) : Tuple(Int32, Int32) #

[View source]
def render(buffer : Buffer, x : Int32, y : Int32, width : Int32, height : Int32) : Nil #

[View source]
def thumb_char : Char | Nil #

[View source]
def thumb_char=(thumb_char : Char | Nil) #

[View source]
def toggle : self #

Toggles state if not disabled


[View source]
def track_char : Char | Nil #

[View source]
def track_char=(track_char : Char | Nil) #

[View source]