class BBS::Window
A Window is a top-level Container with its own border, title, and focus manager. The Application stacks windows; the top window is the active one and receives input first. Windows that are not modal can be switched, Turbo Vision style: a click on one brings it to the front, F6 and Shift-F6 cycle them, Alt-1 … Alt-9 picks one by the number on its frame. The active window has a double frame, the others a single one. A modal window (the Dialogs) keeps the front until it closes.
A maximizable window that can lay itself out at any size (resizable?: MasterDetail, Stream, Form, a scrolling Info) gets a zoom gadget in its top right corner, Turbo Vision style: [↑] fills the desktop between the menubar and the statusbar, [↕] puts it back. F5, Alt-Enter and a double click on the title bar do the same.
A window that is not maximized can be moved and, when resizable?, resized (movable: false turns it off): drag the title bar to move it, the bottom right corner to size it. From the keyboard Ctrl-F5 (or F6) starts it (F6 only while it is the only window), Turbo Vision style: the arrows move the window, Shift and the arrows size it (Tab switches the arrows between moving and sizing), and Enter or Esc ends it. A window moved or sized keeps its place when the terminal is resized, pulled back onto the screen if needed.
Constants
- ALT_KEY
-
An Alt-modified key name,
alt_x; the group is the letter. - ARROWS
-
Arrow key Symbol =>
[dx, dy]step for keyboard moving and sizing. - CLOSE_MIN_WIDTH
-
The narrowest window that shows the close gadget.
- CLOSE_X
-
Column of the close gadget, from the window’s left edge.
- CORNER_HIT
-
Columns of the bottom right corner that start a size drag.
- CORNER_MIN_WIDTH
-
The narrowest window that shows the size corner.
- DOUBLE_CLICK
-
Seconds within which a second click on the title bar counts as a double click.
- GADGET_WIDTH
-
Width of a title bar gadget:
[■],[↑]. - KBD_TITLES
-
Titles shown in the frame while the window is moved (
:move) or sized (:size) from the keyboard. - MIN_HEIGHT
-
Smallest height a resizable window can be sized to (or the desktop height when that is smaller).
- MIN_WIDTH
-
Smallest width a resizable window can be sized to (or the desktop width when that is smaller).
- MODIFIED_MOVE_KEY
-
A Shift, Ctrl, Alt or Ctrl-Shift modified movement key; the group is the key without the modifier.
- MOVE_KEYS
-
Keys that start (and end) moving or sizing the window from the keyboard.
- NUMBER_BEFORE_ZOOM
-
Column of the window number before the zoom gadget, counted back from it.
- NUMBER_FROM_RIGHT
-
Column of the window number without a zoom gadget, counted back from the right edge.
- NUMBER_MIN_WIDTH
-
The narrowest window that shows its number.
- NUMBER_ROOM
-
Further columns a title gives up to the window number.
- TITLE_INDENT
-
Where the title starts when there is a close gadget.
- TITLE_ROOM
-
Columns of the title bar a title gives up without a zoom gadget.
- TITLE_ROOM_ZOOM
-
Columns of the title bar a title gives up to the gadgets when there is a zoom gadget.
- ZOOM_FROM_RIGHT
-
Column of the zoom gadget, counted back from the right edge.
- ZOOM_KEYS
-
Keys that toggle the maximized state of a zoomable window.
- ZOOM_MIN_WIDTH
-
The narrowest window that shows the zoom gadget.
Attributes
Style roles of the window’s own frame drawn in other colours than the theme’s, as a Hash of role => SGR (:window_border, :window_title, :window_title_focused), or nil. The widgets inside keep the theme: an accent marks which part of the board a window belongs to.
window.accent = { window_border: "\e[0;38;5;79;48;5;16m" }
The Application the window is shown in; set by the Application when it opens the window. Moving, sizing and zooming need it.
The window’s settings, as given to ::new: title (shown in the top border), modal (keeps the front, always a double frame), shadow (draws a drop shadow), on_close (callable run with the window when it closes, or false for no close gadget), close_key (key that closes it), maximizable (gets a zoom gadget when resizable?), movable (may be moved and sized). number is the number shown on the frame for Alt-1 … Alt-9, assigned by the Application to non-modal windows.
The window’s settings, as given to ::new: title (shown in the top border), modal (keeps the front, always a double frame), shadow (draws a drop shadow), on_close (callable run with the window when it closes, or false for no close gadget), close_key (key that closes it), maximizable (gets a zoom gadget when resizable?), movable (may be moved and sized). number is the number shown on the frame for Alt-1 … Alt-9, assigned by the Application to non-modal windows.
The window’s settings, as given to ::new: title (shown in the top border), modal (keeps the front, always a double frame), shadow (draws a drop shadow), on_close (callable run with the window when it closes, or false for no close gadget), close_key (key that closes it), maximizable (gets a zoom gadget when resizable?), movable (may be moved and sized). number is the number shown on the frame for Alt-1 … Alt-9, assigned by the Application to non-modal windows.
The window’s settings, as given to ::new: title (shown in the top border), modal (keeps the front, always a double frame), shadow (draws a drop shadow), on_close (callable run with the window when it closes, or false for no close gadget), close_key (key that closes it), maximizable (gets a zoom gadget when resizable?), movable (may be moved and sized). number is the number shown on the frame for Alt-1 … Alt-9, assigned by the Application to non-modal windows.
The window’s settings, as given to ::new: title (shown in the top border), modal (keeps the front, always a double frame), shadow (draws a drop shadow), on_close (callable run with the window when it closes, or false for no close gadget), close_key (key that closes it), maximizable (gets a zoom gadget when resizable?), movable (may be moved and sized). number is the number shown on the frame for Alt-1 … Alt-9, assigned by the Application to non-modal windows.
The window’s settings, as given to ::new: title (shown in the top border), modal (keeps the front, always a double frame), shadow (draws a drop shadow), on_close (callable run with the window when it closes, or false for no close gadget), close_key (key that closes it), maximizable (gets a zoom gadget when resizable?), movable (may be moved and sized). number is the number shown on the frame for Alt-1 … Alt-9, assigned by the Application to non-modal windows.
The window’s settings, as given to ::new: title (shown in the top border), modal (keeps the front, always a double frame), shadow (draws a drop shadow), on_close (callable run with the window when it closes, or false for no close gadget), close_key (key that closes it), maximizable (gets a zoom gadget when resizable?), movable (may be moved and sized). number is the number shown on the frame for Alt-1 … Alt-9, assigned by the Application to non-modal windows.
The window’s settings, as given to ::new: title (shown in the top border), modal (keeps the front, always a double frame), shadow (draws a drop shadow), on_close (callable run with the window when it closes, or false for no close gadget), close_key (key that closes it), maximizable (gets a zoom gadget when resizable?), movable (may be moved and sized). number is the number shown on the frame for Alt-1 … Alt-9, assigned by the Application to non-modal windows.
Public Class Methods
# File lib/bbs/window.rb, line 118 def initialize(title: nil, modal: false, shadow: true, on_close: nil, close_key: :escape, maximizable: false, movable: true, **kw) super(**kw) @title = title @modal = modal @shadow = shadow @on_close = on_close @close_key = close_key @maximizable = maximizable @movable = movable @maximized = false @placed = @drag = @kbd_mode = @focus_manager = @number = nil end
Creates a window. title, modal, shadow, on_close, close_key, maximizable and movable set the attributes of the same name; kw (id, bounds, theme) go to Container.new. The window starts not maximized and without a number.
BBS::Container::new
Public Instance Methods
Source
# File lib/bbs/window.rb, line 137 def busy? = !@kbd_mode.nil? || !@drag.nil?
True while the window is being moved or sized: the keys are its own.
Source
# File lib/bbs/window.rb, line 176 def close = :close_window
The Application closes the window and calls on_close (see Application#close_window), so the callback runs once.
Source
# File lib/bbs/window.rb, line 158 def focus_manager @focus_manager ||= FocusManager.new(self) end
Returns the window’s FocusManager, created on first use.
Source
# File lib/bbs/window.rb, line 170 def hit_test(x, y) close_gadget_at?(x, y) ? self : super end
Returns self for the close gadget area on the top border, otherwise the deepest widget at x, y as Container#hit_test does.
BBS::Container#hit_test
Source
# File lib/bbs/window.rb, line 140 def maximized? = @maximized
Returns whether the window fills the desktop.
Source
# File lib/bbs/window.rb, line 152 def movable? = @movable && !@maximized && !@app.nil?
Returns whether the window can be moved now: movable, not maximized and shown in an Application.
Source
# File lib/bbs/window.rb, line 164 def reset_focus @focus_manager = FocusManager.new(self) end
Replaces the FocusManager with a new one, so the focus starts over from the window’s current widgets.
Source
# File lib/bbs/window.rb, line 144 def resizable? = false
True for windows that can lay out their content at any size; they override place(x, y, width, height) and normal_rect.
Source
# File lib/bbs/window.rb, line 155 def sizable? = movable? && resizable?
Returns whether the window can be sized now: movable? and resizable?.
Source
# File lib/bbs/window.rb, line 134 def style(key) = @accent&.[](key) || super
Returns the SGR for the style role key: the accent’s when it has one, else the theme’s (see BBS::Widget#style).
Source
# File lib/bbs/window.rb, line 181 def tick(app); end
Called once per Application idle tick (about a second) with the Application. Does nothing; subclasses that poll for asynchronous updates override it (such as BBS::Windows::Stream).
Source
# File lib/bbs/window.rb, line 148 def zoomable? = @maximizable && resizable? && !@app.nil?
Returns whether the window can be maximized: it is maximizable, resizable? and shown in an Application.