Class: Tuile::Component::InfoWindow

Inherits:
Window
  • Object
show all
Defined in:
lib/tuile/component/info_window.rb,
sig/tuile.rbs

Overview

A Window with a read-only body, in one of two presentations: prose (#message=) wraps in a scrollable TextView, rows (#lines=) stay one per row in a List, truncating instead of wrapping — the presentation for columnar output, where a wrap would destroy the alignment. Usable tiled (add it to a Layout) or as a popup via InfoWindow.open; the constructor and InfoWindow.open pick the presentation from the body's type:

Component::InfoWindow.open("Help", "A long explanation, wrapped to fit.")
Component::InfoWindow.open("Files", ["drwx  src/", "-rw-  README.md"])

Both write the same body slot — the last writer wins.

Instance Attribute Summary collapse

Attributes inherited from Window

#footer_text

Attributes included from HasContent

#content

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Window

#bottom_border, #caption, #caption=, #focusable?, #footer, #footer=, #layout, #layout_footer, #on_focus, #rect=, #repaint, #repaint_border, #scrollbar=, #top_border

Methods included from HasCaption

#caption, #caption=

Methods included from HasContent

#on_focus, #rect=

Constructor Details

#initialize(caption = "", body = nil) ⇒ InfoWindow

@param caption — the border title.

@param body — an Array is assigned through #lines=, anything else through #message=.

Parameters:



21
22
23
24
25
26
27
28
29
# File 'lib/tuile/component/info_window.rb', line 21

def initialize(caption = "", body = nil)
  @message = nil
  super(caption)
  if body.is_a?(Array)
    self.lines = body
  else
    self.message = body
  end
end

Instance Attribute Details

#messageString, ...

@return — whatever #message= was given — set a String, read that String back. After #lines= it is the List that setter mounted.

Returns:



34
35
36
# File 'lib/tuile/component/info_window.rb', line 34

def message
  @message
end

Class Method Details

.open(caption, body = nil, declared_size: Fraction::HALF) ⇒ Popup

Opens the info window as a popup.

@param caption — the border title.

@param body — dispatched by type as in #initialize.

@param declared_size — the popup's box, applied top-down; the body wraps or scrolls within it. Defaults to Fraction::HALF.

@return — the opened popup.

Parameters:

Returns:



75
76
77
# File 'lib/tuile/component/info_window.rb', line 75

def self.open(caption, body = nil, declared_size: Fraction::HALF)
  Popup.new(content: InfoWindow.new(caption, body), declared_size: declared_size).open
end

Instance Method Details

#lines=(lines) ⇒ void

This method returns an undefined value.

Sets the rows body: a List populated via List#lines= (so entries are coerced, \n-split and rstripped exactly as there), one item per row, long rows truncated — never wrapped. For prose use #message=.

@param lines — entries are String, StyledString, or anything that responds to #to_s.

Parameters:

  • lines (::Array[untyped])


61
62
63
64
65
# File 'lib/tuile/component/info_window.rb', line 61

def lines=(lines)
  list = List.new
  list.lines = lines
  self.message = list
end