"Fossies" - the Fresh Open Source Software Archive

Member "flutter-1.22.4/packages/flutter/lib/src/scheduler/priority.dart" (13 Nov 2020, 1679 Bytes) of package /linux/misc/flutter-1.22.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Dart source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 // Copyright 2014 The Flutter Authors. All rights reserved.
    2 // Use of this source code is governed by a BSD-style license that can be
    3 // found in the LICENSE file.
    4 
    5 import 'package:flutter/foundation.dart';
    6 
    7 /// A task priority, as passed to [SchedulerBinding.scheduleTask].
    8 @immutable
    9 class Priority {
   10   const Priority._(this._value);
   11 
   12   /// Integer that describes this Priority value.
   13   int get value => _value;
   14   final int _value;
   15 
   16   /// A task to run after all other tasks, when no animations are running.
   17   static const Priority idle = Priority._(0);
   18 
   19   /// A task to run even when animations are running.
   20   static const Priority animation = Priority._(100000);
   21 
   22   /// A task to run even when the user is interacting with the device.
   23   static const Priority touch = Priority._(200000);
   24 
   25   /// Maximum offset by which to clamp relative priorities.
   26   ///
   27   /// It is still possible to have priorities that are offset by more
   28   /// than this amount by repeatedly taking relative offsets, but that
   29   /// is generally discouraged.
   30   static const int kMaxOffset = 10000;
   31 
   32   /// Returns a priority relative to this priority.
   33   ///
   34   /// A positive [offset] indicates a higher priority.
   35   ///
   36   /// The parameter [offset] is clamped to ±[kMaxOffset].
   37   Priority operator +(int offset) {
   38     if (offset.abs() > kMaxOffset) {
   39       // Clamp the input offset.
   40       offset = kMaxOffset * offset.sign;
   41     }
   42     return Priority._(_value + offset);
   43   }
   44 
   45   /// Returns a priority relative to this priority.
   46   ///
   47   /// A positive offset indicates a lower priority.
   48   ///
   49   /// The parameter [offset] is clamped to ±[kMaxOffset].
   50   Priority operator -(int offset) => this + (-offset);
   51 }