Module: Thaum::Concerns::Modal
- Included in:
- App
- Defined in:
- lib/thaum/concerns/modal.rb
Instance Method Summary collapse
- #hide_modal ⇒ Object
- #modal_active? ⇒ Boolean
-
#recompute_modal_rect ⇒ Object
Called by the framework on ResizeEvent after the layout repartitions.
-
#show_modal(sigil:, width:, height:, x: nil, y: nil) ⇒ Object
Show a modal Sigil as an overlay above the layout tree.
Instance Method Details
#hide_modal ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/thaum/concerns/modal.rb', line 49 def hide_modal sigil = @modal_sigil return unless sigil Thaum.safe_invoke("#{sigil.class}#on_blur") { sigil.on_blur } Thaum.safe_invoke("#{sigil.class}#on_unmount") { sigil.on_unmount } @modal_sigil = nil @modal_rect = nil @modal_centered = false @modal_decl_w = nil @modal_decl_h = nil sigil.thaum_app = nil sigil.handler_parent = nil sigil.rect = nil restored = @previous_focus @previous_focus = nil if restored && focusable_and_mounted?(restored) @focused_sigil = restored Thaum.safe_invoke("#{restored.class}#on_focus") { restored.on_focus } end request_render nil end |
#modal_active? ⇒ Boolean
76 |
# File 'lib/thaum/concerns/modal.rb', line 76 def modal_active? = !@modal_sigil.nil? |
#recompute_modal_rect ⇒ Object
Called by the framework on ResizeEvent after the layout repartitions. Re-centers a default-centered modal on the new terminal dimensions. Modals with explicit x/y stay put.
81 82 83 84 85 86 |
# File 'lib/thaum/concerns/modal.rb', line 81 def recompute_modal_rect return unless @modal_sigil && @modal_centered @modal_rect = compute_modal_rect(width: @modal_decl_w, height: @modal_decl_h, x: nil, y: nil) @modal_sigil.rect = @modal_rect end |
#show_modal(sigil:, width:, height:, x: nil, y: nil) ⇒ Object
Show a modal Sigil as an overlay above the layout tree. width/height are required; x/y are optional terminal-absolute coords — when nil the modal is centered on the current terminal size. Calling show_modal while a modal is already active fires on_blur + on_unmount on the outgoing modal and replaces it. The previously-focused Sigil (from before any modal was shown) is preserved so hide_modal can restore it.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/thaum/concerns/modal.rb', line 14 def show_modal(sigil:, width:, height:, x: nil, y: nil) replacing = !@modal_sigil.nil? centered = x.nil? && y.nil? if replacing Thaum.safe_invoke("#{@modal_sigil.class}#on_blur") { @modal_sigil.on_blur } Thaum.safe_invoke("#{@modal_sigil.class}#on_unmount") { @modal_sigil.on_unmount } @modal_sigil.thaum_app = nil @modal_sigil.handler_parent = nil @modal_sigil.rect = nil elsif @focused_sigil # First modal — save the underlying focused Sigil and fire its on_blur. @previous_focus = @focused_sigil Thaum.safe_invoke("#{@focused_sigil.class}#on_blur") { @focused_sigil.on_blur } @focused_sigil = nil end rect = compute_modal_rect(width: width, height: height, x: x, y: y) @modal_sigil = sigil @modal_rect = rect @modal_centered = centered @modal_decl_w = width @modal_decl_h = height sigil.thaum_app = self sigil.handler_parent = self sigil.rect = rect Thaum.safe_invoke("#{sigil.class}#on_mount") { sigil.on_mount } Thaum.safe_invoke("#{sigil.class}#on_focus") { sigil.on_focus } request_render sigil end |