class Crysterm::Widget
- Crysterm::Widget
- Reference
- Object
Included Modules
- Crystallabs::Helpers::Alias_Methods
- Crysterm::Helpers
- Crysterm::Macros
- Crysterm::Mixin::Children
- Crysterm::Mixin::Data
- Crysterm::Mixin::Name
- Crysterm::Mixin::Pos
- Crysterm::Mixin::Style
- Crysterm::Mixin::Uid
- EventHandler
Direct Known Subclasses
- Crysterm::Widget::Box
- Crysterm::Widget::Layout
- Crysterm::Widget::List
- Crysterm::Widget::ListTable
- Crysterm::Widget::Menu
Defined in:
widget.crwidget/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
-
#_align(line, width, align = Tput::AlignFlag::None, align_left_too = false)
Aligns content
- #_clines : Crysterm::Widget::CLines
- #_clines=(_clines : Crysterm::Widget::CLines)
- #_get_coords(get = false, noscroll = false)
-
#_is_list : Bool
XXX FIX by removing at some point Used only for lists.
-
#_is_list=(_is_list : Bool)
XXX FIX by removing at some point Used only for lists.
-
#_label : Widget | Nil
Widget implementing the label.
- #_label!
-
#_label=(_label : Widget | Nil)
Widget implementing the label.
-
#_minimal_children_rectangle(xi, xl, yi, yl, get)
Returns minimum widget size based on bounding box
-
#_minimal_content_rectangle(xi, xl, yi, yl)
Returns minimum widget size based on content.
-
#_minimal_rectangle(xi, xl, yi, yl, get)
Returns minimum widget size
- #_parse_attr(lines : CLines)
-
#_parse_tags(text)
Convert
{red-fg}foo{/red-fg}
to\e[31mfoo\e[39m
. -
#_pcontent : String | Nil
Printable, word-wrapped content, ready for rendering into the element.
-
#_pcontent=(_pcontent : String | Nil)
Printable, word-wrapped content, ready for rendering into the element.
- #_recalculate_index
-
#_render(with_children = true)
Renders all child elements into the output buffer.
- #_scroll_bottom
-
#_wrap_content(content, colwidth)
Wraps content based on available widget width
-
#abottom(get = false)
Returns computed absolute bottom position
-
#aheight(get = false)
Returns computed height
-
#aleft(get = false)
Returns computed absolute left position
-
#align : Tput::AlignFlag
Alignment of contained text
-
#align=(align : Tput::AlignFlag)
Alignment of contained text
- #always_scroll=(always_scroll : Bool)
- #always_scroll? : Bool
-
#aright(get = false)
Returns computed absolute right position
-
#atop(get = false)
Returns computed absolute top position
-
#awidth(get = false)
Returns computed width
-
#back!
Sends widget to back
- #base_limit : Int32
- #base_limit=(base_limit : Int32)
- #border_char(border, x, xi, xl, y, yi, yl, default_attr)
-
#bottom : Int32 | Nil
User-defined bottom
-
#bottom=(val : Int32 | Nil)
Sets Widget's
@bottom
-
#child_base : Int32
Offset from the top of content (in number of lines) due to scrolling.
-
#child_base=(child_base : Int32)
Offset from the top of content (in number of lines) due to scrolling.
-
#child_offset : Int32
Offset of cursor (in number of lines) within Widget.
-
#child_offset=(child_offset : Int32)
Offset of cursor (in number of lines) within Widget.
- #clear_base_line(i)
-
#clear_last_rendered_position(get = false, override = false)
Clears area/position of widget's last render
- #clear_line(i)
-
#clickable=(clickable : Bool)
Is element clickable?
-
#clickable? : Bool
Is element clickable?
-
#content : String
Widget's user-set content in original form.
-
#content=(content)
Processes and sets widget content.
- #delete_bottom(n)
- #delete_line(i = nil, n = 1)
- #delete_top(n = 1)
- #destroy
- #determine_screen
- #disable_drag
- #draggable=(draggable : Bool)
-
#draggable=(draggable : Bool)
Is element draggable?
-
#draggable? : Bool?
Is element draggable?
- #enable_drag(x)
-
#focus
Puts current widget in focus
- #focus_on_click=(focus_on_click : Bool)
- #focus_on_click? : Bool
-
#focused?
Returns whether widget is currently in focus
-
#front!
Sends widget to front
- #get_baseline(i)
- #get_content
- #get_line(i)
- #get_lines
- #get_screen_lines
-
#get_scroll
Returns total amount of lines by which widget is scrolled.
- #get_scroll_height
- #get_scroll_perc(s)
- #get_text
-
#height : Int32 | String | Nil
User-defined height (setter is defined below)
-
#height=(val : Int32 | String | Nil)
Sets widget's total height
-
#hide
Hides widget from screen
-
#ibottom
Returns computed content offset from bottom
- #ignore_keys=(ignore_keys : Bool)
- #ignore_keys? : Bool
-
#iheight
Returns summed amount of content offset from top and bottom
-
#ileft
Returns computed content offset from left
- #index : Int32
- #index=(index : Int32)
-
#input=(input : Bool)
Does it accept keyboard input?
-
#input? : Bool
Does it accept keyboard input?
-
#insert(element, i = -1)
Inserts
element
to list of children at a specified position (at end by default) - #insert_bottom(line)
- #insert_line(i = nil, line = "")
- #insert_top(line)
- #interactive=(interactive : Bool)
- #interactive? : Bool
-
#iright
Returns computed content offset from right
- #items : Array(Crysterm::Widget::Box)
- #items=(items : Array(Crysterm::Widget::Box))
-
#itop
Returns computed content offset from top
-
#iwidth
Returns summed amount of content offset from left and right
-
#keyable=(keyable : Bool)
Can element receive keyboard input? (Managed internally; use
input
for user-side setting) -
#keyable? : Bool
Can element receive keyboard input? (Managed internally; use
input
for user-side setting) -
#keys=(keys : Bool)
Should widget react to some pre-defined keys in it?
-
#keys? : Bool
Should widget react to some pre-defined keys in it?
-
#label=(text : String | Nil)
Sets or clears label text
- #last_rendered_position
-
#left : Int32 | String | Nil
User-defined left
-
#left=(val : Int32 | String | Nil)
Sets Widget's
@left
-
#overflow : Crysterm::Overflow
What action to take when widget is overflowing parent's rectangle?
-
#overflow=(overflow : Crysterm::Overflow)
What action to take when widget is overflowing parent's rectangle?
-
#parent : Widget | Nil
Widget's parent
Widget
, if any. -
#parent=(parent : Widget | Nil)
Widget's parent
Widget
, if any. - #parent_or_screen
-
#parse_tags=(parse_tags : Bool)
Is element's content to be parsed for tags?
-
#parse_tags? : Bool
Is element's content to be parsed for tags?
- #pop_line(n)
- #process_content(no_tags = false)
- #push_line(line)
-
#rbottom
Returns computed relative bottom position
-
#really_scrollable?
Potentially use this where ever .scrollable? is used
-
#remove(element)
Removes
element
from list of children -
#remove_from_parent
Removes node from its parent.
- #remove_hover
-
#remove_label
Removes widget label
- #render(with_children = true)
-
#reposition_label(event = nil)
Repositions label to the right place.
- #reset_scroll
-
#resizable=(resizable : Bool)
Can Crysterm resize the widget if/when needed?
-
#resizable? : Bool
Can Crysterm resize the widget if/when needed?
-
#right : Int32 | Nil
User-defined right
-
#right=(val : Int32 | Nil)
Sets Widget's
@right
-
#rleft
Returns computed relative left position
-
#rright
Returns computed relative right position
-
#rtop
Returns computed relative top position
- #sattr(style, fg = nil, bg = nil)
-
#screen : Crysterm::Screen | Nil
Screen owning this element, forced to non-nil at time of access.
-
#screen=(screen : Crysterm::Screen | Nil)
Screen owning this element, forced to non-nil at time of access.
-
#screen? : Crysterm::Screen?
Screen owning this element, forced to non-nil at time of access.
-
#screenshot(xi = nil, xl = nil, yi = nil, yl = nil)
Takes screenshot of a widget.
-
#scroll(offset = 1, always = false)
Scrolls widget by
offset
lines down or up - #scroll_to(offset, always = false)
-
#scrollable=(scrollable : Bool)
Is element scrollable?
-
#scrollable? : Bool
Is element scrollable?
- #scrollbar=(scrollbar : Bool)
- #scrollbar? : Bool
- #set_baseline(i, line)
- #set_content(content : String = "", no_clear = false, no_tags = false)
- #set_hover(hover_text)
- #set_index(index : Int)
-
#set_label(text : String, side = "left")
Sets widget label.
- #set_line(i, line)
- #set_scroll_perc(i)
- #set_text(content = "", no_clear = false)
- #shift_line(n)
-
#show
Shows widget on screen
-
#snapshot(include_decorations = true, dxi = 0, dxl = 0, dyi = 0, dyl = 0)
Takes screenshot of a widget in a more convenient way than
#screenshot
. - #str_width(text)
-
#toggle_visibility
Toggles widget visibility
-
#top : Int32 | String | Nil
User-defined top
-
#top=(val : Int32 | String | Nil)
Sets Widget's
@top
-
#track=(track : Bool)
Should widget indicate the scroll position?
-
#track? : Bool
Should widget indicate the scroll position?
- #unshift_line(line)
- #vi=(vi : Bool)
- #vi? : Bool
-
#visible?
Returns whether widget is visible.
-
#width : Int32 | String | Nil
User-defined width (setter is defined below)
-
#width=(val : Int32 | String | Nil)
Sets widget's total width
-
#wrap_content=(wrap_content : Bool)
Can element's content be word-wrapped?
-
#wrap_content? : Bool
Can element's content be word-wrapped?
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
Class Method Detail
Instance Method Detail
Aligns content
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.
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.
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.
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.
Returns minimum widget size based on bounding box
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.
Printable, word-wrapped content, ready for rendering into the element.
Printable, word-wrapped content, ready for rendering into the element.
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.
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.
Offset of cursor (in number of lines) within Widget. Value of 0 means cursor being at first line of visible (potentially scrolled) content.
Offset of cursor (in number of lines) within Widget. Value of 0 means cursor being at first line of visible (potentially scrolled) content.
Clears area/position of widget's last render
Widget's user-set content in original form. Includes any attributes and tags.
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.
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.
Inserts element
to list of children at a specified position (at end by default)
Can element receive keyboard input? (Managed internally; use input
for user-side setting)
Can element receive keyboard input? (Managed internally; use input
for user-side setting)
What action to take when widget is overflowing parent's rectangle?
What action to take when widget is overflowing parent's rectangle?
Returns parent Widget
(if any) or Screen
to which the widget may be attached.
If the widget already is Screen
, returns nil
.
Removes node from its parent.
This is identical to calling parent.remove(self)
.
Repositions label to the right place. Usually called from resize event
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?
.
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?
.
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?
.
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.
Sets widget label. Can be positioned "left" (default) or "right"
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)
Returns whether widget is visible. Currently does not check if all parents are also visible.