This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Flesh our dart:ui graphics documentation. #2721
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,19 +4,70 @@ | |
|
||
part of dart_ui; | ||
|
||
/// Base class for [Size] and [Offset], which are both ways to describe | ||
/// a distance as a two-dimensional axis-aligned vector. | ||
abstract class OffsetBase { | ||
/// Abstract const constructor. This constructor enables subclasses to provide | ||
/// const constructors so that they can be used in const expressions. | ||
/// | ||
/// The first argument sets the horizontal dimension, and the second the | ||
/// vertical dimension. | ||
const OffsetBase(this._dx, this._dy); | ||
|
||
final double _dx; | ||
final double _dy; | ||
|
||
/// Returns true if either dimension is [double.INFINITY], and false if both | ||
/// are finite (or negative infinity, or NaN). | ||
/// | ||
/// This is different than comparing for equality with an instance that has | ||
/// _both_ dimensions set to [double.INFINITY]. | ||
bool get isInfinite => _dx >= double.INFINITY || _dy >= double.INFINITY; | ||
|
||
/// Less-than operator. Compares an [Offset] or [Size] to another [Offset] or | ||
/// [Size], and returns true if both the horizontal and vertical values of the | ||
/// left-hand-side operand are smaller than the horizontal and vertical values | ||
/// of the right-hand-side operand respectively. Returns false otherwise. | ||
/// | ||
/// This is a partial ordering. It is possible for two values to be neither | ||
/// less, nor greater than, nor equal to, another. | ||
bool operator <(OffsetBase other) => _dx < other._dx && _dy < other._dy; | ||
|
||
/// Less-than-or-equal-to operator. Compares an [Offset] or [Size] to another | ||
/// [Offset] or [Size], and returns true if both the horizontal and vertical | ||
/// values of the left-hand-side operand are smaller than or equal to the | ||
/// horizontal and vertical values of the right-hand-side operand | ||
/// respectively. Returns false otherwise. | ||
/// | ||
/// This is a partial ordering. It is possible for two values to be neither | ||
/// less, nor greater than, nor equal to, another. | ||
bool operator <=(OffsetBase other) => _dx <= other._dx && _dy <= other._dy; | ||
|
||
/// Greater-than operator. Compares an [Offset] or [Size] to another [Offset] | ||
/// or [Size], and returns true if both the horizontal and vertical values of | ||
/// the left-hand-side operand are bigger than the horizontal and vertical | ||
/// values of the right-hand-side operand respectively. Returns false | ||
/// otherwise. | ||
/// | ||
/// This is a partial ordering. It is possible for two values to be neither | ||
/// less, nor greater than, nor equal to, another. | ||
bool operator >(OffsetBase other) => _dx > other._dx && _dy > other._dy; | ||
|
||
/// Less-than-or-equal-to operator. Compares an [Offset] or [Size] to another | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Greater-than-or-equal-to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
/// [Offset] or [Size], and returns true if both the horizontal and vertical | ||
/// values of the left-hand-side operand are bigger than or equal to the | ||
/// horizontal and vertical values of the right-hand-side operand | ||
/// respectively. Returns false otherwise. | ||
/// | ||
/// This is a partial ordering. It is possible for two values to be neither | ||
/// less, nor greater than, nor equal to, another. | ||
bool operator >=(OffsetBase other) => _dx > other._dx && _dy >= other._dy; | ||
|
||
/// Equality operator. Compares an [Offset] or [Size] to another [Offset] or | ||
/// [Size], and returns true if the horizontal and vertical values of the | ||
/// left-hand-side operand are equal to the horizontal and vertical values of | ||
/// the right-hand-side operand respectively. Returns false otherwise. | ||
@override | ||
bool operator ==(dynamic other) { | ||
if (other is! OffsetBase) | ||
return false; | ||
|
@@ -25,5 +76,6 @@ abstract class OffsetBase { | |
_dy == typedOther._dy; | ||
} | ||
|
||
@override | ||
int get hashCode => hashValues(_dx, _dy); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ class Paint { | |
/// | ||
/// If null, defaults to [PaintingStyle.fill]. | ||
PaintingStyle style; | ||
static const PaintingStyle _kDefaultStyle = PaintingStyle.fill; | ||
|
||
/// How wide to make edges drawn when [style] is set to | ||
/// [PaintingStyle.stroke] or [PaintingStyle.strokeAndFill]. The | ||
|
@@ -37,44 +38,95 @@ class Paint { | |
/// | ||
/// The values null and 0.0 correspond to a hairline width. | ||
double strokeWidth; | ||
static const double _kDefaultStrokeWidth = 0.0; | ||
|
||
/// The kind of finish to place on the end of lines drawn when | ||
/// [style] is set to [PaintingStyle.stroke] or | ||
/// [PaintingStyle.strokeAndFill]. | ||
/// | ||
/// If null, defaults to [StrokeCap.butt], i.e. no caps. | ||
StrokeCap strokeCap; | ||
static const StrokeCap _kDefaultStrokeCap = StrokeCap.butt; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMHO, we should skip these defaults. The null values mean we don't have to call into skia in C++, which means we get the default in Skia. That's going to be slightly more efficient. |
||
|
||
/// Whether to apply anti-aliasing to lines and images drawn on the | ||
/// canvas. | ||
/// | ||
/// Defaults to true. The value null is treated as false. | ||
bool isAntiAlias = true; | ||
|
||
/// The color to use when stroking or filling a shape. | ||
/// | ||
/// Defaults to black. | ||
/// | ||
/// See also: | ||
/// | ||
/// * [style], which controls whether to stroke or fill (or both). | ||
/// * [colorFilter], which overrides [color]. | ||
/// * [shader], which overrides [color] with more elaborate effects. | ||
/// | ||
/// This color is not used when compositing. To colorize a layer, use | ||
/// [colorFilter]. | ||
Color color = _kDefaultPaintColor; | ||
static const Color _kDefaultPaintColor = const Color(0xFF000000); | ||
|
||
TransferMode transferMode; | ||
|
||
ColorFilter colorFilter; | ||
|
||
/// A mask filter (for example, a blur) to apply to a shape after it has been | ||
/// drawn but before it has been composited into the image. | ||
/// | ||
/// See [MaskFilter] for details. | ||
MaskFilter maskFilter; | ||
|
||
/// Controls the performance vs quality trade-off to use when applying | ||
/// filters, such as [maskFilter], or when drawing images, as with | ||
/// [Canvas.drawImageRect] or [Canvas.drawImageNine]. | ||
// TODO(ianh): verify that the image drawing methods actually respect this | ||
FilterQuality filterQuality; | ||
|
||
/// The shader to use when stroking or filling a shape. | ||
/// | ||
/// When this is null, the [color] is used instead. | ||
/// | ||
/// See also: | ||
/// | ||
/// * [Gradient], a shader that paints a color gradient. | ||
/// * [ImageShader], a shader that tiles an [Image]. | ||
/// * [colorFilter], which overrides [shader]. | ||
/// * [color], which is used if [shader] and [colorFilter] are null. | ||
Shader shader; | ||
|
||
/// A color filter to apply when a shape is drawn or when a layer is | ||
/// composited. | ||
/// | ||
/// See [ColorFilter] for details. | ||
/// | ||
/// When a shape is being drawn, [colorFilter] overrides [color] and [shader]. | ||
ColorFilter colorFilter; | ||
|
||
/// A transfer mode to apply when a shape is drawn or a layer is composited. | ||
/// | ||
/// The source colors are from the shape being drawn (e.g. from | ||
/// [Canvas.drawPath]) or layer being composited (the graphics that were drawn | ||
/// between the [Canvas.saveLayer] and [Canvas.restore] calls), after applying | ||
/// the [colorFilter], if any. | ||
/// | ||
/// The destination colors are from the background onto which the shape or | ||
/// layer is being composited. | ||
/// | ||
/// If null, defaults to [TransferMode.srcOver]. | ||
TransferMode transferMode; | ||
static const TransferMode _kDefaultTransferMode = TransferMode.srcOver; | ||
|
||
|
||
// Must match PaintFields enum in Paint.cpp. | ||
dynamic get _value { | ||
// The most common usage is a Paint with no options besides a color and | ||
// anti-aliasing. In this case, save time by just returning the color | ||
// as an int. | ||
if ((style == null || style == PaintingStyle.fill) && | ||
(strokeWidth == null || strokeWidth == 0.0) && | ||
(strokeCap == null || strokeCap == StrokeCap.butt) && | ||
if ((style == null || style == _kDefaultStyle) && | ||
(strokeWidth == null || strokeWidth == _kDefaultStrokeWidth) && | ||
(strokeCap == null || strokeCap == _kDefaultStrokeCap) && | ||
isAntiAlias && | ||
color != null && | ||
transferMode == null && | ||
(transferMode == null || transferMode == _kDefaultTransferMode) && | ||
colorFilter == null && | ||
maskFilter == null && | ||
filterQuality == null && | ||
|
@@ -96,6 +148,7 @@ class Paint { | |
]; | ||
} | ||
|
||
@override | ||
String toString() { | ||
StringBuffer result = new StringBuffer(); | ||
String semicolon = ''; | ||
|
@@ -106,7 +159,7 @@ class Paint { | |
result.write(' $strokeWidth'); | ||
else | ||
result.write(' hairline'); | ||
if (strokeCap != null && strokeCap != StrokeCap.butt) | ||
if (strokeCap != null && strokeCap != _kDefaultStrokeCap) | ||
result.write(' $strokeCap'); | ||
semicolon = '; '; | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated to documentation, but I wonder if cross-comparisons between Offset and Size should be disallowed via typing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was intentionally allowed initially (it's why they share a base class). We haven't used it much, though.