"Fossies" - the Fresh Open Source Software Archive

Member "flutter-1.22.4/packages/flutter/lib/src/painting/basic_types.dart" (13 Nov 2020, 8447 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 
    6 import 'dart:ui' show TextDirection;
    7 
    8 export 'dart:ui' show
    9   BlendMode,
   10   BlurStyle,
   11   Canvas,
   12   Clip,
   13   Color,
   14   ColorFilter,
   15   FilterQuality,
   16   FontStyle,
   17   FontWeight,
   18   ImageShader,
   19   Locale,
   20   MaskFilter,
   21   Offset,
   22   Paint,
   23   PaintingStyle,
   24   Path,
   25   PathFillType,
   26   PathOperation,
   27   Radius,
   28   RRect,
   29   RSTransform,
   30   Rect,
   31   Shader,
   32   Size,
   33   StrokeCap,
   34   StrokeJoin,
   35   TextAffinity,
   36   TextAlign,
   37   TextBaseline,
   38   TextBox,
   39   TextDecoration,
   40   TextDecorationStyle,
   41   TextDirection,
   42   TextPosition,
   43   TileMode,
   44   VertexMode,
   45   hashValues,
   46   hashList;
   47 
   48 export 'package:flutter/foundation.dart' show VoidCallback;
   49 
   50 // Intentionally not exported:
   51 //  - Image, instantiateImageCodec, decodeImageFromList:
   52 //      We use ui.* to make it very explicit that these are low-level image APIs.
   53 //      Generally, higher layers provide more reasonable APIs around images.
   54 //  - lerpDouble:
   55 //      Hopefully this will eventually become Double.lerp.
   56 //  - Paragraph, ParagraphBuilder, ParagraphStyle, TextBox:
   57 //      These are low-level text primitives. Use this package's TextPainter API.
   58 //  - Picture, PictureRecorder, Scene, SceneBuilder:
   59 //      These are low-level primitives. Generally, the rendering layer makes these moot.
   60 //  - Gradient:
   61 //      Use this package's higher-level Gradient API instead.
   62 //  - window, WindowPadding
   63 //      These are generally wrapped by other APIs so we always refer to them directly
   64 //      as ui.* to avoid making them seem like high-level APIs.
   65 
   66 /// The description of the difference between two objects, in the context of how
   67 /// it will affect the rendering.
   68 ///
   69 /// Used by [TextSpan.compareTo] and [TextStyle.compareTo].
   70 ///
   71 /// The values in this enum are ordered such that they are in increasing order
   72 /// of cost. A value with index N implies all the values with index less than N.
   73 /// For example, [layout] (index 3) implies [paint] (2).
   74 enum RenderComparison {
   75   /// The two objects are identical (meaning deeply equal, not necessarily
   76   /// [dart:core.identical]).
   77   identical,
   78 
   79   /// The two objects are identical for the purpose of layout, but may be different
   80   /// in other ways.
   81   ///
   82   /// For example, maybe some event handlers changed.
   83   metadata,
   84 
   85   /// The two objects are different but only in ways that affect paint, not layout.
   86   ///
   87   /// For example, only the color is changed.
   88   ///
   89   /// [RenderObject.markNeedsPaint] would be necessary to handle this kind of
   90   /// change in a render object.
   91   paint,
   92 
   93   /// The two objects are different in ways that affect layout (and therefore paint).
   94   ///
   95   /// For example, the size is changed.
   96   ///
   97   /// This is the most drastic level of change possible.
   98   ///
   99   /// [RenderObject.markNeedsLayout] would be necessary to handle this kind of
  100   /// change in a render object.
  101   layout,
  102 }
  103 
  104 /// The two cardinal directions in two dimensions.
  105 ///
  106 /// The axis is always relative to the current coordinate space. This means, for
  107 /// example, that a [horizontal] axis might actually be diagonally from top
  108 /// right to bottom left, due to some local [Transform] applied to the scene.
  109 ///
  110 /// See also:
  111 ///
  112 ///  * [AxisDirection], which is a directional version of this enum (with values
  113 ///    light left and right, rather than just horizontal).
  114 ///  * [TextDirection], which disambiguates between left-to-right horizontal
  115 ///    content and right-to-left horizontal content.
  116 enum Axis {
  117   /// Left and right.
  118   ///
  119   /// See also:
  120   ///
  121   ///  * [TextDirection], which disambiguates between left-to-right horizontal
  122   ///    content and right-to-left horizontal content.
  123   horizontal,
  124 
  125   /// Up and down.
  126   vertical,
  127 }
  128 
  129 /// Returns the opposite of the given [Axis].
  130 ///
  131 /// Specifically, returns [Axis.horizontal] for [Axis.vertical], and
  132 /// vice versa.
  133 ///
  134 /// See also:
  135 ///
  136 ///  * [flipAxisDirection], which does the same thing for [AxisDirection] values.
  137 Axis flipAxis(Axis direction) {
  138   assert(direction != null);
  139   switch (direction) {
  140     case Axis.horizontal:
  141       return Axis.vertical;
  142     case Axis.vertical:
  143       return Axis.horizontal;
  144   }
  145 }
  146 
  147 /// A direction in which boxes flow vertically.
  148 ///
  149 /// This is used by the flex algorithm (e.g. [Column]) to decide in which
  150 /// direction to draw boxes.
  151 ///
  152 /// This is also used to disambiguate `start` and `end` values (e.g.
  153 /// [MainAxisAlignment.start] or [CrossAxisAlignment.end]).
  154 ///
  155 /// See also:
  156 ///
  157 ///  * [TextDirection], which controls the same thing but horizontally.
  158 enum VerticalDirection {
  159   /// Boxes should start at the bottom and be stacked vertically towards the top.
  160   ///
  161   /// The "start" is at the bottom, the "end" is at the top.
  162   up,
  163 
  164   /// Boxes should start at the top and be stacked vertically towards the bottom.
  165   ///
  166   /// The "start" is at the top, the "end" is at the bottom.
  167   down,
  168 }
  169 
  170 /// A direction along either the horizontal or vertical [Axis].
  171 enum AxisDirection {
  172   /// Zero is at the bottom and positive values are above it: `⇈`
  173   ///
  174   /// Alphabetical content with a [GrowthDirection.forward] would have the A at
  175   /// the bottom and the Z at the top. This is an unusual configuration.
  176   up,
  177 
  178   /// Zero is on the left and positive values are to the right of it: `⇉`
  179   ///
  180   /// Alphabetical content with a [GrowthDirection.forward] would have the A on
  181   /// the left and the Z on the right. This is the ordinary reading order for a
  182   /// horizontal set of tabs in an English application, for example.
  183   right,
  184 
  185   /// Zero is at the top and positive values are below it: `⇊`
  186   ///
  187   /// Alphabetical content with a [GrowthDirection.forward] would have the A at
  188   /// the top and the Z at the bottom. This is the ordinary reading order for a
  189   /// vertical list.
  190   down,
  191 
  192   /// Zero is to the right and positive values are to the left of it: `⇇`
  193   ///
  194   /// Alphabetical content with a [GrowthDirection.forward] would have the A at
  195   /// the right and the Z at the left. This is the ordinary reading order for a
  196   /// horizontal set of tabs in a Hebrew application, for example.
  197   left,
  198 }
  199 
  200 /// Returns the [Axis] that contains the given [AxisDirection].
  201 ///
  202 /// Specifically, returns [Axis.vertical] for [AxisDirection.up] and
  203 /// [AxisDirection.down] and returns [Axis.horizontal] for [AxisDirection.left]
  204 /// and [AxisDirection.right].
  205 Axis axisDirectionToAxis(AxisDirection axisDirection) {
  206   assert(axisDirection != null);
  207   switch (axisDirection) {
  208     case AxisDirection.up:
  209     case AxisDirection.down:
  210       return Axis.vertical;
  211     case AxisDirection.left:
  212     case AxisDirection.right:
  213       return Axis.horizontal;
  214   }
  215 }
  216 
  217 /// Returns the [AxisDirection] in which reading occurs in the given [TextDirection].
  218 ///
  219 /// Specifically, returns [AxisDirection.left] for [TextDirection.rtl] and
  220 /// [AxisDirection.right] for [TextDirection.ltr].
  221 AxisDirection textDirectionToAxisDirection(TextDirection textDirection) {
  222   assert(textDirection != null);
  223   switch (textDirection) {
  224     case TextDirection.rtl:
  225       return AxisDirection.left;
  226     case TextDirection.ltr:
  227       return AxisDirection.right;
  228   }
  229 }
  230 
  231 /// Returns the opposite of the given [AxisDirection].
  232 ///
  233 /// Specifically, returns [AxisDirection.up] for [AxisDirection.down] (and
  234 /// vice versa), as well as [AxisDirection.left] for [AxisDirection.right] (and
  235 /// vice versa).
  236 ///
  237 /// See also:
  238 ///
  239 ///  * [flipAxis], which does the same thing for [Axis] values.
  240 AxisDirection flipAxisDirection(AxisDirection axisDirection) {
  241   assert(axisDirection != null);
  242   switch (axisDirection) {
  243     case AxisDirection.up:
  244       return AxisDirection.down;
  245     case AxisDirection.right:
  246       return AxisDirection.left;
  247     case AxisDirection.down:
  248       return AxisDirection.up;
  249     case AxisDirection.left:
  250       return AxisDirection.right;
  251   }
  252 }
  253 
  254 /// Returns whether traveling along the given axis direction visits coordinates
  255 /// along that axis in numerically decreasing order.
  256 ///
  257 /// Specifically, returns true for [AxisDirection.up] and [AxisDirection.left]
  258 /// and false for [AxisDirection.down] and [AxisDirection.right].
  259 bool axisDirectionIsReversed(AxisDirection axisDirection) {
  260   assert(axisDirection != null);
  261   switch (axisDirection) {
  262     case AxisDirection.up:
  263     case AxisDirection.left:
  264       return true;
  265     case AxisDirection.down:
  266     case AxisDirection.right:
  267       return false;
  268   }
  269 }