module BBS::Window::Placement
Where a Window stands and how big it is: zooming, moving and sizing with the mouse and the keyboard, and keeping its place when the terminal is resized.
Public Instance Methods
# File lib/bbs/window/placement.rb, line 28 def move_to(x, y, width = bounds.width, height = bounds.height) return unless movable? @placed = on_desktop(x, y, *fitted_size(width, height)) resizable? ? place(*@placed) : shift(@placed[0] - bounds.x, @placed[1] - bounds.y) end
Moves (and, when resizable?, sizes) the window to the rect, kept on the desktop; the window keeps it through later relayouts. A resizable window is clamped to MIN_WIDTH by MIN_HEIGHT and the desktop size; any other keeps its size. Does nothing unless #movable?.
Source
# File lib/bbs/window/placement.rb, line 41 def relayout(app) return move_to(*@placed) if @placed && !@maximized return place(*(@maximized ? app.desktop_rect : normal_rect)) if resizable? centre_in(app) end
Called by the Application when the terminal is resized. The default keeps the windowโs size and re-centers it, shifting every descendant along. Subclasses whose geometry depends on the terminal size override this (such as BBS::Windows::MasterDetail). A window moved or sized by the user goes back to its place, a resizable one is placed at the desktop (maximized) or its normal_rect.
Source
# File lib/bbs/window/placement.rb, line 50 def shift(dx, dy) return if dx.zero? && dy.zero? walk do |w| b = w.bounds w.bounds = Widget::Rect.new(b.x + dx, b.y + dy, b.width, b.height) end end
Moves the window and all its descendants by dx columns and dy rows.
Source
# File lib/bbs/window/placement.rb, line 14 def toggle_maximize return :handled unless zoomable? @maximized = !@maximized @kbd_mode = nil @drag = nil relayout(@app) :handled end
Maximizes the window to the desktop, or puts it back to its normal place, ending any move or size in progress. Does nothing unless #zoomable?. Returns :handled.