Class: Gemba::FrameStack

Inherits:
Object
  • Object
show all
Defined in:
lib/gemba/frame_stack.rb

Overview

Push/pop stack for content frames inside the main window.

Mirrors the ModalStack pattern. When a new frame is pushed, the previous frame is hidden and the new one is shown. Popping reverses the transition.

Frames must implement the FrameStack protocol:

show     

Examples:

stack = FrameStack.new
stack.push(:picker, game_picker_frame)
stack.push(:emulator, emulator_frame)  # picker auto-hidden
stack.pop  # emulator hidden, picker re-shown

Defined Under Namespace

Classes: Entry

Instance Method Summary collapse

Constructor Details

#initializeFrameStack

Returns a new instance of FrameStack.



23
24
25
# File 'lib/gemba/frame_stack.rb', line 23

def initialize
  @stack = []
end

Instance Method Details

#active?Boolean

Returns true if any frame is on the stack.

Returns:

  • (Boolean)

    true if any frame is on the stack



28
# File 'lib/gemba/frame_stack.rb', line 28

def active? = !@stack.empty?

#currentSymbol?

Returns name of the topmost frame.

Returns:

  • (Symbol, nil)

    name of the topmost frame



31
# File 'lib/gemba/frame_stack.rb', line 31

def current = @stack.last&.name

#current_frameObject?

Returns the topmost frame object.

Returns:

  • (Object, nil)

    the topmost frame object



34
# File 'lib/gemba/frame_stack.rb', line 34

def current_frame = @stack.last&.frame

#popObject

Pop the current frame off the stack.

The popped frame is hidden. If there’s a previous frame, it is re-shown.



54
55
56
57
58
# File 'lib/gemba/frame_stack.rb', line 54

def pop
  return unless (entry = @stack.pop)
  entry.frame.hide
  @stack.last&.frame&.show
end

#push(name, frame) ⇒ Object

Push a frame onto the stack.

The previous frame (if any) is hidden before the new one is shown.

Parameters:

  • name (Symbol)

    identifier (e.g. :picker, :emulator)

  • frame (#show, #hide)

    the frame object



45
46
47
48
49
# File 'lib/gemba/frame_stack.rb', line 45

def push(name, frame)
  @stack.last&.frame&.hide
  @stack.push(Entry.new(name: name, frame: frame))
  frame.show
end

#sizeInteger

Returns number of frames on the stack.

Returns:

  • (Integer)

    number of frames on the stack



37
# File 'lib/gemba/frame_stack.rb', line 37

def size = @stack.length