Class: Tuile::Component::Window
- Inherits:
-
Tuile::Component
- Object
- Tuile::Component
- Tuile::Component::Window
- Includes:
- HasContent
- Defined in:
- lib/tuile/component/window.rb
Overview
A window with a frame, a #caption and a content Tuile::Component. Doesn’t support overlapping with other windows: it paints its entire contents and doesn’t clip if there are other overlapping windows.
The window’s ‘content` is unset by default; assign one via HasContent#content=.
Window is considered invisible if #rect is empty. The window won’t draw when invisible. (Repaint of detached windows is short-circuited by #invalidate; subclasses don’t need to re-check.)
Direct Known Subclasses
Instance Attribute Summary collapse
-
#caption ⇒ String
The current caption, empty by default.
-
#footer ⇒ Component?
Optional component overlaying the bottom border row.
Attributes included from HasContent
Attributes inherited from Tuile::Component
Instance Method Summary collapse
- #children ⇒ Array<Component>
-
#content_size ⇒ Size
The size needed to fit the window’s content, footer (width only — footer overlays the bottom border), and caption, plus the 2-character border.
- #focusable? ⇒ Boolean
- #handle_key(key) ⇒ Boolean
- #handle_mouse(event) ⇒ void
-
#initialize(caption = "") ⇒ Window
constructor
A new instance of Window.
- #key_shortcut=(key) ⇒ void
- #rect=(new_rect) ⇒ void
-
#repaint ⇒ void
Fully repaints the window: both frame and contents.
- #scrollbar=(value) ⇒ void
Methods included from HasContent
Methods inherited from Tuile::Component
#active=, #active?, #attached?, #cursor_position, #depth, #find_shortcut_component, #focus, #keyboard_hint, #on_child_removed, #on_focus, #on_tree, #root, #screen, #tab_stop?
Constructor Details
#initialize(caption = "") ⇒ Window
Returns a new instance of Window.
18 19 20 21 22 23 24 25 |
# File 'lib/tuile/component/window.rb', line 18 def initialize(caption = "") super() @border_right = 1 @caption = caption # Optional bottom-row chrome that overlays the bottom border (e.g. a # search field). @footer = nil end |
Instance Attribute Details
#caption ⇒ String
Returns the current caption, empty by default.
106 107 108 |
# File 'lib/tuile/component/window.rb', line 106 def caption @caption end |
#footer ⇒ Component?
Returns optional component overlaying the bottom border row.
31 32 33 |
# File 'lib/tuile/component/window.rb', line 31 def @footer end |
Instance Method Details
#children ⇒ Array<Component>
62 63 64 |
# File 'lib/tuile/component/window.rb', line 62 def children @footer.nil? ? super : super + [@footer] end |
#content_size ⇒ Size
Returns the size needed to fit the window’s content, footer (width only — footer overlays the bottom border), and caption, plus the 2-character border. Returns Size‘.new(2, 2)` when the window has no content, footer, or caption.
119 120 121 122 123 124 125 126 127 |
# File 'lib/tuile/component/window.rb', line 119 def content_size inner_w = [ content&.content_size&.width || 0, @footer&.content_size&.width || 0, frame_caption.length ].max inner_h = content&.content_size&.height || 0 Size.new(inner_w + 2, inner_h + 2) end |
#focusable? ⇒ Boolean
27 |
# File 'lib/tuile/component/window.rb', line 27 def focusable? = true |
#handle_key(key) ⇒ Boolean
68 69 70 71 72 |
# File 'lib/tuile/component/window.rb', line 68 def handle_key(key) return @footer.handle_key(key) if @footer&.active? super end |
#handle_mouse(event) ⇒ void
This method returns an undefined value.
76 77 78 79 80 81 82 |
# File 'lib/tuile/component/window.rb', line 76 def handle_mouse(event) if @footer&.rect&.contains?(event.point) @footer.handle_mouse(event) else super end end |
#key_shortcut=(key) ⇒ void
This method returns an undefined value.
149 150 151 152 153 |
# File 'lib/tuile/component/window.rb', line 149 def key_shortcut=(key) super # The shortcut key is shown in the caption — repaint. invalidate end |
#rect=(new_rect) ⇒ void
This method returns an undefined value.
86 87 88 89 |
# File 'lib/tuile/component/window.rb', line 86 def rect=(new_rect) super end |
#repaint ⇒ void
This method returns an undefined value.
Fully repaints the window: both frame and contents.
Window deliberately paints over its entire rect (border around the edge, content/footer over the interior), so we don’t need the Tuile::Component#repaint default’s auto-clear — but we do still want its “re-invalidate children” effect, since the border overpaints whatever the content/footer drew on the perimeter. Calling super handles both: the auto-clear is harmless (we re-paint over it), and the invalidation queues content + footer for repaint in the same cycle.
140 141 142 143 144 145 |
# File 'lib/tuile/component/window.rb', line 140 def repaint return if rect.empty? super repaint_border end |
#scrollbar=(value) ⇒ void
This method returns an undefined value.
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/tuile/component/window.rb', line 93 def (value) unless content.respond_to?(:scrollbar_visibility=) raise Tuile::Error, "scrollbar= requires a content component that supports scrollbar_visibility=, got #{content.inspect}" end content. = value ? :visible : :gone @border_right = value ? 0 : 1 invalidate layout(content) end |