// Copyright 2019 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.

syntax = "proto2";

package components.feed.core.proto.ui.piet;

option optimize_for = LITE_RUNTIME;

option java_package = "org.chromium.components.feed.core.proto.ui.piet";
option java_outer_classname = "GradientsProto";
option cc_enable_arenas = true;

// Represents a Fill to be used for a Piet element.
message Fill {
  // A fill can be either a solid color or a gradient.
  oneof fill_type {
    // A solid color fill. Colors are ARGB.
    fixed32 color = 1;

    // A linear gradient, expressed as multiple color stops.
    LinearGradient linear_gradient = 2;
  }
}

// A linear gradient interpolates the given color stops linearly.
message LinearGradient {
  // Multiple stops for this gradient. A valid gradient must have at least
  // two stops, one at position 0 and another at position 100.
  repeated ColorStop stops = 1;

  // Direction towards which this gradient should be rendered, in degrees from
  // the top.
  //   0: ↑ From Bottom to Top.
  //  90: → From Left to Right.
  // 180: ↓ From Top to Bottom.
  // 270: ← From Right to Left.
  // Values must be in the range [0..360). Negative values are not valid.
  optional uint32 direction_deg = 2;

  // If this boolean is true, the 'x' component of the gradient's angle will be
  // reversed when Piet is rendering a layout for a right-to-left language.
  optional bool reverse_for_rtl = 3;
}

// A GradientStop is one color in a gradient. A simple gradient is composed of
// at least two stops: starting with `position_percent` 0 & ending with
// `position_percent` 100. The linear gradient is interpolated between these two
// endpoints. More complex gradients can be achieved by inserting more color
// stops into the list.
message ColorStop {
  // ARGB color of the color stop.
  optional fixed32 color = 1;

  // Position of this color stop, expressed as a percent. It is an error for
  // position_percent to be outside [0..100].
  optional fixed32 position_percent = 2;
}
