Sha256: 21ea0f18e71de13d2dc3725bfff6ff7cc845257ace740140f9ec90869e15290b

Contents?: true

Size: 1.76 KB

Versions: 4

Compression:

Stored size: 1.76 KB

Contents

require "forwardable"

require "rabbit/action"
require "rabbit/progress"

module Rabbit
  module Renderer
    module Display
      module Progress
        extend Forwardable

        def_delegator(:@progress, :foreground, :progress_foreground)
        def_delegator(:@progress, :foreground=, :progress_foreground=)
        def_delegator(:@progress, :background, :progress_background)
        def_delegator(:@progress, :background=, :progress_background=)
        def_delegator(:@progress, :clear_color, :clear_progress_color)

        def initialize(*args, &block)
          super
          init_progress
        end

        private
        def init_progress
          @progress = Rabbit::Progress.new
          @progress_end_id = nil
        end

        def start_progress(max)
          return if max.zero?

          if @progress_end_id
            GLib::Source.remove(@progress_end_id)
            @progress_end_id = nil
            @progress.hide
          end
          update_menu
          @progress.start_progress(max, @canvas.window)
          adjust_progress_window
        end

        def update_progress(i)
          return if @progress_end_id
          @progress.update_progress(i)
          Utils.process_pending_events
        end

        def end_progress
          @progress.end_progress
          @progress_end_id = GLib::Timeout.add(100) do
            @progress.hide
            update_menu
            @progress_end_id = nil
            GLib::Source::REMOVE
          end
        end

        def configured(x, y, w, h)
          super
          adjust_progress_window
        end

        def adjust_progress_window
          if @window and @progress.window
            Utils.move_to_top_left(@window, @progress.window)
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rabbit-3.0.3 lib/rabbit/renderer/display/progress.rb
rabbit-3.0.2 lib/rabbit/renderer/display/progress.rb
rabbit-3.0.1 lib/rabbit/renderer/display/progress.rb
rabbit-3.0.0 lib/rabbit/renderer/display/progress.rb