class Crysterm::Widget

Included Modules

Direct Known Subclasses

Defined in:

widget.cr
widget/bigtext.cr
widget/box.cr
widget/button.cr
widget/checkbox.cr
widget/hline.cr
widget/input.cr
widget/label.cr
widget/layout.cr
widget/line.cr
widget/list.cr
widget/listtable.cr
widget/loading.cr
widget/log.cr
widget/menu.cr
widget/message.cr
widget/overlayimage.cr
widget/pine/header_bar.cr
widget/pine/status_bar.cr
widget/progressbar.cr
widget/prompt.cr
widget/question.cr
widget/radiobutton.cr
widget/radioset.cr
widget/scrollable_box.cr
widget/scrollable_text.cr
widget/textarea.cr
widget/textbox.cr
widget/vline.cr
widget_children.cr
widget_content.cr
widget_decoration.cr
widget_index.cr
widget_interaction.cr
widget_label.cr
widget_position.cr
widget_rendering.cr
widget_screenshot.cr
widget_scrolling.cr
widget_size.cr
widget_visibility.cr

Constant Summary

SGR_REGEX = /\e\[[\d;]*m/

Convenience regex for matching SGR sequences.

SGR_REGEX_AT_BEGINNING = /^#{SGR_REGEX}/

Convenience regex for matching SGR sequences.

TAG_REGEX = /\{(\/?)([\w\-,;!#]*)\}/

Convenience regex for matching Crysterm tags and their content (i.e. '{bold}This text is bold{/bold}').

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from module Crysterm::Mixin::Data

data : YAML::Any | Nil data, data=(data : YAML::Any | Nil) data=

Instance methods inherited from module Crysterm::Mixin::Style

state state, state=(state) state=, style : Crysterm::Style style, style=(style : Crysterm::Style | Nil) style=, styles : Crysterm::Styles styles, styles=(styles : Crysterm::Styles) styles=

Instance methods inherited from module Crysterm::Mixin::Pos

abottom : Int32 | Nil abottom, abottom=(abottom : Int32 | Nil) abottom=, aleft : Int32 | Nil aleft, aleft=(aleft : Int32 | Nil) aleft=, aright : Int32 | Nil aright, aright=(aright : Int32 | Nil) aright=, atop : Int32 | Nil atop, atop=(atop : Int32 | Nil) atop=, lpos : LPos | Nil lpos, lpos=(lpos : LPos | Nil) lpos=, renders renders, renders=(renders) renders=, scrollable=(scrollable) scrollable=, scrollable? scrollable?

Instance methods inherited from module Crysterm::Mixin::Uid

uid : Int32 uid, uid=(uid : Int32) uid=

Class methods inherited from module Crysterm::Mixin::Uid

next_uid : Int32 next_uid

Instance methods inherited from module Crysterm::Mixin::Name

name : String | Nil name, name=(name : String | Nil) name=

Macros inherited from module Crysterm::Macros

alias_method(new_method, old_method) alias_method, alias_previous(*new_methods) alias_previous, handle(event, handler = nil) handle

Instance methods inherited from module Crysterm::Helpers

asort(obj) asort, clean_tags(text) clean_tags, drop_unicode(text) drop_unicode, escape(text) escape, find_file(start, target) find_file, hsort(obj) hsort, strip_tags(text : String) strip_tags

Instance methods inherited from module Crysterm::Mixin::Children

<<(widget : Widget) <<, >>(widget : Widget) >>, append(element)
append(*elements)
append
, children children, collect_ancestors(el : Widget) : Array(Widget) collect_ancestors, collect_descendants(el : Widget) : Array(Widget) collect_descendants, each_ancestor(&block : Proc(Widget, Nil)) : Nil each_ancestor, each_descendant(&block : Proc(Widget, Nil)) : Nil each_descendant, emit_ancestors(ev : EventHandler::Event | EventHandler::Event.class) : Nil emit_ancestors, emit_descendants(ev : EventHandler::Event | EventHandler::Event.class) : Nil emit_descendants, has_ancestor?(obj) has_ancestor?, has_descendant?(obj) has_descendant?, insert(element, i = -1) insert, insert_after(element, other) insert_after, insert_before(element, other) insert_before, prepend(element) prepend, remove(element) remove, self_and_each_ancestor(&block : Proc(Widget, Nil)) : Nil self_and_each_ancestor, self_and_each_descendant(&block : Proc(Widget, Nil)) : Nil self_and_each_descendant

Constructor Detail

def self.new(parent = nil, *, name : Nil | String = @name, screen : Nil | Crysterm::Screen = @screen, left : Int32 | String | Nil = @left, top : Int32 | String | Nil = @top, right : Int32 | Nil = @right, bottom : Int32 | Nil = @bottom, width : Int32 | String | Nil = @width, height : Int32 | String | Nil = @height, resizable : Bool = @resizable, visible = nil, fixed : Bool = @fixed, align : Tput::Namespace::AlignFlag = @align, overflow : Crysterm::Overflow = @overflow, scrollbar : Bool = @scrollbar, track : Bool = @track, content = "", parse_tags : Bool = @parse_tags, wrap_content : Bool = @wrap_content, label = nil, hover_text = nil, scrollable = nil, always_scroll : Bool = @always_scroll, draggable : Bool = @draggable, focused = false, focus_on_click : Bool = @focus_on_click, keys : Bool = @keys, vi : Bool = @vi, input = nil, style = nil, styles : Crysterm::Styles = @styles, index : Int32 = -1, children = [] of Widget) #

[View source]

Class Method Detail

def self.sattr(style, fg = nil, bg = nil) #

[View source]

Instance Method Detail

def _align(line, width, align = Tput::AlignFlag::None, align_left_too = false) #

Aligns content


[View source]
def _clines : Crysterm::Widget::CLines #

[View source]
def _clines=(_clines : Crysterm::Widget::CLines) #

[View source]
def _get_coords(get = false, noscroll = false) #

[View source]
def _is_list : Bool #

XXX FIX by removing at some point Used only for lists. The reason why it hasn't been replaced with is_a?(List) already is because maybe someone would want this to be true even if not inheriting from List.


[View source]
def _is_list=(_is_list : Bool) #

XXX FIX by removing at some point Used only for lists. The reason why it hasn't been replaced with is_a?(List) already is because maybe someone would want this to be true even if not inheriting from List.


[View source]
def _label : Widget | Nil #

Widget implementing the label. If label is asked for and no specific widget is set, we create a TextBox with chosen content.. But one can set this property manually to have a custom/specific label.


[View source]
def _label! #

[View source]
def _label=(_label : Widget | Nil) #

Widget implementing the label. If label is asked for and no specific widget is set, we create a TextBox with chosen content.. But one can set this property manually to have a custom/specific label.


[View source]
def _minimal_children_rectangle(xi, xl, yi, yl, get) #

Returns minimum widget size based on bounding box


[View source]
def _minimal_content_rectangle(xi, xl, yi, yl) #

Returns minimum widget size based on content.

NOTE For this function to return intended results, the widget whose contents are being examined should not have a particular #align= value. If #align= is used, the alignment method will align it by padding with spaces, and in turn make the minimal size returned from this method be the maximum/full size of the surrounding box.


[View source]
def _minimal_rectangle(xi, xl, yi, yl, get) #

Returns minimum widget size


[View source]
def _parse_attr(lines : CLines) #

[View source]
def _parse_tags(text) #

Convert {red-fg}foo{/red-fg} to \e[31mfoo\e[39m.


[View source]
def _pcontent : String | Nil #

Printable, word-wrapped content, ready for rendering into the element.


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

Printable, word-wrapped content, ready for rendering into the element.


[View source]
def _recalculate_index #

[View source]
def _render(with_children = true) #

Renders all child elements into the output buffer.


[View source]
def _scroll_bottom #

[View source]
def _wrap_content(content, colwidth) #

Wraps content based on available widget width


[View source]
def abottom(get = false) #

Returns computed absolute bottom position


[View source]
def aheight(get = false) #

Returns computed height


[View source]
def aleft(get = false) #

Returns computed absolute left position


[View source]
def align : Tput::AlignFlag #

Alignment of contained text


[View source]
def align=(align : Tput::AlignFlag) #

Alignment of contained text


[View source]
def always_scroll=(always_scroll : Bool) #

[View source]
def always_scroll? : Bool #

[View source]
def aright(get = false) #

Returns computed absolute right position


[View source]
def atop(get = false) #

Returns computed absolute top position


[View source]
def awidth(get = false) #

Returns computed width


[View source]
def back! #

Sends widget to back


[View source]
def base_limit : Int32 #

[View source]
def base_limit=(base_limit : Int32) #

[View source]
def border_char(border, x, xi, xl, y, yi, yl, default_attr) #

[View source]
def bottom : Int32 | Nil #

User-defined bottom


[View source]
def bottom=(val : Int32 | Nil) #

Sets Widget's @bottom


[View source]
def child_base : Int32 #

Offset from the top of content (in number of lines) due to scrolling. E.g. 0 == no scroll (first line is visible/shown at the top), or 5 == 5 lines are hidden due to scroll, 6th line of content is first to be displayed.


[View source]
def child_base=(child_base : Int32) #

Offset from the top of content (in number of lines) due to scrolling. E.g. 0 == no scroll (first line is visible/shown at the top), or 5 == 5 lines are hidden due to scroll, 6th line of content is first to be displayed.


[View source]
def child_offset : Int32 #

Offset of cursor (in number of lines) within Widget. Value of 0 means cursor being at first line of visible (potentially scrolled) content.


[View source]
def child_offset=(child_offset : Int32) #

Offset of cursor (in number of lines) within Widget. Value of 0 means cursor being at first line of visible (potentially scrolled) content.


[View source]
def clear_base_line(i) #

[View source]
def clear_last_rendered_position(get = false, override = false) #

Clears area/position of widget's last render


[View source]
def clear_line(i) #

[View source]
def clickable=(clickable : Bool) #

Is element clickable?


[View source]
def clickable? : Bool #

Is element clickable?


[View source]
def content : String #

Widget's user-set content in original form. Includes any attributes and tags.


[View source]
def content=(content) #

Processes and sets widget content. Does not allow extra options re. how content is to be processed; use #set_content if you need to provide extra options.


[View source]
def delete_bottom(n) #

[View source]
def delete_line(i = nil, n = 1) #

[View source]
def delete_top(n = 1) #

[View source]
def destroy #

[View source]
def determine_screen #

[View source]
def disable_drag #

[View source]
def draggable=(draggable : Bool) #

[View source]
def draggable=(draggable : Bool) #

Is element draggable?


[View source]
def draggable? : Bool? #

Is element draggable?


[View source]
def enable_drag(x) #

[View source]
def focus #

Puts current widget in focus


[View source]
def focus_on_click=(focus_on_click : Bool) #

[View source]
def focus_on_click? : Bool #

[View source]
def focused? #

Returns whether widget is currently in focus


[View source]
def front! #

Sends widget to front


[View source]
def get_baseline(i) #

[View source]
def get_content #

[View source]
def get_line(i) #

[View source]
def get_lines #

[View source]
def get_screen_lines #

[View source]
def get_scroll #

Returns total amount of lines by which widget is scrolled.

The value combines invisible and visible parts. E.g. if a widget is scrolled by 6 lines which are invisible (out of screen), and the cursor is at the 5th line of visible content, #get_scroll will return 11.


[View source]
def get_scroll_height #

[View source]
def get_scroll_perc(s) #

[View source]
def get_text #

[View source]
def height : Int32 | String | Nil #

User-defined height (setter is defined below)


[View source]
def height=(val : Int32 | String | Nil) #

Sets widget's total height


[View source]
def hide #

Hides widget from screen


[View source]
def ibottom #

Returns computed content offset from bottom


[View source]
def ignore_keys=(ignore_keys : Bool) #

[View source]
def ignore_keys? : Bool #

[View source]
def iheight #

Returns summed amount of content offset from top and bottom


[View source]
def ileft #

Returns computed content offset from left


[View source]
def index : Int32 #

[View source]
def index=(index : Int32) #

[View source]
def input=(input : Bool) #

Does it accept keyboard input?


[View source]
def input? : Bool #

Does it accept keyboard input?


[View source]
def insert(element, i = -1) #

Inserts element to list of children at a specified position (at end by default)


[View source]
def insert_bottom(line) #

[View source]
def insert_line(i = nil, line = "") #

[View source]
def insert_top(line) #

[View source]
def interactive=(interactive : Bool) #

[View source]
def interactive? : Bool #

[View source]
def iright #

Returns computed content offset from right


[View source]
def items : Array(Crysterm::Widget::Box) #

[View source]
def items=(items : Array(Crysterm::Widget::Box)) #

[View source]
def itop #

Returns computed content offset from top


[View source]
def iwidth #

Returns summed amount of content offset from left and right


[View source]
def keyable=(keyable : Bool) #

Can element receive keyboard input? (Managed internally; use input for user-side setting)


[View source]
def keyable? : Bool #

Can element receive keyboard input? (Managed internally; use input for user-side setting)


[View source]
def keys=(keys : Bool) #

Should widget react to some pre-defined keys in it?


[View source]
def keys? : Bool #

Should widget react to some pre-defined keys in it?


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

Sets or clears label text


[View source]
def last_rendered_position #

[View source]
def left : Int32 | String | Nil #

User-defined left


[View source]
def left=(val : Int32 | String | Nil) #

Sets Widget's @left


[View source]
def overflow : Crysterm::Overflow #

What action to take when widget is overflowing parent's rectangle?


[View source]
def overflow=(overflow : Crysterm::Overflow) #

What action to take when widget is overflowing parent's rectangle?


[View source]
def parent : Widget | Nil #

Widget's parent Widget, if any.


[View source]
def parent=(parent : Widget | Nil) #

Widget's parent Widget, if any.


[View source]
def parent_or_screen #

Returns parent Widget (if any) or Screen to which the widget may be attached. If the widget already is Screen, returns nil.


[View source]
def parse_tags=(parse_tags : Bool) #

Is element's content to be parsed for tags?


[View source]
def parse_tags? : Bool #

Is element's content to be parsed for tags?


[View source]
def pop_line(n) #

[View source]
def process_content(no_tags = false) #

[View source]
def push_line(line) #

[View source]
def rbottom #

Returns computed relative bottom position


[View source]
def really_scrollable? #

Potentially use this where ever .scrollable? is used


[View source]
def remove(element) #

Removes element from list of children


[View source]
def remove_from_parent #

Removes node from its parent. This is identical to calling parent.remove(self).


[View source]
def remove_hover #

[View source]
def remove_label #

Removes widget label


[View source]
def render(with_children = true) #

[View source]
def reposition_label(event = nil) #

Repositions label to the right place. Usually called from resize event


[View source]
def reset_scroll #

[View source]
def resizable=(resizable : Bool) #

Can Crysterm resize the widget if/when needed?


[View source]
def resizable? : Bool #

Can Crysterm resize the widget if/when needed?


[View source]
def right : Int32 | Nil #

User-defined right


[View source]
def right=(val : Int32 | Nil) #

Sets Widget's @right


[View source]
def rleft #

Returns computed relative left position


[View source]
def rright #

Returns computed relative right position


[View source]
def rtop #

Returns computed relative top position


[View source]
def sattr(style, fg = nil, bg = nil) #

[View source]
def screen : Crysterm::Screen | Nil #

Screen owning this element, forced to non-nil at time of access. Each element must belong to a Screen if it is to be rendered/displayed anywhere. If you just want to test for screen being set, use #screen?.


def screen=(screen : Crysterm::Screen | Nil) #

Screen owning this element, forced to non-nil at time of access. Each element must belong to a Screen if it is to be rendered/displayed anywhere. If you just want to test for screen being set, use #screen?.


[View source]
def screen? : Crysterm::Screen? #

Screen owning this element, forced to non-nil at time of access. Each element must belong to a Screen if it is to be rendered/displayed anywhere. If you just want to test for screen being set, use #screen?.


[View source]
def screenshot(xi = nil, xl = nil, yi = nil, yl = nil) #

Takes screenshot of a widget.

Does not include decorations, but content only.

It is possible to influence the coordinates that will be screenshot with the 4 arguments to the function, but they are not intuitive.


[View source]
def scroll(offset = 1, always = false) #

Scrolls widget by offset lines down or up


[View source]
def scroll_to(offset, always = false) #

[View source]
def scrollable=(scrollable : Bool) #

Is element scrollable?


[View source]
def scrollable? : Bool #

Is element scrollable?


[View source]
def scrollbar=(scrollbar : Bool) #

[View source]
def scrollbar? : Bool #

[View source]
def set_baseline(i, line) #

[View source]
def set_content(content : String = "", no_clear = false, no_tags = false) #

[View source]
def set_hover(hover_text) #

[View source]
def set_index(index : Int) #

[View source]
def set_label(text : String, side = "left") #

Sets widget label. Can be positioned "left" (default) or "right"


[View source]
def set_line(i, line) #

[View source]
def set_scroll_perc(i) #

[View source]
def set_text(content = "", no_clear = false) #

[View source]
def shift_line(n) #

[View source]
def show #

Shows widget on screen


[View source]
def snapshot(include_decorations = true, dxi = 0, dxl = 0, dyi = 0, dyl = 0) #

Takes screenshot of a widget in a more convenient way than #screenshot.

To take a screenshot of entire widget, just call #snapshot. To avoid decorations, use #snapshot(false).

To additionally fine-tune the region, pass 'd' values. For example to enlarge the area of screenshot by 1 cell on the left, 2 cells on the right, 3 on top, and 4 on the bottom, call:

snapshot(true, -1, 2, -3, 4)

This is hopefully better than the equivalent you would have to use with #screenshot:

screenshot(-ileft - 1, width + iright + 2, -itop - 3, height + ibottom + 4)

[View source]
def str_width(text) #

[View source]
def toggle_visibility #

Toggles widget visibility


[View source]
def top : Int32 | String | Nil #

User-defined top


[View source]
def top=(val : Int32 | String | Nil) #

Sets Widget's @top


[View source]
def track=(track : Bool) #

Should widget indicate the scroll position?


[View source]
def track? : Bool #

Should widget indicate the scroll position?


[View source]
def unshift_line(line) #

[View source]
def vi=(vi : Bool) #

[View source]
def vi? : Bool #

[View source]
def visible? #

Returns whether widget is visible. Currently does not check if all parents are also visible.


[View source]
def width : Int32 | String | Nil #

User-defined width (setter is defined below)


[View source]
def width=(val : Int32 | String | Nil) #

Sets widget's total width


[View source]
def wrap_content=(wrap_content : Bool) #

Can element's content be word-wrapped?


[View source]
def wrap_content? : Bool #

Can element's content be word-wrapped?


[View source]