|
| 1 | +/* |
| 2 | + * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + */ |
| 7 | + |
| 8 | +package com.facebook.yoga; |
| 9 | + |
| 10 | +/** |
| 11 | + * Represents a grid track value for use with grid-template-rows/columns. |
| 12 | + */ |
| 13 | +public class YogaGridTrackValue { |
| 14 | + public enum Type { |
| 15 | + AUTO, |
| 16 | + POINTS, |
| 17 | + PERCENT, |
| 18 | + FR, |
| 19 | + MINMAX |
| 20 | + } |
| 21 | + |
| 22 | + private final Type type; |
| 23 | + private final float value; |
| 24 | + private final YogaGridTrackValue minValue; |
| 25 | + private final YogaGridTrackValue maxValue; |
| 26 | + |
| 27 | + private YogaGridTrackValue(Type type, float value) { |
| 28 | + this.type = type; |
| 29 | + this.value = value; |
| 30 | + this.minValue = null; |
| 31 | + this.maxValue = null; |
| 32 | + } |
| 33 | + |
| 34 | + private YogaGridTrackValue(YogaGridTrackValue min, YogaGridTrackValue max) { |
| 35 | + this.type = Type.MINMAX; |
| 36 | + this.value = 0; |
| 37 | + this.minValue = min; |
| 38 | + this.maxValue = max; |
| 39 | + } |
| 40 | + |
| 41 | + public static YogaGridTrackValue auto() { |
| 42 | + return new YogaGridTrackValue(Type.AUTO, 0); |
| 43 | + } |
| 44 | + |
| 45 | + public static YogaGridTrackValue points(float points) { |
| 46 | + return new YogaGridTrackValue(Type.POINTS, points); |
| 47 | + } |
| 48 | + |
| 49 | + public static YogaGridTrackValue percent(float percent) { |
| 50 | + return new YogaGridTrackValue(Type.PERCENT, percent); |
| 51 | + } |
| 52 | + |
| 53 | + public static YogaGridTrackValue fr(float fr) { |
| 54 | + return new YogaGridTrackValue(Type.FR, fr); |
| 55 | + } |
| 56 | + |
| 57 | + public static YogaGridTrackValue minMax(YogaGridTrackValue min, YogaGridTrackValue max) { |
| 58 | + return new YogaGridTrackValue(min, max); |
| 59 | + } |
| 60 | + |
| 61 | + public Type getType() { |
| 62 | + return type; |
| 63 | + } |
| 64 | + |
| 65 | + public float getValue() { |
| 66 | + return value; |
| 67 | + } |
| 68 | + |
| 69 | + public YogaGridTrackValue getMinValue() { |
| 70 | + return minValue; |
| 71 | + } |
| 72 | + |
| 73 | + public YogaGridTrackValue getMaxValue() { |
| 74 | + return maxValue; |
| 75 | + } |
| 76 | +} |
0 commit comments