flutter_flutter/engine/bindings/scripts/templates/interface_dart.template
Hixie fa70eb0982 Split Size into Size and Offset.
Added a OffsetBase class that Size now inherits from, and added a new
Offset class that also inherits from OffsetBase.

Offset has:
 - dx and dy members
 - zero and infinite static constants
 - a method that returns a new Offset that's the existing one scaled
   by a scalar
 - a unary minus operator
 - operators overloads such that subtracting or adding two Offsets
   gives another Offset
 - a toPoint() method

Added Offset and Size to the dart bindings, so they can be used from C++.

Changed the Canvas API to use Point, Size, and Offset where appropriate:
 - drawLine uses Points now
 - drawCircle uses a Point now
 - drawImage uses a Paint now
 - the constructor uses a Size

Changed Point as follows:
 - added a unary minus
 - Point difference now gives an Offset rather than a Size
 - You can add an Offset to a Point to get a new Point
 - toSize() has been replaced by toOffset()

Changed Rect as follows:
 - renamed upperLeft and lowerRight to topLeft and bottomRight for
   consistency with our other APIs
 - added bottomLeft and topRight for completeness

Changed Size as follows:
 - now inherits from OffsetBase
 - added *, /, ~/, and % operators for scaling sizes
 - subtracting a Size from a Size gives an Offset
 - subtracting an Offset from a Size gives a Size
 - changed the + operator to take an Offset instead of a Size
 - added topLeft, bottomLeft, topRight, bottomRight to match Rect
 - added center for the same reason
 - added shortestSide getter since that was a common pattern
 - removed toPoint()

Changed DrawLooperLayerInfo as follows:
 - setOffset member takes an Offset instead of a Point

Changed BoxConstraints as follows:
 - added biggest getter since it was a common pattern
 - added smallest getter for symmetry

Changed BoxShadow as follows:
 - offset member is an Offset rather than a Size

Changed ViewConstraints as follows:
 - replaced height and width members by a single size member

I did some minor code cleanup in nearby files while I was there,
including sorting sky/engine/core/core.gni alphabetically, and fixing
some warnings in the examples.

BUG=
R=abarth@chromium.org, chinmaygarde@google.com

Review URL: https://codereview.chromium.org/1214833004.
2015-06-26 15:21:29 -07:00

62 lines
2.5 KiB
Plaintext

// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// WARNING: Do not edit - generated code.
part of dart.sky;
{% macro args_macro(args) -%}
{%- for arg in args -%}
{%- if arg.is_optional and (loop.first or not args[arg.index-1].is_optional) -%}
{{ '{' if arg.is_named else '[' }}
{%- endif -%}
{{ arg.dart_type }} {{ arg.name }}
{%- if arg.is_optional %} {{ ':' if arg.is_named else '='}} {{ arg.dart_default_value }}
{#- TODO(eseidel): This does not support having both optional and named arguments! (then again, neither does Dart, currently) -#}
{%- if loop.last -%}{{ '}' if arg.is_named else ']' }}{%- endif -%}
{%- endif -%}
{%- if not loop.last %}, {% endif %}
{%- endfor -%}
{%- endmacro -%}
{%- set prefix = "_" if private_dart else "" -%}
{% if not constructors and not custom_constructors %}abstract {% endif -%}
class {{prefix}}{{interface_name}} extends
{{ parent_interface if parent_interface else 'NativeFieldWrapperClass2' }} {
// Constructors
{# TODO(eseidel): We only ever have one constructor. #}
{%- for constructor in constructors + custom_constructors %}
void _constructor(
{%- for arg in constructor.arguments -%}
{{ arg.dart_type }} {{ arg.name }}{% if not loop.last %}, {% endif %}
{%- endfor -%}
) native "{{interface_name}}_constructorCallback";
{{prefix}}{{interface_name}}({{ args_macro(constructor.arguments) }}) { _constructor(
{%- for arg in constructor.arguments -%}
{{ arg.name }}{% if not loop.last %}, {% endif %}
{%- endfor -%}
); }
{% endfor %}
// Attributes
{% for attribute in attributes %}
{{ attribute.dart_type }} get {{prefix}}{{ attribute.name }} native "{{interface_name}}_{{ attribute.name }}_Getter";
{% if not attribute.is_read_only %}
void set {{prefix}}{{ attribute.name }}({{ attribute.dart_type }} value) native "{{interface_name}}_{{ attribute.name }}_Setter";
{% endif %}
{% endfor %}
// Methods
{% for method in methods %}
{{method.dart_type}} {{prefix}}{{method.name}}({{ args_macro(method.arguments)}}) native "{{interface_name}}_{{ method.name }}_Callback";
{% endfor %}
// Operators
{% if named_property_getter %}
String operator[](String name) native "{{interface_name}}___getter___Callback";
{% endif %}
{% if named_property_setter %}
void operator[]=(String name, String value) native "{{interface_name}}___setter___Callback";
{% endif %}
}