abstract class Opal::UI::Element

Overview

Base class for all visual components in the declarative UI hierarchy.

Included Modules

Direct Known Subclasses

Defined in:

opal/ui/element.cr

Instance Method Summary

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

Instance Method Detail

def add_class(name : String) : self #

[View source]
def children : Array(Element) #

Returns child elements for hierarchical tree traversal and DOM querying


[View source]
def classes : Set(String) #

[View source]
def classes=(classes : Set(String)) #

[View source]
def has_class?(name : String) : Bool #

[View source]
def id : String | Nil #

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

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

Returns the preferred size for one-shot print mode rendering, where height should expand to fit all content rather than clamping to viewport rows.


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

[View source]
def print(io : IO = STDOUT, width : Int32 | Nil = nil, color : Bool | Nil = nil, theme : Theme | Nil = nil) : Nil #

Prints the element directly to an IO stream in one-shot print mode.


[View source]
def query(selector : String) : Array(Element) #

Queries all descendants matching a CSS-like selector string


[View source]
def query(klass : T.class) : Array(T) forall T #

Queries all descendants matching a specific Crystal type class


[View source]
def query_one(selector : String) : Element #

Queries the first descendant matching selector, or raises KeyError


[View source]
def query_one(klass : T.class) : T forall T #

Queries the first descendant matching type class, or raises KeyError


[View source]
def query_one?(selector : String) : Element | Nil #

Queries the first descendant matching selector, or nil


[View source]
def query_one?(klass : T.class) : T | Nil forall T #

Queries the first descendant matching type class, or nil


[View source]
def remove_class(name : String) : self #

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

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

Print-mode rendering hook that components can override if their print layout differs from interactive layout


[View source]
def to_print_s(width : Int32 | Nil = nil, color : Bool | Nil = nil, theme : Theme | Nil = nil) : String #

Renders the element into a string buffer in one-shot print mode. If color is nil, auto-detects from TTY and NO_COLOR environment variable.


[View source]
def to_string(width : Int32 | Nil = nil, color : Bool | Nil = nil, theme : Theme | Nil = nil) : String #

Alias for to_print_s


[View source]