Class: MittensUi::Loader
Overview
A loading spinner widget that displays an animated indicator during asynchronous operations. Wraps Gtk::Spinner and manages a background worker thread to prevent blocking the UI during long-running tasks.
The spinner is hidden by default and automatically shown/hidden based on processing state. Only one worker thread can run at a time; subsequent calls to #start while a thread is already running are safely ignored.
Instance Attribute Summary
Attributes inherited from Core
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Loader
constructor
Creates a new Loader widget with a spinner animation.
-
#start(&block) ⇒ void
Starts the spinner animation and executes a block in a background worker thread.
Methods inherited from Core
#hidden?, #hide, #keyboard_shortcut, #remove, #remove_keyboard_shortcut, #render, #shortcuts, #show
Methods included from Helpers
#icon_map, #list_system_icons, #set_margin_from_opts_for
Constructor Details
#initialize(options = {}) ⇒ Loader
Creates a new Loader widget with a spinner animation.
The spinner is initialized in a hidden state. Call #start to begin displaying the animation and executing a background task.
37 38 39 40 41 42 |
# File 'lib/mittens_ui/loader.rb', line 37 def initialize( = {}) @spinner = Gtk::Spinner.new @processing = false super(@spinner, ) @spinner.visible = false end |
Instance Method Details
#start(&block) ⇒ void
This method returns an undefined value.
Starts the spinner animation and executes a block in a background worker thread.
The spinner is displayed while the block executes, then automatically hidden when the block completes. If a worker thread is already running, this method safely returns without starting a new thread.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/mittens_ui/loader.rb', line 70 def start(&block) return if @processing return if @worker_thread&.alive? @processing = true @spinner.visible = true @spinner.start @worker_thread = Thread.new do block.call @processing = false @spinner.stop @spinner.visible = false end end |